mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-04-29 03:00:14 -04:00
fix test_schedule conv2d bug (#7549)
* tests tests tests * slap a resolve on it * fix comment
This commit is contained in:
@@ -1629,6 +1629,15 @@ class TestOps(unittest.TestCase):
|
||||
def test_conv2d_bs_1_cin_1(self): self._test_conv2d(bs=1, cin=1)
|
||||
def test_conv2d_bs_4_cin_1(self): self._test_conv2d(bs=4, cin=1)
|
||||
|
||||
def test_conv2d_errors(self):
|
||||
# kernel size cannot be larger than input size
|
||||
self.helper_test_exception([(1,1,6,7), (6,1,3,3)],
|
||||
lambda x,w:torch.nn.functional.conv2d(x,w,dilation=3),
|
||||
lambda x,w: Tensor.conv2d(x,w,dilation=3), expected=(RuntimeError, AssertionError))
|
||||
# regression test for https://github.com/tinygrad/tinygrad/pull/7549/
|
||||
self.helper_test_exception([(2,16,2,2), (32,16,3,3)], lambda x,w:torch.nn.functional.conv2d(x,w), lambda x,w: Tensor.conv2d(x,w),
|
||||
expected=(RuntimeError, AssertionError))
|
||||
|
||||
def test_large_input_conv2d(self):
|
||||
bs = 4
|
||||
cin = 16
|
||||
|
||||
@@ -932,7 +932,7 @@ class TestSchedule(unittest.TestCase):
|
||||
with Tensor.train():
|
||||
img = Tensor.empty(2,3,4,4)
|
||||
c1 = nn.Conv2d(3,16,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,2,bias=False)
|
||||
_realize_weights([c1, c2])
|
||||
opt = nn.optim.Adam(nn.state.get_parameters([c1, c2]), lr=1e-4)
|
||||
opt.zero_grad()
|
||||
@@ -953,23 +953,23 @@ class TestSchedule(unittest.TestCase):
|
||||
with Tensor.train():
|
||||
img = Tensor.empty(2,3,4,4)
|
||||
c1 = nn.Conv2d(3,16,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,2,bias=False)
|
||||
_realize_weights([c1, c2])
|
||||
opt = nn.optim.SGD(nn.state.get_parameters([c1, c2]))
|
||||
opt.zero_grad()
|
||||
c2(c1(img).relu()).relu().sum().backward()
|
||||
check_schedule(opt.schedule_step(), 6)
|
||||
check_schedule(opt.schedule_step(), 8)
|
||||
|
||||
def test_fold_2convs_sgd_nesterov_momentum_wd(self):
|
||||
with Tensor.train():
|
||||
img = Tensor.empty(2,3,4,4)
|
||||
c1 = nn.Conv2d(3,16,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,3,bias=False)
|
||||
c2 = nn.Conv2d(16,32,2,bias=False)
|
||||
_realize_weights([c1, c2])
|
||||
opt = nn.optim.SGD(nn.state.get_parameters([c1, c2]), nesterov=True, momentum=0.9, weight_decay=0.1)
|
||||
opt.zero_grad()
|
||||
c2(c1(img).relu()).relu().sum().backward()
|
||||
check_schedule(opt.schedule_step(), 8)
|
||||
check_schedule(opt.schedule_step(), 10)
|
||||
|
||||
def test_sgd_4convs_fuse(self):
|
||||
with Tensor.train():
|
||||
|
||||
Reference in New Issue
Block a user