KJNodes/wangenerated

WanVideoNAG

This node is implemented based on ChenDarYen's Normalized-Attention-Guidance project and works by modifying the cross-attention layers during the model's diffusion process.

Wan Video NAG

model
conditioning
model
nag_scale
11.000
nag_alpha
0.250
nag_tau
2.500
input_type
COMBO
inplace
KJNodes

The WanVideoNAG node is implemented based on ChenDarYen's Normalized-Attention-Guidance project. It works by modifying the cross-attention layers during the model's diffusion process.

WanVideoNAG is an experimental node designed to apply "Normalized Attention Guidance" (NAG) to video generation models. Its core function is to enhance or control the alignment between the generated video content and given conditions (such as text prompts) by adjusting the model's internal attention mechanism. This can potentially improve video coherence or thematic consistency.

Node Functionality

This node is implemented based on ChenDarYen's Normalized-Attention-Guidance project. It works by modifying the cross-attention layers during the model's diffusion process. It takes a base model and conditioning input, and finely controls the guidance strength, mixing ratio, and clipping threshold for attention bias using the three parameters nag_scale, nag_alpha, and nag_tau. It also offers optional settings for input type and in-place model modification. Ultimately, it outputs a modified new model that incorporates the NAG mechanism.

Node Parameter Description - WanVideoNAG

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
modelMODELYes--Outputs a new model with the normalized attention guidance mechanism applied.
conditioningCONDITIONINGYes--Input the text conditioning embeddings used to guide the generation process. Typically comes from a CLIP Text Encode node.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
nag_scaleFLOATYes11.00.0 - 100.0 (Step: 0.001)Strength of negative guidance effect
nag_alphaFLOATYes0.250.0 - 1.0 (Step: 0.001)Mixing coefficient that controls the balance between the normalized guided representation and the original positive representation.
nag_tauFLOATYes2.50.0 - 10.0 (Step: 0.001)Clipping threshold that controls how much the guided attention can deviate from the positive attention.
input_typeCOMBONodefault"default", "batch"Determines how the conditioning is applied. "default" processes conditioning as a single input; "batch" expects batched conditioning.
inplaceBOOLEANNoFalseTrue/FalseIf enabled, modifies the model in-place instead of returning a copy. Use with caution to avoid unintended side effects.

Output

Parameter NameData TypeDescription
modelMODELOutputs a new model with the normalized attention guidance mechanism applied.

Usage Scenarios

In a video generation workflow, you can place this node after loading the base model and before the sampler. For example, first load a video model using Checkpoint Loader, then generate conditioning using the CLIP Text Encode node. Next, input the model and conditioning into the WanVideoNAG node for adjustment. Finally, connect the output model to a sampler node for video generation.

Notes

This node is located under the KJNodes/wan category and is based on research code from the Normalized-Attention-Guidance project. While its functionality can be powerful, it may still behave unpredictably in certain workflows. It is recommended to test with a range of parameters and understand the underlying mechanism before relying on it for production use.

The WanVideoNAG node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…