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
| 13 | |
| 14 | |
| 15 | class 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 | |
| 39 | class Transformer(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected