r""" Args: x(Tensor): Shape [B, L, C]
(self, x)
| 79 | self.weight = nn.Parameter(torch.ones(dim)) |
| 80 | |
| 81 | def forward(self, x): |
| 82 | r""" |
| 83 | Args: |
| 84 | x(Tensor): Shape [B, L, C] |
| 85 | """ |
| 86 | return self._norm(x.float()).type_as(x) * self.weight |
| 87 | |
| 88 | def _norm(self, x): |
| 89 | return x * torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps) |