Repository navigation
[guiders] fix MagnitudeAwareGuidance norm over 3+ dims - #15237
Open
davrens101 wants to merge 1 commit into
Open
davrens101 wants to merge 1 commit into
davrens101 wants to merge 1 commit into
Conversation
torch.norm with a dim list of 3 or more entries is dispatched to linalg.matrix_norm and raises on current torch, so mambo_guidance failed for every image or video latent. Use torch.linalg.vector_norm, which reduces over any dims.
This branch has not been deployed
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.
What does this PR do?
mambo_guidance(used byMagnitudeAwareGuidance) computes a per-sample norm withtorch.norm(x, dim=list(range(1, ndim)), keepdim=True). With three or more dims,torch.normis routed tolinalg.matrix_norm, which only accepts a 2-tuple. So the guider fails on any normal image latent (B, C, H, W) or video latent (B, C, F, H, W) whenever guidance is active.I found it by calling
forwardon every guider with random 4D tensors:This was on torch 2.15.0+cpu, on main at 33b3d37.
The fix swaps both calls for
torch.linalg.vector_norm, which reduces over any set of dims and gives the same per-sample 2-norm.I added
tests/others/test_magnitude_aware_guidance.py. It comparesmambo_guidanceagainst a flatten-then-norm reference for 4D and 5D inputs in both formulations, and runsMagnitudeAwareGuidance.forwardon image latents. On unmodified main, all 5 tests fail with the error above. With the change, all 5 pass.ruff checkandruff format --checkare clean on the two touched files.Limits: CPU only, on Windows. I did not run the full test suite or any end-to-end pipeline with this guider. I did not check older torch versions where
torch.normmay have accepted these dims.I used an AI coding assistant to write and test this change, and the numbers above come from its runs on my machine.