[vla] perf: use fused F.rms_norm in FastWAM VAE RMSNorm - #129
Merged
Conversation
| class RMSNorm(nn.Module): | ||
| """Root mean square normalization supporting channel-first tensors.""" | ||
|
|
||
| def __init__(self, dim, channel_first=True, images=True, bias=False): |
Collaborator
There was a problem hiding this comment.
It is recommended to retain the bias support path rather than remove it entirely.
Collaborator
Author
There was a problem hiding this comment.
The latest commit restores the bias support path while retaining the fused VAE RMSNorm implementation.
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.
Replace the hand-written RMSNorm in the Wan VAE with
F.rms_norm.The previous implementation expressed RMS normalization as
F.normalize(x, dim) * dim**0.5 * gamma + bias, which launches four separate elementwise kernels over the full activation.F.rms_normdoes the same work —mean(x^2)->rsqrt-> scale bygamma— in a single fused kernel.F.rms_normnormalizes over trailing dimensions only, while this module normalizes over the channel axis of(B, C, T, H, W)tensors. The channel-first path therefore moves channels to the last axis withmovedim(1, -1)and moves them back afterwards;movedimonly changes strides and does not copy.Why it is equivalent
F.normalize(x, dim)isx / max(||x||_2, eps); multiplying bysqrt(dim)givesx / sqrt(mean(x^2)), which is the RMSNorm definition. The only difference is whereepsis applied — clamped in the denominator before, added inside the square root now.epsis set explicitly to1e-12to match the previousF.normalizedefault.Verification
Notes
F.rms_norm. No fallback is kept.biasargument fromRMSNorm.__init__. It defaulted toFalseand no call site ever set it, so no parameter was created and checkpoint compatibility is unaffected.