Skip to navigation

nemo_automodel.components.models.glm_moe_dsa.flops

View as MarkdownOpen in Claude

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

Module Contents

Functions

NameDescription
_causal_capped_pairsSum over one-based query positions of min(position, cap).
_layer_has_indexerMirror Block.__init__: only IndexShare "shared" layers own no indexer.
_layer_is_moeMirror Block.__init__: mlp_layer_types wins, else the first first_k_dense_replace layers are dense.
model_flopsCount useful GEMM FLOPs for one optimizer step of full-parameter GLM MoE DSA training.

API

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).

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.

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.

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
intDefaults to 1

Sequences per global optimizer step.

seq_len
int | NoneDefaults to 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.