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
Conversation
…, list generator, mid-block disable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 defaultThe docstring says
context_length=Nonefalls back tomotion_adapter.config.motion_max_seq_length, but the warning check at L494 comparesNone > intbefore the default is resolved at L505.Fix: resolve the default once, up front, then drop the now-redundant
orfrom the assignment.Issue 3 —
repeat_context/shuffle_contextignorecontext_lengthcontext_num_framescompares the intself._free_noise_context_lengthto the literal string"repeat_context"(looks like the author meantself._free_noise_noise_type). It is always falsy, socontext_num_framesalways falls through tonum_frames. As a result,repeat_contextstarts fromnum_framesrandom frames and the trailing[:num_frames]slice makes the repeat a no-op, andshuffle_contextshuffles a window the same size as the output instead of a smaller context window.Fix (matches the suggestion in the meta-issue): pick
num_framesonly fornoise_type == "random", otherwise usecontext_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) andrandn_tensorhandles that, buttorch.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_tensorkeeps using the per-sample list for the actual noise.Issue 5 —
disable_free_noise()always reaches intomid_blockLines 523-528 first compute
blockswith the correct guard for adapters whose mid-block has no motion modules, then unconditionally re-assign the same list includingmid_blockon the next line. Pipelines whose mid-block lacksmotion_modulestherefore raiseAttributeErrorwhile 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
pipeline_infrastructuremodel/pipeline review #13653 are not included here — Issue 1 is inonnx_utils.py(separate PR fix(onnx): make provider_options optional in OnnxRuntimeModel._from_pretrained (#13653) #13667) and Issues 6/7 each touch a different file. Happy to follow up with those if helpful.🤖 Generated with Claude Code