Skip to content

fix(free_noise): resolve None default, repeat_context/shuffle_context, list gen, mid-block disable (#13653)#13668

Open
Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Anai-Guo:fix/free-noise-default-and-block-bugs
Open

fix(free_noise): resolve None default, repeat_context/shuffle_context, list gen, mid-block disable (#13653)#13668
Anai-Guo wants to merge 1 commit intohuggingface:mainfrom
Anai-Guo:fix/free-noise-default-and-block-bugs

Conversation

@Anai-Guo
Copy link
Copy Markdown

@Anai-Guo Anai-Guo commented May 1, 2026

Problem

Fixes Issues 2, 3, 4, and 5 of #13653 — four surgical bugs in free_noise_utils.py. They are independent but cluster in one file, so I bundled them.

Issue 2 — enable_free_noise(context_length=None) crashes before applying the documented default

The docstring says context_length=None falls back to motion_adapter.config.motion_max_seq_length, but the warning check at L494 compares None > int before the default is resolved at L505.

pipe.enable_free_noise(context_length=None)
# TypeError: '>' not supported between instances of 'NoneType' and 'int'

Fix: resolve the default once, up front, then drop the now-redundant or from the assignment.

Issue 3 — repeat_context / shuffle_context ignore context_length

context_num_frames compares the int self._free_noise_context_length to the literal string "repeat_context" (looks like the author meant self._free_noise_noise_type). It is always falsy, so context_num_frames always falls through to num_frames. As a result, repeat_context starts from num_frames random frames and the trailing [:num_frames] slice makes the repeat a no-op, and shuffle_context shuffles a window the same size as the output instead of a smaller context window.

Fix (matches the suggestion in the meta-issue): pick num_frames only for noise_type == "random", otherwise use context_length.

Issue 4 — list generators fail in shuffle_context

_prepare_latents_free_noise() accepts a list of generators (one per batch item, the standard diffusers convention) and randn_tensor handles that, but torch.randperm(window_length, generator=generator) is then called with the full list and crashes.

Fix: use the first generator from the list for the permutation. The shuffle is one window-level operation shared across the batch, so a single deterministic generator is the right semantics. randn_tensor keeps using the per-sample list for the actual noise.

Issue 5 — disable_free_noise() always reaches into mid_block

Lines 523-528 first compute blocks with the correct guard for adapters whose mid-block has no motion modules, then unconditionally re-assign the same list including mid_block on the next line. Pipelines whose mid-block lacks motion_modules therefore raise AttributeError while disabling FreeNoise.

Fix: delete the unconditional reassignment.

Reproductions

(All four come straight from #13653. Verified the logical fixes pass; the pipeline-level repros are end-to-end and need a real motion adapter to drive, which I cannot run locally.)

Notes

🤖 Generated with Claude Code

@github-actions github-actions Bot added size/S PR with diff < 50 LOC pipelines labels May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipelines size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant