add models and layers backward test

This commit is contained in:
cyberguli
2024-02-19 23:09:10 +01:00
committed by Nicola Demo
parent cbb43a5392
commit eb1af0b50e
10 changed files with 308 additions and 1 deletions

View File

@@ -106,6 +106,39 @@ def test_forward():
conv(x)
def test_backward():
model = MLP
x = torch.rand(dim_input)
x = make_grid(x)
x.requires_grad = True
# simple backward
conv = ContinuousConvBlock(channel_input,
channel_output,
dim,
stride,
model=model)
conv(x)
l=torch.mean(conv(x))
l.backward()
assert x._grad.shape == torch.Size([2, 2, 20, 3])
x = torch.rand(dim_input)
x = make_grid(x)
x.requires_grad = True
# simple backward with optimization
conv = ContinuousConvBlock(channel_input,
channel_output,
dim,
stride,
model=model,
optimize=True)
conv(x)
l=torch.mean(conv(x))
l.backward()
assert x._grad.shape == torch.Size([2, 2, 20, 3])
def test_transpose():
model = MLP