MCPcopy Create free account
hub / github.com/UVA-Computer-Vision-Lab/FrameINO / WanRMS_norm

Class WanRMS_norm

architecture/autoencoder_kl_wan.py:179–202  ·  view source on GitHub ↗

r""" A custom RMS normalization layer. Args: dim (int): The number of dimensions to normalize over. channel_first (bool, optional): Whether the input tensor has channels as the first dimension. Default is True. images (bool, optional): Whether the input r

Source from the content-addressed store, hash-verified

177
178
179class WanRMS_norm(nn.Module):
180 r"""
181 A custom RMS normalization layer.
182
183 Args:
184 dim (int): The number of dimensions to normalize over.
185 channel_first (bool, optional): Whether the input tensor has channels as the first dimension.
186 Default is True.
187 images (bool, optional): Whether the input represents image data. Default is True.
188 bias (bool, optional): Whether to include a learnable bias term. Default is False.
189 """
190
191 def __init__(self, dim: int, channel_first: bool = True, images: bool = True, bias: bool = False) -> None:
192 super().__init__()
193 broadcastable_dims = (1, 1, 1) if not images else (1, 1)
194 shape = (dim, *broadcastable_dims) if channel_first else (dim,)
195
196 self.channel_first = channel_first
197 self.scale = dim**0.5
198 self.gamma = nn.Parameter(torch.ones(shape))
199 self.bias = nn.Parameter(torch.zeros(shape)) if bias else 0.0
200
201 def forward(self, x):
202 return F.normalize(x, dim=(1 if self.channel_first else -1)) * self.scale * self.gamma + self.bias
203
204
205class WanUpsample(nn.Upsample):

Callers 4

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected