Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix transpose 4bit #1301

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bitsandbytes/backends/cpu_xpu_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def quantize_4bit_impl(
state.absmax = torch.Tensor()
return torch.Tensor(), state

return out, state
return out.unsqueeze(0), state


@_maybe_torch_compile
Expand Down Expand Up @@ -428,6 +428,13 @@ def dequantize_4bit_impl(
Dequantized tensor.
"""

if A.shape[0] == 1:
transpose = False
A = A.squeeze(0)
elif A.shape[1] == 1:
transpose = True
A = A.squeeze(1)

if quant_state is None:
assert absmax is not None and out is not None

Expand Down Expand Up @@ -484,6 +491,9 @@ def dequantize_4bit_impl(
out_reshaped[n - rem :] = out_dq[n - rem :] * absmax[-1]

# take transpose here because weight is transposed (again) for computation
if transpose:
out = out.t()

return out


Expand Down