pytorch-avitm icon indicating copy to clipboard operation
pytorch-avitm copied to clipboard

RuntimeError: undefined Tensor

Open mfaisal opened this issue 5 years ago • 2 comments

I am getting following error with pytorch 1.2.0 in python 3.7. Any help will be appreciated:

/workspace/topic-modeling-/pytorch_model.py:60: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. p = F.softmax(z) # mixture probability /workspace/topic-modeling-/pytorch_model.py:65: UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument. recon = F.softmax(self.decoder_bn(self.decoder(p))) # reconstructed distribution over vocabulary

RuntimeError Traceback (most recent call last) in ----> 1 train(tensor_tr) 2 emb = model.decoder.weight.data.cpu().numpy().T

in train(dataset_tensor) 30 # optimize 31 optimizer.zero_grad() # clear previous gradients ---> 32 loss.backward() # backprop 33 optimizer.step() # update parameters 34 # report

~/anaconda3/lib/python3.7/site-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph) 116 products. Defaults to False. 117 """ --> 118 torch.autograd.backward(self, gradient, retain_graph, create_graph) 119 120 def register_hook(self, hook):

~/anaconda3/lib/python3.7/site-packages/torch/autograd/init.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables) 91 Variable._execution_engine.run_backward( 92 tensors, grad_tensors, retain_graph, create_graph, ---> 93 allow_unreachable=True) # allow_unreachable flag 94 95

RuntimeError: undefined Tensor

mfaisal avatar Nov 26 '19 20:11 mfaisal

I had the same problem.

460176980 avatar Sep 08 '20 06:09 460176980

You can comment out the below lines, and remove these variables from forward function. It works for me.

remove BN's scale parameters

    # 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)

jackyuanjie1990 avatar Feb 24 '21 06:02 jackyuanjie1990