Skip to content

Commit 28a9313

Browse files
committed
cast before allclose
1 parent 95dafc6 commit 28a9313

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/test_modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ 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() # note: we grad original weights before quantization,
544+
w1, w2 = mlp.fc1.weight.clone().cuda(), mlp.fc2.weight.clone().cuda() # grab weights before quantization,
545545
mlp = mlp.cuda().half() # and this line triggers quantization
546546

547547
for i in range(100):
@@ -567,7 +567,7 @@ def test_linear8bitlt_no_fp16_weights(threshold, memory_efficient_backward):
567567

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

573573

0 commit comments

Comments
 (0)