Add padded-buffer KV corruption reproductions - #338
Conversation
|
Independent confirmation of this bug from a downstream project (a Qwen2.5-Coder-14B-4bit server built on mlx-rs 0.25.3), plus two findings that may help localize it. Confirmed against a real model + reference, not just synthetic arrays. Per-position top-k logit dump at greedy temp=0, mlx-rs vs Python
Finding 1 — it is not limited to padded buffers. It also reproduces with the default lazy Finding 2 — architecture-dependent visibility (useful as a diagnostic). Dense, no-QK-norm models (Qwen2, Mistral) garble visibly. A QK-norm model (Qwen3.5/3.6 MoE) appears clean through the same cache — the per-head RMSNorm on Q/K renormalizes the zeroed tail and masks the corruption. So the corruption is present model-agnostically (as you note, below the model layer); QK-norm just hides it. Also consistent with this issue: the output is evaluation-order-dependent — forcing the cache to materialize each step (eager eval, a pre-allocated Happy to share the argmax-parity harness (Rust dump + Python reference dump + diff) and the per-layer norm probe if useful. Thanks for the diagnostic repros here — they matched our independent investigation exactly. |
|
Correction to my earlier comment above. I attributed our downstream dense-model decode garble to this KV-cache / padded-buffer corruption. That was wrong, and I want to set the record straight. The actual root cause in our project was the RoPE reshape round-trip in Why it looked like cache corruption: RoPE mangles the non-contiguous transposed-view q/k during decode ( Your padded-buffer repros here may still capture a separate latent contiguity issue worth keeping; I just can't claim they were the cause of the symptom I reported. Apologies for the noise — and thanks for the diagnostics that kept me looking at the contiguity angle, which is ultimately where it was. |
Summary
Adds minimal reproductions for a lower-level padded-buffer corruption issue observed while investigating KV cache growth. This PR is intentionally diagnostic only; it does not attempt a fix.
What is included
KVCachevsConcatKeyValueCachereproduction tests inmlx-lm/src/cache.rstry_index_mutreproductionconcatenate(prefix, token, zero_pad)reproductionconcatenate(prefix, token)worksKey finding
The failure reproduces below the Qwen2/model layer. Appending or concatenating into a padded-capacity buffer can yield a live prefix view whose tail is zeroed where the appended token should be.
Current status