You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Memory] Implement QK attention head chunking to prevent HBM OOM
Currently, evaluating the QK dot product natively in MLA materializes
the full [batch, count_of_heads, q_len, kv_len] attention scores tensor.
This causes severe memory constraints (HBM OOM) for large context lengths.
This change introduces the Config variable `qk_head_chunk_size` alongside
a `jax.lax.scan` algorithm. Since the `heads` dimension is locally dense
and unsharded (unlike `q_len` which is Context Parallel), we scan over
groups of heads iteratively computing query-key projections and their softmax
partials, avoiding vast intermediate allocations.
Copy file name to clipboardExpand all lines: src/maxtext/configs/base.yml
+4Lines changed: 4 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -192,6 +192,8 @@ logits_dot_in_fp32: false # whether to use fp32 in logits_dense or shared_embed
192
192
cast_logits_to_fp32: true # whether to cast the logits to fp32. the higher precision is generally beneficial, but it can vary slightly.
193
193
float32_qk_product: false # in dot_product attention, whether to cast to fp32 the inputs to qk product
194
194
float32_logits: false # in dot_product attention, whether to cast to fp32 the inputs to softmax
195
+
# Limits HBM footprint by sequentially evaluating the QK matrix across the unsharded local heads dimension natively. Size must evenly divide the number of attention heads. Note: This parameter is currently specific to MLA attention.
196
+
mla_qk_head_chunk_size: 0
195
197
float32_weight_sum: true # whether to use full fp32 precision to sum expert weights for numerical stability
196
198
float32_gate_logits: false # whether to cast inputs to fp32 to compute MoE gate logits for numerical stability
0 commit comments