mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 15:08:02 -05:00
improve conv testing
This commit is contained in:
@@ -66,20 +66,23 @@ class TestTinygrad(unittest.TestCase):
|
||||
|
||||
class TestOps(unittest.TestCase):
|
||||
def test_conv2d(self):
|
||||
x = torch.randn((5,2,10,7), requires_grad=True)
|
||||
w = torch.randn((4,2,3,2), requires_grad=True)
|
||||
xt = Tensor(x.detach().numpy())
|
||||
wt = Tensor(w.detach().numpy())
|
||||
for cin in [1,2,3]:
|
||||
for H in [2,3,5]:
|
||||
for W in [2,3,5]:
|
||||
x = torch.randn((5,cin,10,7), requires_grad=True)
|
||||
w = torch.randn((4,cin,H,W), requires_grad=True)
|
||||
xt = Tensor(x.detach().numpy())
|
||||
wt = Tensor(w.detach().numpy())
|
||||
|
||||
out = torch.nn.functional.conv2d(x,w)
|
||||
ret = Tensor.conv2d(xt, wt)
|
||||
np.testing.assert_allclose(ret.data, out.detach().numpy(), atol=1e-5)
|
||||
out = torch.nn.functional.conv2d(x,w)
|
||||
ret = Tensor.conv2d(xt, wt)
|
||||
np.testing.assert_allclose(ret.data, out.detach().numpy(), atol=1e-5)
|
||||
|
||||
out.mean().backward()
|
||||
ret.mean().backward()
|
||||
out.mean().backward()
|
||||
ret.mean().backward()
|
||||
|
||||
np.testing.assert_allclose(w.grad, wt.grad, atol=1e-7)
|
||||
np.testing.assert_allclose(x.grad, xt.grad, atol=1e-7)
|
||||
np.testing.assert_allclose(w.grad, wt.grad, atol=1e-7)
|
||||
np.testing.assert_allclose(x.grad, xt.grad, atol=1e-7)
|
||||
|
||||
def test_maxpool2x2(self):
|
||||
x = torch.randn((5,2,10,8), requires_grad=True)
|
||||
|
||||
Reference in New Issue
Block a user