MCPcopy Create free account
hub / github.com/kyegomez/BitNet / RMSNorm

Class RMSNorm

bitnet/bit_transformer.py:15–36  ·  view source on GitHub ↗

Root Mean Square Normalization (RMSNorm) module. Args: dim (int): The input dimension. affine (bool, optional): If True, apply an affine transformation to the normalized output. Default is True. Attributes: scale (float): The scaling factor for the

Source from the content-addressed store, hash-verified

13
14
15class RMSNorm(nn.Module):
16 """
17 Root Mean Square Normalization (RMSNorm) module.
18
19 Args:
20 dim (int): The input dimension.
21 affine (bool, optional): If True, apply an affine transformation to the normalized output.
22 Default is True.
23
24 Attributes:
25 scale (float): The scaling factor for the normalized output.
26 gamma (torch.Tensor or float): The learnable parameter for the affine transformation.
27
28 """
29
30 def __init__(self, dim, affine=True):
31 super().__init__()
32 self.scale = dim**0.5
33 self.gamma = nn.Parameter(torch.ones(dim)) if affine else 1.0
34
35 def forward(self, x):
36 return l2norm(x) * self.gamma * self.scale
37
38
39class Transformer(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected