| 232 | |
| 233 | |
| 234 | class WanRMSNorm(nn.Module): |
| 235 | |
| 236 | def __init__(self, dim, eps=1e-5): |
| 237 | super().__init__() |
| 238 | self.dim = dim |
| 239 | self.eps = eps |
| 240 | self.weight = nn.Parameter(torch.ones(dim)) |
| 241 | |
| 242 | def forward(self, x): |
| 243 | return self._norm(x.float()).type_as(x) * self.weight |
| 244 | |
| 245 | def _norm(self, x): |
| 246 | return x * torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps) |
| 247 | |
| 248 | |
| 249 | class WanLayerNorm(nn.LayerNorm): |