[Model] Switch to Fused RMSNorm in GLM-4.1V model (#24733)

Signed-off-by: SamitHuang <285365963@qq.com>
This commit is contained in:
Samit 2025-09-13 00:12:23 +08:00 committed by GitHub
parent b0d1213ac3
commit f17c075884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -419,15 +419,16 @@ class Glm4vVisionBlock(nn.Module):
max_seqlen: Optional[int] = None, # Only used for Flash Attention
seqlens: Optional[list[int]] = None, # Only used for xFormers
) -> torch.Tensor:
x = x + self.attn(
x_attn = self.attn(
self.norm1(x),
cu_seqlens=cu_seqlens,
rotary_pos_emb=rotary_pos_emb,
max_seqlen=max_seqlen,
seqlens=seqlens,
)
x_fused_norm, residual = self.norm2(x, residual=x_attn)
x = residual + self.mlp(x_fused_norm)
x = x + self.mlp(self.norm2(x))
return x