DeepSpeed
e74c7071 - Preallocate the static KV cache with config.head_dim (#8389)

Commit
86 days ago
Preallocate the static KV cache with config.head_dim (#8389) `DeepSpeedStaticCache` preallocates its KV buffers with `hidden_size // num_attention_heads`. Models that set `head_dim` explicitly (Qwen3, Gemma, Llama 4) break that identity, so the buffers get the wrong last dimension and the prefill copy in `_generate_graph` dies before the graph is ever captured: ``` RuntimeError: The size of tensor a (16) must match the size of tensor b (32) at non-singleton dimension 3 ``` Now it reads `head_dim` off the config and falls back to the division when the attribute is missing or None (older configs set it to None). To reproduce on CPU: a tiny Qwen3 with `hidden_size=64`, `num_attention_heads=4`, `head_dim=32`, prefilled through the HF `StaticCache` the way `_generate_graph` does, then the copy loop at `hybrid_engine_rollout.py:346` verbatim. The prefill cache comes back `(1, 2, 8, 32)` and `DeepSpeedStaticCache` allocates `(1, 2, 8, 16)`. With `head_dim=16` the same script is fine on both sides, which is why nothing has caught this so far. Two tests in `tests/unit/runtime/rollout/`. The `head_dim` one fails on master. No GPU on this machine, so the capture and replay path itself is not exercised, only the allocation and the copy that feeds it. Signed-off-by: Ehsan Barkhordar <realbarkhordar@gmail.com> Co-authored-by: Ma, Guokai <guokai.ma@gmail.com>
Author
Parents
Loading