Repository navigation
Keep codebook quantizer buffers on the input device - #4962
Open
adenzhou1350 wants to merge 1 commit into
Open
adenzhou1350 wants to merge 1 commit into
adenzhou1350 wants to merge 1 commit into
Conversation
Signed-off-by: Xucheng Zhou <aden1350@outlook.com>
adenzhou1350
requested review from
andrewor14,
jerryzh168 and
vkuzo
as code owners
September 30, 2026 12:45
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4962
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Author
|
@andrewor14 could you take a look? This keeps the prototype codebook buffers on the input device. The three new CPU regressions fail on main and pass with the fix, including the QuantizedLinear caller. |
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.
Summary
VectorQuantizerFunctionmoves all three accumulation buffers to the default CUDA device, even when the input and codebook are on CPU. This makes the exportedCodeBookQuantizerand a CPUQuantizedLinearusing it fail during forward.Allocate the FP32 buffers on the existing tensor device instead. Keep the centroid update, empty-cluster handling and straight-through backward unchanged. Replace the two placeholder codebook tests and add a CPU quantized-linear regression. Device subtests also exercise available CUDA devices when run on a GPU host.
Validation
On current main
3972ed015091f659418dedf12edb980a8ca56b53, the three new CPU regressions fail at.cuda()without the production fix.With the fix, native package tests pass:
16 passed, 1 skipped, 2 subtests passed. The skipped test requires Faiss. Python 3.12 / PyTorch 2.12.1+cu130, CUDA hidden:CUDA_VISIBLE_DEVICES='' python -m pytest -q -p no:cacheprovider \ test/prototype/module_swap_quantization/test_quantizers.py \ test/prototype/module_swap_quantization/test_module_swap.py \ test/prototype/module_swap_quantization/test_kmeans_codebook.pyRuff 0.11.6 lint/format, copyright-header check and
git diff --checkpass.The entire directory could not be collected in this source-only environment: Transformers rejects the uninstalled TorchAO version
unknownin a separate test file. No CUDA runtime or Faiss initialization result is claimed.This is a device-correctness fix for the prototype API, not a performance change.