Skip to content

Static attention: support overriding RMSNorm class #12833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
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
12 changes: 9 additions & 3 deletions examples/models/llama/static_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,9 @@ def _forward_mha(

return y.transpose(1, 2).contiguous().view(bsz, seq_len, -1), out_cache_state

def load_weights_from_attention_mha(self, other: AttentionMHA):
def load_weights_from_attention_mha(
self, other: AttentionMHA, rms_norm_class=torch.nn.RMSNorm
):
if self.split_mha:
for i in range(self.n_heads):
self.wqs[i].weight.data.copy_(
Expand All @@ -864,9 +866,13 @@ def load_weights_from_attention_mha(self, other: AttentionMHA):
if other.use_qk_norm:
self.use_qk_norm = True
self.qk_norm_before_rope = other.qk_norm_before_rope
self.q_norm = torch.nn.RMSNorm(other.q_norm_fn.dim, other.q_norm_fn.eps)
self.q_norm = rms_norm_class(other.q_norm_fn.dim, other.q_norm_fn.eps).to(
other.q_norm_fn.weight.dtype
)
self.q_norm.load_state_dict(other.q_norm_fn.state_dict())
self.k_norm = torch.nn.RMSNorm(other.k_norm_fn.dim, other.k_norm_fn.eps)
self.k_norm = rms_norm_class(other.k_norm_fn.dim, other.k_norm_fn.eps).to(
other.k_norm_fn.weight.dtype
)
self.k_norm.load_state_dict(other.k_norm_fn.state_dict())

def adopt_hf_rope(self):
Expand Down
Loading