Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/transformers/models/aimv2/modeling_aimv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/apertus/modeling_apertus.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/apertus1p5/modeling_apertus1p5.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/arcee/modeling_arcee.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/aria/modeling_aria.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/axk1/modeling_axk1.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/axk2/modeling_axk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/bamba/modeling_bamba.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,11 +829,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/bitnet/modeling_bitnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/blt/modeling_blt.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/chameleon/modeling_chameleon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/clvp/modeling_clvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/cohere2_moe/modeling_cohere2_moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/cosmos3_edge/modeling_cosmos3_edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/csm/modeling_csm.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/cwm/modeling_cwm.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
18 changes: 8 additions & 10 deletions src/transformers/models/deepseek_ocr2/modeling_deepseek_ocr2.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down Expand Up @@ -1201,11 +1200,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
9 changes: 4 additions & 5 deletions src/transformers/models/deepseek_v2/modeling_deepseek_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ def __init__(self, hidden_size, eps: float = 1e-6) -> None:
self.variance_epsilon = eps

def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
input_dtype = hidden_states.dtype
hidden_states = hidden_states.to(torch.float32)
variance = hidden_states.pow(2).mean(-1, keepdim=True)
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
return self.weight * hidden_states.to(input_dtype)
# Don't pass the weight to rms_norm: scaling after the cast to the input dtype (autocast runs rms_norm in
# fp32) keeps the rounding and output dtype of the original implementations, fusing it shifts the logits
normalized = nn.functional.rms_norm(hidden_states, hidden_states.shape[-1:], eps=self.variance_epsilon)
return self.weight * normalized.to(hidden_states.dtype)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
Expand Down
Loading
Loading