Skip to content

Commit a506bcb

Browse files
committed
fix(fastwam): restore bias support for fused VAE RMSNorm
1 parent 4d5ea92 commit a506bcb

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

  • loongforge/embodied/model/fastwam/wan

loongforge/embodied/model/fastwam/wan/vae.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def forward(self, x, cache_x=None):
7676
class RMSNorm(nn.Module):
7777
"""Root mean square normalization supporting channel-first tensors."""
7878

79-
def __init__(self, dim, channel_first=True, images=True):
79+
def __init__(self, dim, channel_first=True, images=True, bias=False):
8080
"""Initialize learnable RMS normalization parameters."""
8181
super().__init__()
8282
broadcastable_dims = (1, 1, 1) if not images else (1, 1)
@@ -85,15 +85,18 @@ def __init__(self, dim, channel_first=True, images=True):
8585
self.channel_first = channel_first
8686
self.eps = 1e-12
8787
self.gamma = nn.Parameter(torch.ones(shape))
88+
self.bias = nn.Parameter(torch.zeros(shape)) if bias else 0.
8889

8990
def forward(self, x):
90-
"""Normalize input tensor and apply scale parameters."""
91+
"""Normalize input tensor and apply scale and bias parameters."""
9192
weight = self.gamma.reshape(-1)
9293
if self.channel_first:
9394
# Move channels to the last axis so F.rms_norm can use the fused kernel.
9495
x = F.rms_norm(x.movedim(1, -1), weight.shape, weight=weight, eps=self.eps)
95-
return x.movedim(-1, 1)
96-
return F.rms_norm(x, weight.shape, weight=weight, eps=self.eps)
96+
x = x.movedim(-1, 1)
97+
else:
98+
x = F.rms_norm(x, weight.shape, weight=weight, eps=self.eps)
99+
return x + self.bias
97100

98101

99102
class Upsample(nn.Upsample):

0 commit comments

Comments
 (0)