fix(ssd-cache): spill native QuantizedKVCache + handle bfloat16 buffer#605
Merged
waybarrios merged 2 commits intoJun 11, 2026
Merged
Conversation
When --kv-cache-quantization is enabled, KV layers are QuantizedKVCache whose keys/values are tuples of (packed, scales, biases); the spill serializer didn't recognize them. Also: numpy's PEP 3118 buffer protocol can't read bfloat16, so cast before serialize. Recreates closed waybarrios#602 on top of latest main. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Single-line wrap on the `mx.dequantize(*layer.keys, ...)` call in the native QuantizedKVCache spill path. CI lint was failing on the original b51d8f4 push because the line exceeded black's 88-char limit.
Owner
|
Merged, thanks. One follow-up worth a small PR: the dequant path casts bf16 to fp16 before spilling but doesn't record the original dtype, so restore hands back fp16 where the model computed bf16. The plain-cache path already solves this with metadata: # existing pattern in _mx_to_numpy_safe
snapshot["keys_original_dtype"] = "bfloat16" # restored on reloadMirroring that for the dequantized layers would keep the round-trip dtype-faithful. While at it, |
This was referenced Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Recreates #602 (branch was deleted) on top of latest
main.Problem
With
--kv-cache-quantizationenabled, KV layers areQuantizedKVCachewhose keys/values are tuples of(packed, scales, biases). The SSD-spill serializer didn't recognize this layout, so spilling a quantized KV cache failed. Separately, numpy's PEP 3118 buffer protocol can't readbfloat16, which broke serialization of bf16 tensors.Fix
_is_quantized_layer) and route them through a serializer that handles the(packed, scales, biases)tuple.bfloat16to a numpy-readable dtype before serialize.tests/test_ssd_cache.py.Supersedes the closed #602; rebased clean on current main.