Repository navigation
fix: count only attention layers in NemotronH KV memory - #544
Conversation
Signed-off-by: Alexandre Milesi <milesial@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📜 Recent review details
📝 Summary
Merge Risk: ⚪ Minimal · up to
|
tedzhouhk
left a comment
There was a problem hiding this comment.
Reviewed 84c34f45; no new correctness issue found. Counting attention layers from the normalized hybrid pattern fixes attention-KV sizing while preserving KV-head sharding/replication (including TP greater than the KV-head count).
Validation on the exact head: 547 model/config/memory tests passed, plus 72 independent model/topology/dtype cases and 12 public estimate_kv_cache() cases. The cited Super 120B FP8 model gives 4,096 bytes/token at TP1 and 2,048 at TP2/TP4, with the inverse capacity calculation consistent.
The 11x correction is attention KV bytes/token for that model, not total GPU memory. Mamba recurrent-state sizing remains separate; this PR does not add automatic Nemotron state sizing. No end-to-end GPU accuracy validation was performed.
Why and what changed
NemotronH inherits attention KV accounting that multiplies by every layer in the model. Its hybrid stack includes Mamba, MoE, and MLP layers that do not allocate attention KV. This overstates the token-dependent memory cost and understates KV token capacity.
Count only attention layers from the hybrid pattern while preserving KV-head sharding and replication across tensor-parallel ranks. For the bundled Nemotron 3 Super configuration at TP1, this changes FP8 attention KV from 45,056 to 4,096 bytes per token: 8 attention layers × 2 KV heads × 128 elements × K/V.
Review map
NemotronHModel.get_kvcache_elements_per_token.Evidence
Modeling or data provenance
Attention tensor geometry from the bundled
nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-FP8configuration. This is a memory-accounting correction, not a measured latency calibration.