nemo_automodel.components.models.glm5_next.flops
nemo_automodel.components.models.glm5_next.flops
Backend-independent training FLOPs for the GLM-5.3 text backbone.
Module Contents
Functions
API
Count useful forward/backward FLOPs for unpadded, independent sequences.
Trainable matrix products cost six FLOPs per MAC (forward, input gradient,
weight gradient). KDA uses the recurrent equation’s three contractions per
head, or 18 * heads * head_dim**2 training FLOPs per token. Extra chunk
algorithm work is excluded, as are activation recomputation and CP replicas.
DSA uses expanded QK/value widths, independent of the backend’s equivalent
latent absorption. Its KPool indexer runs without gradients, so projections
and causal pool scoring cost two FLOPs per MAC; masked future pools and
padded sparse slots are excluded.
Includes dense/MoE SwiGLU, selected and shared experts, router, language-model
head, mHC coefficient projections and stream contractions, and causal short
convolutions. Norms, activations, softmax, top-k, communication and optimizer
work are excluded. The checkpoint’s unused MTP head and vision tower are not
counted. Use benchmark.flops_scope: text for the composite model.
For the released 45-layer configuration with index_kpool=4, this fixed
convention gives 104.177535648 GFLOPs/token at 4096 tokens. A packed batch
requires summing this formula over its actual document lengths; treating a
pack of short documents as one long sequence overcounts sparse/indexer work.
Parameters:
Native text configuration, including effective layer patterns.
Number of independent sequences in the global optimizer step.
Valid tokens in each sequence; defaults to the context limit.
Returns: float
Global training FLOPs, before division by device count or elapsed time.
Raises:
ValueError: If the global batch size or sequence length is not positive.