While implementing an Improved Wasserstein GAN architecture, we ran into a problem when consecutively adding 2 Conv2d layers before the final classification layer, which results in the following Error:
/home/hartmank/anaconda2/lib/python2.7/site-packages/torch/autograd/variable.pyc in backward(self, gradient, retain_graph, create_graph, retain_variables)
150                 Defaults to False, unless ``gradient`` is a volatile Variable.
151         """
--> 152         torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
153 
154     def register_hook(self, hook):

/home/hartmank/anaconda2/lib/python2.7/site-packages/torch/autograd/__init__.pyc in backward(variables, grad_variables, retain_graph, create_graph, retain_variables)
 96 
 97     Variable._execution_engine.run_backward(
---> 98         variables, grad_variables, retain_graph)
 99 
100 

RuntimeError: ConvNdBackward: expected Variable at argument 0 (got None)

The error vanished when the final classification output is transformed by 1/x.
We tested the following architectures:
Conv2d - LeakyReLU - Linear -> No Error
Conv2d - Conv2d - LeakyReLU - Linear -> Error
Conv2d - Conv2d - LeakyReLU - Conv2d - LeakyReLU - Linear -> No Error
Conv2d - Conv2d - LeakyReLU - Conv2d - Conv2d - LeakyReLU - Linear -> Error
Conv2d - Conv2d - LeakyReLU - Conv2d - Conv2d - LeakyReLU - Linear - 1/x -> No Error
Notebook with Code: https://gist.github.com/kahartma/ccf7279fb20a216905079f6b10b31b78 10
Does anybody have any idea what’s going on or what we do wrong?
Cheers
Kay