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

Adjust PE [Full Stretch] πŸŽ­πŸ…πŸ…“

Stretching AnimateDiff's positional encoding past its training window

By KosinkadinkΒ·Created 3 years agoΒ·Updated 17 days agoΒ· 3,522
Adjust PE [Full Stretch] πŸŽ­πŸ…πŸ…“
  • prev_pe_adjust
  • PE_ADJUST
β—„pe_stretch0β–Ί
β—„print_adjustmentfalseβ–Ί

If you've pushed AnimateDiff's context length past what the motion module was actually trained on and started seeing motion turn to mush - smeary, jittery, losing coherence the longer the clip runs - this node is one of the knobs built specifically to fight that. Adjust PE [Full Stretch] reshapes the motion module's positional encoding (PE) so it covers your actual generation length instead of running out of trained range.

Why this exists

AnimateDiff's temporal transformer blocks know "this is frame 3 of 16" (or whatever the module was trained at) via positional encoding baked into the model. Kosinkadink's sliding-context-window trick is what lets AnimateDiff generate arbitrarily long clips at all - it processes 16(ish) frames at a time with overlap - but each window still asks the module to reason about positions it saw during training. Push the context length or the total frame count too far past that native range and the encoding starts extrapolating into territory it's never seen, which is a real contributor to the quality drop-off people report on long, high-context runs. The PE Adjust family (this node, plus Manual and Sweetspot) exists to remap those positions instead of feeding them raw.

"Full Stretch" is the blunt instrument of the three: it stretches the model's trained PE range proportionally across your target length rather than truncating or wrapping it, which is a different trade-off than the Sweetspot or Manual variants (worth reading the pack's own node documentation for the exact math if you're tuning this seriously - it's not laid out in the top-level README, and this is genuinely advanced-user territory).

Inputs and output

  • pe_stretch (int, default 0) - the stretch amount. At 0 it's a no-op; you'll want to actually set this if you're using it. There's no magic default here that suits every motion model or context length, so expect to test.
  • print_adjustment (bool, default off) - prints what the node actually computed to the console. Turn this on the first time you use it so you can see what's happening instead of guessing.
  • prev_pe_adjust (optional, PE_ADJUST) - lets you chain PE adjustments together, feeding the output of one into the input of the next.
  • Output: PE_ADJUST - not something you look at directly. It's a settings object you wire into whatever node in your graph collects per-model AnimateDiff settings (the pack calls it something like a custom AnimateDiff settings node) - that then attaches to your motion model loader.

Installing the pack

Easiest path is ComfyUI Manager: search for AnimateDiff Evolved, confirm the author is Kosinkadink, install, restart. Manually:

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

then restart ComfyUI. This particular node doesn't need any extra model files itself - it's pure settings, no weights - but you do need at least one motion module downloaded (mm_sd_v15_v2, v3_sd15_mm, etc.) and dropped into ComfyUI/models/animatediff_models for anything else in the graph to have something for this node's output to attach to.

Common issues

You changed it and nothing looks different. Turn on print_adjustment and confirm the value is actually reaching your motion model settings - it's easy to build the PE_ADJUST chain and forget to wire the final output into anything.

It's making things worse, not better. This isn't a "bigger number = better" knob. Full Stretch, Manual, and Sweetspot exist as different strategies for the same underlying problem, and which one helps depends on your motion model version and how far past 16-24 frames you're pushing the context. If Full Stretch degrades quality on your setup, try Sweetspot instead - it's built around the idea that these modules have a "best" context length they were most heavily trained at, and reshaping around that sweet spot rather than uniformly stretching everything can behave very differently.

Worth asking first: do you need this at all? If you're just trying to get a longer video and haven't touched Context Options yet, tuning context_length / context_overlap there gets you most of the way with far less fiddling - PE adjustment is for squeezing quality out of context lengths that are already pushing the model's limits, not a first resort. And if raw video quality (not the AnimateDiff morph look specifically) is the goal, it's worth knowing Wan and LTX-based tooling now handle long, coherent clips natively without any of this - AnimateDiff is the right call when you specifically want its aesthetic or you're already deep in an SD 1.5 pipeline.

KB gap: the pack's own documentation/nodes page (linked from the README but not fetched for this article) almost certainly has the exact formula for how "stretch" maps onto encoding indices - worth pulling in next time this pack comes up.

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

Inputs (3)

NameTypeDefaultDescription
pe_stretchINT00–9007199254740991β€”
print_adjustmentBOOLEANfalseβ€”
prev_pe_adjustoptPE_ADJUSTβ€”

Outputs (1)

NameTypeDescription
PE_ADJUSTPE_ADJUSTβ€”