Skip to content

Commit 95dafc6

Browse files
committed
cast before allclose
1 parent 37f805b commit 95dafc6

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

tests/test_modules.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ def test_linear8bitlt_no_fp16_weights(threshold, memory_efficient_backward):
541541
mlp = MLP8bit(
542542
32, 64, threshold=threshold, has_fp16_weights=False, memory_efficient_backward=memory_efficient_backward
543543
)
544-
w1, w2 = mlp.fc1.weight.clone(), mlp.fc2.weight.clone()
545-
mlp = mlp.cuda().half()
544+
w1, w2 = mlp.fc1.weight.clone(), mlp.fc2.weight.clone() # note: we grad original weights before quantization,
545+
mlp = mlp.cuda().half() # and this line triggers quantization
546546

547547
for i in range(100):
548548
b1 = torch.randn(16, 8, 32, device="cuda").half()
@@ -567,8 +567,7 @@ def test_linear8bitlt_no_fp16_weights(threshold, memory_efficient_backward):
567567

568568
mlp.zero_grad()
569569
(o1 * grad_proj).sum().backward()
570-
assert False, (w1, w2)
571-
grad_ref = grad_proj.flatten(2) @ w2 @ w1
570+
grad_ref = grad_proj.flatten(2) @ w2.to(grad_proj.device) @ w1.to(grad_proj.device)
572571
assert torch.allclose(b1.grad, grad_ref)
573572

574573

0 commit comments

Comments
 (0)