Repository navigation
Validate packed size against quant_state.shape in dequantize_4bit - #2107
Open
tritsystem wants to merge 1 commit into
Open
tritsystem wants to merge 1 commit into
tritsystem wants to merge 1 commit into
Conversation
dequantize_4bit trusts quant_state.shape (and absmax length) to decide how many 4-bit values to read from the packed tensor, but never checks the packed tensor is large enough. A QuantState whose shape claims more elements than the packed weight holds -- e.g. reconstructed from a corrupt or crafted checkpoint via Params4bit.from_prequantized / QuantState.from_dict -- makes kDequantizeBlockwise read past the end of the packed buffer (confirmed with compute-sanitizer: "Invalid __global__ read ... out of bounds"). Add a size check so an inconsistent state raises a clear ValueError instead of reading out of bounds, plus a matching check on the absmax length. The honest round-trip path is unchanged.
Author
|
A scope note for reviewers: this PR adds the packed-size check in If you'd prefer, the check could live where the shape first arrives from serialized data ( |
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.
What / why
Fixes #2106.
dequantize_4bittrustsquant_state.shape(and theabsmaxlength) to decide how many 4-bit values to read from the packed tensor, but never checks the packed tensor is large enough. AQuantStatewhoseshapeclaims more elements than the packed weight holds — e.g. reconstructed from a corrupt or crafted checkpoint viaParams4bit.from_prequantized/QuantState.from_dict— makeskDequantizeBlockwiseread past the end of the packed buffer.compute-sanitizer(withPYTORCH_NO_CUDA_MEMORY_CACHING=1):Per
agents/security_guide.mdTier 7, this is framed as a correctness/reliability issue (out-of-bounds read → wrong results / possible crash), not a traditional exploit.Fix
Add a size check in
dequantize_4bit: if the packed tensor can't holdprod(quant_state.shape)4-bit values (orabsmaxis shorter than the implied block count), raise a clearValueErrorinstead of reading out of bounds. The capacity is computed asA.numel() * A.element_size() * 2, which is correct regardless ofquant_storagewidth. The honest round-trip path is unchanged.Test
tests/test_ops.py::Test4bitBlockwiseQuantOps::test_dequantize_4bit_rejects_shape_larger_than_packedbuilds a 32-byte packed tensor with aQuantStateclaiming(4096, 4096)and asserts aValueErroris raised.test_ops.pyare unaffected (verified against the installed 0.50.0 binary — pure-Python change, so no rebuild needed).The repo's
pre-commitsuite passes on both changed files.I used Claude Code as my assistant to investigate, fix, and verify this issue; I reviewed the analysis and the fix before submitting.