> 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.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/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.

# nemo_automodel.components.models.glm_moe_dsa.flops

Useful model FLOPs for GLM MoE DSA (GLM-5.x) training.

## Module Contents

### Functions

| Name                                                                                               | Description                                                                                               |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
| [`_causal_capped_pairs`](#nemo_automodel-components-models-glm_moe_dsa-flops-_causal_capped_pairs) | Sum over one-based query positions of `min(position, cap)`.                                               |
| [`_layer_has_indexer`](#nemo_automodel-components-models-glm_moe_dsa-flops-_layer_has_indexer)     | Mirror `Block.__init__`: only IndexShare `"shared"` layers own no indexer.                                |
| [`_layer_is_moe`](#nemo_automodel-components-models-glm_moe_dsa-flops-_layer_is_moe)               | Mirror `Block.__init__`: `mlp_layer_types` wins, else the first `first_k_dense_replace` layers are dense. |
| [`model_flops`](#nemo_automodel-components-models-glm_moe_dsa-flops-model_flops)                   | Count useful GEMM FLOPs for one optimizer step of full-parameter GLM MoE DSA training.                    |

### API

```python
nemo_automodel.components.models.glm_moe_dsa.flops._causal_capped_pairs(
    length: int,
    cap: int
) -> int
```

Sum over one-based query positions of `min(position, cap)`.

```python
nemo_automodel.components.models.glm_moe_dsa.flops._layer_has_indexer(
    config: transformers.models.glm_moe_dsa.configuration_glm_moe_dsa.GlmMoeDsaConfig,
    layer_idx: int
) -> bool
```

Mirror `Block.__init__`: only IndexShare `"shared"` layers own no indexer.

```python
nemo_automodel.components.models.glm_moe_dsa.flops._layer_is_moe(
    config: transformers.models.glm_moe_dsa.configuration_glm_moe_dsa.GlmMoeDsaConfig,
    layer_idx: int
) -> bool
```

Mirror `Block.__init__`: `mlp_layer_types` wins, else the first `first_k_dense_replace` layers are dense.

```python
nemo_automodel.components.models.glm_moe_dsa.flops.model_flops(
    config: transformers.models.glm_moe_dsa.configuration_glm_moe_dsa.GlmMoeDsaConfig,
    gbs: int = 1,
    seq_len: int | None = None
) -> float
```

Count useful GEMM FLOPs for one optimizer step of full-parameter GLM MoE DSA training.

The MLA projections, the dense MLPs, the active routed and shared experts, the router
and the LM head count forward and backward (6 FLOPs per MAC). Sparse attention counts
the unabsorbed MLA form over the keys a causal query can select: one-based position
`i` attends to `min(i, index_topk)` keys. The indexer exists only on
`indexer_types == "full"` layers and receives no gradient (its top-k selection is
discrete and its scores feed nothing else), so its projections and causal score GEMM
count forward only (2 FLOPs per MAC); IndexShare `"shared"` layers reuse the previous
selection at no indexer cost. The AutoModel GLM model has no MTP module, so
`num_nextn_predict_layers` adds nothing.

Counts assume one unpadded document per sequence. Activation recomputation, the extra
latent-width work of the absorbed sparse kernels, norms, RoPE, softmax, the top-k
selection, communication and optimizer updates are excluded, as in the other MFU
formulas.

**Parameters:**

**`config`** `GlmMoeDsaConfig`

GLM MoE DSA configuration.

---

**`gbs`** `int` — default: 1

Sequences per global optimizer step.

---

**`seq_len`** `int | None` — default: None

Tokens per sequence; defaults to `max_position_embeddings`.

---

**Returns:** `float`

Model FLOPs across all devices for one optimizer step.

**Raises:**

* `ValueError`: `gbs`, the sequence length or `index_topk` is not positive.