theeluwin/pytorch-sgns

An error occurred when testing the repo

Closed this issue · 4 comments

Hi
Thank you for sharing the code. However, when I tried to test the repo with "python preprocess.py" and " python train.py --weights --cuda", the first one worked well and generated processed data, whereas the second reported the error as follows:

[Epoch 1]: 0%| | 0/1 [00:00<?, ?it/s]Traceback (most recent call last):
File "train.py", line 93, in train(parse_args())
File "train.py", line 81, in train loss = sgns(iword, owords)
File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call
result = self.forward(*input, **kwargs)
File "/home/weixin/Downloads/pytorch-sgns-master/model.py", line 70, in forward
ivectors = self.embedding.forward_i(iword).unsqueeze(2)
File "/home/weixin/Downloads/pytorch-sgns-master/model.py", line 42, in forward_i
return self.ivectors(v)
File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call
result = self.forward(*input, **kwargs)
File "/home/weixin/anaconda2/envs/p3/lib/python3.6/site-packages/torch/nn/modules/sparse.py", line 103, in forward
self.scale_grad_by_freq, self.sparse
RuntimeError: save_for_backward can only save input or output tensors, but argument 0 doesn't satisfy this condition

I am quite new to Pytorch so any idea what might go wrong?
Many thanks.

Can you offer your pytorch version? It seems that the error here looks similar to https://discuss.pytorch.org/t/why-i-cant-use-torch-index-select-in-forward-function/8010

Hi, thanks for the reply. The pytorch version is 0.3.0.post4.
The error does look similar to the post. Should I wrap the Tensors in the Variables?
Many thanks.

Yes, you should wrap tensors with Variable properly. I removed all Variable because it was removed in 0.4.0 (see https://pytorch.org/2018/04/22/0_4_0-migration-guide.html).

Many thanks for your feedback. I will try it later.