Skip to content
Open
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
8 changes: 6 additions & 2 deletions bitsandbytes/autograd/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def forward(ctx, A, B, out=None, bias=None, state=MatmulLtState):
B = state.CB

CB = state.CB.data.to(A.dtype).mul_(state.SCB.unsqueeze(1).mul(1.0 / 127.0))
output = torch.nn.functional.linear(A, CB, bias)
with torch.no_grad():
output = torch.nn.functional.linear(A, CB, bias)
ctx.state = state
ctx.dtype_A = A.dtype
ctx.grad_shape = A.shape
Expand Down Expand Up @@ -317,7 +318,10 @@ def forward(ctx, A, B, out=None, bias=None, quant_state: Optional[F.QuantState]

# 1. Dequantize
# 2. MatmulnN
output = torch.nn.functional.linear(A, F.dequantize_4bit(B, quant_state).to(A.dtype).t(), bias)
# no_grad prevents F.linear from saving the dequantized weight
# (MatMul4Bit.backward re-dequantizes from NF4 anyway)
with torch.no_grad():
output = torch.nn.functional.linear(A, F.dequantize_4bit(B, quant_state).to(A.dtype).t(), bias)
if out is not None:
out.copy_(output)
output = out
Expand Down