Spaces:
Runtime error
Runtime error
File size: 438 Bytes
982a4de |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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
|