> This page is for version 0.5.0 · 26.06.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.models.glm4_moe.layers

## Module Contents

### Classes

| Name                                                                                     | Description                                                                 |
| ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| [`Glm4MoeAttention`](#nemo_automodel-components-models-glm4_moe-layers-Glm4MoeAttention) | GLM4 MoE attention with optional query/key per-head RMSNorm + partial RoPE. |

### API

```python
class nemo_automodel.components.models.glm4_moe.layers.Glm4MoeAttention(
    config: transformers.models.glm4_moe.configuration_glm4_moe.Glm4MoeConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**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`**

---

```python
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
```

```python
nemo_automodel.components.models.glm4_moe.layers.Glm4MoeAttention.init_weights(
    buffer_device: torch.device,
    init_std: float = 0.02
)
```