Nodes/AnimateDiff Evolved/ContextRef Tuneβ—†Attn+Adain πŸŽ­πŸ…πŸ…“
ComfyUI Node Runs on cloud

ContextRef Tuneβ—†Attn+Adain πŸŽ­πŸ…πŸ…“

Attention injection plus color and style matching

By KosinkadinkΒ·Created 3 years agoΒ·Updated 8 days agoΒ· 3,519
ContextRef Tuneβ—†Attn+Adain πŸŽ­πŸ…πŸ…“
    • CONTEXTREF_TUNE
    β—„attn_style_fidelity1.00β–Ί
    β—„attn_ref_weight1.00β–Ί
    β—„attn_strength1.00β–Ί
    β—„adain_style_fidelity1.00β–Ί
    β—„adain_ref_weight1.00β–Ί
    β—„adain_strength1.00β–Ί

    This is ContextRef Tune Β· Attn's three attention dials, plus a second consistency mechanism stacked on top: AdaIN, Adaptive Instance Normalization, a standard style-transfer technique that matches the statistical "feel" - in practice, color, contrast, and luminance - of one image's features onto another's. Here it's applied between the reference context window and every later window, on top of the attention injection ContextRef already does.

    What it does

    Six optional float inputs, all 0–1, all defaulting to 1. The first three are identical to the plain Tune Β· Attn node:

    • attn_style_fidelity, attn_ref_weight, attn_strength - the attention-injection dials, same behavior as Tune Β· Attn.

    The three new ones control the added AdaIN layer:

    • adain_style_fidelity - how strongly the reference's color and lighting statistics get matched onto later windows.
    • adain_ref_weight - how much weight the reference's statistics carry relative to each window's own, when blended.
    • adain_strength - an overall multiplier on the AdaIN effect.

    Output is CONTEXTREF_TUNE, same as Tune Β· Attn, wired the same way into contextref_tune or tune_replace.

    Why add AdaIN on top of attention

    Attention injection alone pulls identity and composition toward the reference; it doesn't necessarily lock color and exposure the same way. Stacking AdaIN on top adds that statistical color and lighting match, which is the more direct fix if what's actually drifting across your sliding-context render is tone and grading rather than who's in the frame. The tradeoff is the standard one with AdaIN-style matching in general: push it hard enough and you can flatten out lighting variation you actually wanted - a scene that's supposed to dim or shift color over the course of the clip instead gets pulled back toward the reference window's exposure the whole way through.

    Where this fits relative to Tune Β· Attn

    Everything in the plain Tune Β· Attn node's article carries over here unchanged - the three attn_* dials behave identically. This node exists purely to add the adain_* layer on top, for renders where attention injection alone isn't enough to hold color and lighting steady across a long sliding-context render.

    Installing it

    ComfyUI Manager: search AnimateDiff Evolved, author Kosinkadink, install, restart. Or clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved into custom_nodes manually and restart.

    A reasonable way to tune it

    Since there's essentially no community writeup to lean on here, treat the two halves separately rather than adjusting all six at once: get the attention dials to a level of identity-consistency you're happy with first, using a short test render, then add the AdaIN dials on top only if color and lighting are still the specific thing drifting. Pushing both effects to full strength simultaneously makes it hard to tell which one is responsible when a render looks over-locked.

    CategoryAnimate Diff πŸŽ­πŸ…πŸ…“/context opts/context extras/contextref

    Inputs (6)

    NameTypeDefaultDescription
    attn_style_fidelityoptFLOAT1.000–1β€”
    attn_ref_weightoptFLOAT1.000–1β€”
    attn_strengthoptFLOAT1.000–1β€”
    adain_style_fidelityoptFLOAT1.000–1β€”
    adain_ref_weightoptFLOAT1.000–1β€”
    adain_strengthoptFLOAT1.000–1β€”

    Outputs (1)

    NameTypeDescription
    CONTEXTREF_TUNECONTEXTREF_TUNEβ€”