Skip to navigation

nemo_automodel.components.models.glm4_moe.layers

View as Markdown

Module Contents

Classes

NameDescription
Glm4MoeAttentionGLM4 MoE attention with optional query/key per-head RMSNorm + partial RoPE.

API

class nemo_automodel.components.models.glm4_moe.layers.Glm4MoeAttention(
config: transformers.models.glm4_moe.configuration_glm4_moe.Glm4MoeConfig,
)

Bases: Module

GLM4 MoE attention with optional query/key per-head RMSNorm + partial RoPE.

Key differences from Qwen3 MoE:

  • Optional QK normalization (controlled by use_qk_norm)
  • Partial rotary embeddings (controlled by partial_rotary_factor)
  • o_proj bias is False (unlike Qwen3 which has configurable attention_bias)

Shapes:

  • Input: x -> [B, S, H]
  • Projections: q: [B, S, n_heads, head_dim] k/v: [B, S, n_kv_heads, head_dim] -> repeated to n_heads via groups
  • Output: [B, S, H]
head_dim
k_norm
k_proj
num_heads
= config.num_attention_heads
num_kv_heads
= config.num_key_value_heads
o_proj
partial_rotary_factor
= getattr(config, 'partial_rotary_factor', 0.5)
q_norm
q_proj
use_qk_norm
= config.use_qk_norm
v_proj
nemo_automodel.components.models.glm4_moe.layers.Glm4MoeAttention.forward(
x: torch.Tensor,
freqs_cis: torch.Tensor,
attention_mask: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor
nemo_automodel.components.models.glm4_moe.layers.Glm4MoeAttention.init_weights(
buffer_device: torch.device,
init_std: float = 0.02
)