Nodes/AnimateDiff Evolved/Adjust PE [Manual] πŸŽ­πŸ…πŸ…“
ComfyUI Node Runs on cloud

Adjust PE [Manual] πŸŽ­πŸ…πŸ…“

Hand-tuning AnimateDiff's positional encoding, index by index

By KosinkadinkΒ·Created 3 years agoΒ·Updated 8 days agoΒ· 3,519
Adjust PE [Manual] πŸŽ­πŸ…πŸ…“
  • prev_pe_adjust
  • PE_ADJUST
β—„cap_initial_pe_length0β–Ί
β—„interpolate_pe_to_length0β–Ί
β—„initial_pe_idx_offset0β–Ί
β—„final_pe_idx_offset0β–Ί
β—„print_adjustmentfalseβ–Ί

This is the "I know exactly what I want" version of AnimateDiff's positional-encoding tricks. Where Adjust PE [Full Stretch] and Adjust PE [Sweetspot] apply a preset strategy for remapping the motion module's positional encoding, Adjust PE [Manual] hands you four raw numbers and lets you build the remapping yourself. It's the escape hatch for when the presets don't do what you need.

Why you'd reach for it

The motion module's temporal attention layers were trained on a fixed range of frame positions (natively 16 for the earlier models). Kosinkadink's sliding context windows are what let AnimateDiff generate past that, but push a context length or extended-length generation far enough and you're asking the module to reason about positions it never trained on - one of the real contributors to the motion smear and coherence loss people hit on long, high-context runs. The PE Adjust nodes exist to remap indices before they hit the model instead of feeding them raw and hoping. Manual is the version for people who've already tried Full Stretch or Sweetspot, understood roughly what they do, and want finer control than either preset offers - genuinely a power-user node, not a first stop.

Inputs and output

Four integer knobs, all defaulting to 0:

  • cap_initial_pe_length - caps how much of the initial trained positional range gets used before your remapping kicks in.
  • interpolate_pe_to_length - the target length you're interpolating the encoding out to.
  • initial_pe_idx_offset - shifts where in the encoding range you start reading from.
  • final_pe_idx_offset - shifts where you end.

Plus print_adjustment (bool, off by default) - flip this on so you can actually see what values the node computed, since with four interacting numbers it's easy to end up somewhere you didn't intend.

Optionally chain a prev_pe_adjust (PE_ADJUST) in to stack this on top of an earlier adjustment. Output is PE_ADJUST, a settings object - it does nothing on its own; wire it into whichever node in your graph collects per-model AnimateDiff settings, which then attaches to your motion model.

Installing the pack

ComfyUI Manager: search AnimateDiff Evolved, verify the author is Kosinkadink, install and restart. Manual install:

cd ComfyUI/custom_nodes
git clone https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved

restart ComfyUI. This node itself carries no weights - it's a pure settings node - but you need at least one motion module (mm_sd_v15_v2, v3_sd15_mm, etc.) downloaded into ComfyUI/models/animatediff_models for anything downstream to matter.

Common issues

You have no idea what numbers to put in. Fair - this node doesn't hold your hand, and the exact semantics of these four fields live in the pack's own node documentation (not the top-level README), not in a tooltip here. The honest starting point is to first get Full Stretch or Sweetspot working reasonably well, turn print_adjustment on for both, and use the numbers they produce as a baseline for what "reasonable" looks like before you start hand-editing.

Small changes cause big, weird effects. These four values interact - moving the offset without also moving the cap can produce results that look nothing like what you'd expect from either number alone. Change one at a time and re-render, don't tune all four blind.

You're reaching for this and don't actually need it. If your context length is already close to what the motion model was natively trained on (16 frames for most SD 1.5 modules), you probably don't need PE adjustment at all - this is specifically for pushing past that. Try Context Options tuning first; it solves the "longer video" problem for far less effort, and PE adjustment is only worth the trouble once that alone stops being enough.

KB gap: the exact mapping these four fields perform isn't documented anywhere in our knowledge base - it lives in the pack's documentation/nodes page on GitHub, which wasn't part of the sources for this article. Worth pulling in directly if this node keeps coming up.

CategoryAnimate Diff πŸŽ­πŸ…πŸ…“/ad settings/pe adjust

Inputs (6)

NameTypeDefaultDescription
cap_initial_pe_lengthINT0β€”
interpolate_pe_to_lengthINT0β€”
initial_pe_idx_offsetINT0β€”
final_pe_idx_offsetINT0β€”
print_adjustmentBOOLEANfalseβ€”
prev_pe_adjustoptPE_ADJUSTβ€”

Outputs (1)

NameTypeDescription
PE_ADJUSTPE_ADJUSTβ€”