I see, i think the input tensor shape is the problem.
i tried to run your code:
This works fine
rand_tensor= torch.rand(8,1, 256, 256) 
 

output= model(rand_tensor)

gives same error as yours
rand_tensor= torch.rand(8,1, 255, 256) 
 

output= model(rand_tensor)

so try adjusting the input shape to an even number or power of 2.
PS: Your code has memory leaks, it wont train for very long.