Update rmsnorm.py
Browse filesModifies the forward pass of RMSNorm to avoid mixed precision issues as described in https://github.com/chandar-lab/AMPLIFY/issues/19
19 unmodified lines2021222324255 unmodified lines3132333419 unmodified linesself.eps = epsself.weight = nn.Parameter(torch.ones(dim))def forward(self, x):"""Forward pass through the RMSNorm layer.5 unmodified linestorch.Tensor: The output tensor after applying RMSNorm."""return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps) * self.weight19 unmodified lines2021222324252627285 unmodified lines343536373819 unmodified linesself.eps = epsself.weight = nn.Parameter(torch.ones(dim))def _norm(self, x):return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)def forward(self, x):"""Forward pass through the RMSNorm layer.5 unmodified linestorch.Tensor: The output tensor after applying RMSNorm."""output = self._norm(x.float()).type_as(x) # Avoids mixed precision issues as in https://github.com/chandar-lab/AMPLIFY/issues/19return output * self.weight
rmsnorm.py+5-1