| 11 | |
| 12 | # taken straight from https://github.com/johnma2006/mamba-minimal/blob/master/model.py |
| 13 | class RMSNorm(nn.Module): |
| 14 | def __init__(self, dim: int, eps: float = 1e-5): |
| 15 | super().__init__() |
| 16 | |
| 17 | self.eps = eps |
| 18 | self.weight = nn.Parameter(torch.ones(dim)) |
| 19 | |
| 20 | def forward(self, x): |
| 21 | output = ( |
| 22 | x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) * self.weight |
| 23 | ) |
| 24 | |
| 25 | return output |
| 26 | |
| 27 | |
| 28 | class PScan(torch.autograd.Function): |