Repository navigation
Conversation
The CUDA implementations of int8_vectorwise_quant, int8_linear_matmul and int8_mm_dequant pass raw pointers to the kernels and cuBLASLt, which assume dense row-major storage. A strided view such as hidden_states[:, 0] was read as if it were dense, so every row except the first was silently wrong. Convert the inputs to contiguous first, as bitsandbytes-foundation#1859 did for the blockwise and 4-bit ops, and add regression tests. Fixes bitsandbytes-foundation#2130 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
int8_vectorwise_quant,int8_linear_matmulandint8_mm_dequantbefore their raw pointers go to the kernels and cuBLASLt. This is the same approach Handle non-contiguous tensors in quantize/dequantize ops #1859 took for the blockwise and 4-bit ops.hidden_states[:, 0]in BERT-style poolers and classification heads, andhidden_states[:, -1:, :]with batch > 1. Every row except the first comes from the wrong address, and nothing reports an error.Linear8bitLtwith fp16 activations reaches this throughMatMul8bitLt. The repro and the effect on real models are in LLM.int8(): int8 CUDA ops ignore input strides, so Linear8bitLt silently returns wrong rows for non-contiguous inputs like hidden_states[:, 0] #2130..contiguous()returns the tensor itself when it is already contiguous, so the usual path does not change.Fixes #2130
Test plan
TestNonContiguousInputs(tests/test_ops.py):test_int8_vectorwise_quant_non_contiguous(threshold 0.0 and 6.0, with an outlier column)test_int8_linear_matmul_non_contiguoustest_int8_mm_dequant_non_contiguoustest_linear8bitlt_non_contiguous_input(tests/test_linear8bitlt.py), coveringh[:, 0]andh[:, -1:, :]with threshold 0.0 and 6.0.main@ a616886 with-DCOMPUTE_CAPABILITY=89: the 6 new CUDA test cases fail without the change and pass with it. With the change,TestNonContiguousInputsplus the newLinear8bitLttest give 84 passed, 36 skipped.tests/test_ops.py,tests/test_linear8bitlt.py,tests/test_functional.pyandtests/test_autograd.py, selected with-k "int8 or Int8 or matmullt or linear8bit or NonContiguous or non_contiguous or LLMInt8 or linear_no_igemmlt". With the change: 1338 passed, 52 skipped, 2 xfailed. Without it: 1332 passed, and the only failures are the 6 new CUDA test cases.ruff checkandruff format --check(ruff 0.14.x) are clean.main@ a616886. Models were loaded withload_in_8bit=Trueanddtype=torch.float16, and a batch of 8 was compared with running the same inputs one at a time:distilbert-base-uncased-finetuned-sst-2-english: before the change, every sentence in the batch is labelled positive (agreement 0.50); after it, the labels match (agreement 1.00).cross-encoder/ms-marco-MiniLM-L6-v2: the top-3 goes from[4, 0, 3]back to[0, 2, 6].🤖 Generated with Claude Code