Skip to content

Commit d9b8789

Browse files
committed
debug
1 parent 5d65817 commit d9b8789

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/test_modules.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def test_linear8bitlt_no_fp16_weights(threshold, memory_efficient_backward):
545545
.to(torch.float16)
546546
.to("cuda")
547547
)
548+
w1, w2 = mlp.fc1.weight.clone(), mlp.fc2.weight.clone()
548549

549550
for i in range(100):
550551
b1 = torch.randn(16, 8, 32, device="cuda").half()
@@ -567,8 +568,15 @@ def test_linear8bitlt_no_fp16_weights(threshold, memory_efficient_backward):
567568
assert o1.requires_grad
568569
grad_proj = torch.randn_like(o1)
569570

571+
mlp.zero_grad()
570572
(o1 * grad_proj).sum().backward()
571573

574+
grad_ref = grad_proj.flatten(2) @ w2 @ w1
575+
assert torch.allclose(b1.grad, grad_ref)
576+
577+
578+
579+
572580

573581

574582

0 commit comments

Comments
 (0)