Repository navigation
Conversation
This branch has not been deployed
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.
Problem
The CPU quantization LUT cache checks the codebook pointer and only four entries: 0, 1, 127 and 255. A caller can update other entries of a valid, sorted, contiguous codebook in place while all four sampled values stay unchanged. The cache then returns the old LUT, so the encoded weights no longer agree with the new codebook saved in QuantState.
Changes
Keep a complete 256-value codebook snapshot in each cache slot. Reuse a cached LUT only when the pointer and every value match; copy the new snapshot after rebuilding the LUT.
The four-slot replacement policy, existing locking and LUT quantization algorithm remain unchanged. The snapshots add approximately 4 KB of static storage and compare 256 float values on a pointer match.
Validation
Native CPU source builds and regression tests, source
5fa7276f1f2590b7e27419c02ddd05f25b5b1612:git diff --checkpassed.The runner separately rebuilt the original and patched CPU shared libraries with the repository's CMake build, verified different library hashes, and used fresh Python processes for each revision. Environment: Ubuntu 24.04, Python 3.12, PyTorch 2.14.0+cpu.
Tests cover FP16/BF16/FP32, two block sizes, changes in either codebook half that preserve the old fingerprint, an independent nearest-code reference, unchanged maps, cache-slot replacement, and actual saved quantized weights used by a linear layer.
This fixes stale-cache correctness for codebook updates. It does not change LUT approximation, cache concurrency guarantees or GPU kernels, and makes no claim of improved model quality or general speed.