nemo_automodel.components.models.ergo.flops
nemo_automodel.components.models.ergo.flops
Useful model FLOPs for Ergo training.
Module Contents
Functions
API
Count useful GEMM FLOPs for one optimizer step of full-parameter Ergo training.
A multiply-accumulate (MAC) is two FLOPs. Every counted product is trainable, so it counts the forward pass, the input gradient and the weight gradient (six FLOPs per MAC); attention counts the same three passes over its two operands. Per layer and token:
- The fused query/key/value projection,
hidden * (heads + 2 * kv_heads) * head_dim, and the output projection,heads * head_dim * hidden. - Attention:
heads * 2 * head_dimper permitted query-key pair (QK^TandPV; grouped keys and values are repeated to every query head). Everyglobal_attention_every_n_layers-th layer permits theS * (S + 1) / 2causal pairs. The other layers use a window that includes the query itself, so the query at one-based positionpattendsmin(p, window)keys. - A leading dense block: the up and down projections,
hidden * first_dense_intermediate_sizeeach. - An MoE block: the router,
hidden * experts;top-krouted experts of2 * hidden * moe_intermediate_size(up and down, no gate projection); and the shared expert,2 * hidden * shared_intermediate_size.
The LM head adds hidden * vocab per token; the embedding lookup has no GEMM.
Counted work is the algorithmic model FLOPs (MFU), independent of the backend: a dense attention kernel also executes the masked pairs. Elementwise operations (RMS norms, RoPE, ReLU squared, the residual blends, softmax, top-k), activation recomputation, padding, optimizer updates and communication are excluded.
Each sequence is one document without padding. Packed-document FLOPs need the individual document lengths and cannot be inferred from a packed row length.
Parameters:
Effective Ergo configuration.
Number of full-length sequences in the global optimizer step.
Tokens in each sequence; defaults to max_position_embeddings.
Returns: float
Useful model FLOPs over all devices for one optimizer step.
Raises:
ValueError:gbsorseq_lenis not positive.