Size is not implemented for type Undefined in backward method


In the backward method, I am getting an error like this,:
Traceback (most recent call last):
File “./”, line 153, in
File “./”, line 93, in train
loss.backward() # backprop
File “/usr/local/lib/python2.7/dist-packages/torch/autograd/”, line 167, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
File “/usr/local/lib/python2.7/dist-packages/torch/autograd/”, line 99, in backward
variables, grad_variables, retain_graph)
RuntimeError: size is not implemented for type UndefinedType

But, the loss is a Tensor of type torch.FloatTensor.

Any hints on where the issue could be?

Thanks in advance,

Is your loss a scalar value or a multidimensional value (for example in vision: one value per pixel)?

No, it is a FloatTensor of dimension 1, not a scalar

Could you show us your training/gradient update code?


The code was registering the parameters which gave the error, it works fine now. Thanks for your help.

Would you mind sharing your code even if you fixed it? It may help others which got the same error

I was trying to implement this

The error was while registering the parameters like this
self.logvar_bn .register_parameter(‘weight’, None)
self.mean_bn .register_parameter(‘weight’, None)
self.decoder_bn.register_parameter(‘weight’, None)
self.decoder_bn.register_parameter(‘weight’, None)
in which was giving the errors.

1 Like