r""" Args: x(Tensor): Shape [B, L, C]
(self, x)
| 85 | self.weight = nn.Parameter(torch.ones(dim)) |
| 86 | |
| 87 | def forward(self, x): |
| 88 | r""" |
| 89 | Args: |
| 90 | x(Tensor): Shape [B, L, C] |
| 91 | """ |
| 92 | return self._norm(x.float()).type_as(x) * self.weight |
| 93 | |
| 94 | def _norm(self, x): |
| 95 | return x * torch.rsqrt(x.pow(2).mean(dim=-1, keepdim=True) + self.eps) |