Skip to content

[vla] perf: use fused F.rms_norm in FastWAM VAE RMSNorm - #129

Merged
nullnonenilNULL merged 2 commits into
baidu-baige:masterfrom
XueSongTap:master
Jul 28, 2026
Merged

[vla] perf: use fused F.rms_norm in FastWAM VAE RMSNorm#129
nullnonenilNULL merged 2 commits into
baidu-baige:masterfrom
XueSongTap:master

Conversation

@XueSongTap

@XueSongTap XueSongTap commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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_norm does the same work — mean(x^2) -> rsqrt -> scale by gamma — in a single fused kernel.

F.rms_norm normalizes 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 with movedim(1, -1) and moves them back afterwards; movedim only changes strides and does not copy.

Why it is equivalent

F.normalize(x, dim) is x / max(||x||_2, eps); multiplying by sqrt(dim) gives x / sqrt(mean(x^2)), which is the RMSNorm definition. The only difference is where eps is applied — clamped in the denominator before, added inside the square root now. eps is set explicitly to 1e-12 to match the previous F.normalize default.

Verification

  • Training loss curves match the baseline.
image
  • End-to-end throughput: ~1% improvement in the typical case.
image

Notes

  • Requires PyTorch >= 2.4 for F.rms_norm. No fallback is kept.
  • Removes the unused bias argument from RMSNorm.__init__. It defaulted to False and no call site ever set it, so no parameter was created and checkpoint compatibility is unaffected.

class RMSNorm(nn.Module):
"""Root mean square normalization supporting channel-first tensors."""

def __init__(self, dim, channel_first=True, images=True, bias=False):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to retain the bias support path rather than remove it entirely.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest commit restores the bias support path while retaining the fused VAE RMSNorm implementation.

@XueSongTap XueSongTap changed the title [fastwam] perf: use fused F.rms_norm in Wan VAE RMSNorm [vla] perf: use fused F.rms_norm in FastWAM VAE RMSNorm Jul 28, 2026
@nullnonenilNULL
nullnonenilNULL merged commit 1695eb1 into baidu-baige:master Jul 28, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants