This commit is contained in:
Jukka Seppänen
2024-10-10 23:12:11 +03:00
parent e05cd55498
commit 88f4d14666
3 changed files with 29 additions and 22 deletions
+10 -4
View File
@@ -57,10 +57,16 @@ class RMSNorm(nn.Module):
hidden_states = hidden_states * torch.rsqrt(variance + self.eps)
if self.weight is not None:
# convert into half-precision if necessary
if self.weight.dtype in [torch.float16, torch.bfloat16]:
hidden_states = hidden_states.to(self.weight.dtype)
hidden_states = hidden_states * self.weight
# Handle the case where self.weight is torch.float8_e4m3fn
if self.weight.dtype == torch.float8_e4m3fn:
weight = self.weight.to(torch.float32)
else:
weight = self.weight
# Convert hidden_states to the dtype of weight if necessary
if hidden_states.dtype != weight.dtype:
hidden_states = hidden_states.to(weight.dtype)
hidden_states = hidden_states * weight
hidden_states = hidden_states.to(input_dtype)