fix(cpu): correctly handle 1D output shape in dequantize_4bit - #2055
Open
SparshM8 wants to merge 1 commit into
Open
fix(cpu): correctly handle 1D output shape in dequantize_4bit#2055SparshM8 wants to merge 1 commit into
SparshM8 wants to merge 1 commit into
Conversation
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.
Description
Fixes #2047.
The CPU kernel for
dequantize_4bitwas unconditionally unsqueezing 1D shapes to(1, n)to satisfy C-library pointer requirements, but it failed to preserve the original 1D shape in the returned tensor. This resulted in an unexpected(1, N)output for a requested(N,)shape, which could cause dimension mismatch errors in downstream code.Changes
bitsandbytes/backends/cpu/ops.pyto use anout_ptr(an unsqueezed view) for C-library calls while maintaining the originalouttensor's shape.out_ptrpattern toquantize_blockwise,dequantize_blockwise, andgemv_4bitkernels for consistency and safety.tests/test_issue_2047.pythat verifies 1D output shapes for all supported dtypes and quantization types on available devices.Testing
Verified with the new regression test on CPU:
Output:
12 passed in 18.96s