Spaces:
Runtime error
Runtime error
Download models/norm.py from Linly-AI/Linly-ChatFlow: direct link, hf CLI and curl.
- Browser
- Download file 438 Bytes
-
https://huggingface.co/spaces/Linly-AI/Linly-ChatFlow/resolve/main/models/norm.py
- Command line
-
hf download hf://spaces/Linly-AI/Linly-ChatFlow/models/norm.py
-
curl -L -o norm.py https://huggingface.co/spaces/Linly-AI/Linly-ChatFlow/resolve/main/models/norm.py
438 Bytes
| from torch import nn | |
| import torch | |
| class RMSNorm(torch.nn.Module): | |
| def __init__(self, hidden_size, eps=1e-6): | |
| super().__init__() | |
| self.eps = eps | |
| self.weight = nn.Parameter(torch.ones(hidden_size)) | |
| def _norm(self, x): | |
| return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) | |
| def forward(self, x): | |
| output = self._norm(x.float()).type_as(x) | |
| return output * self.weight | |