Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I run python train.py and get error with File "../utils/alias_multinomial.py", line 57 #2

Open
thucnt opened this issue Nov 30, 2017 · 13 comments

Comments

@thucnt
Copy link

thucnt commented Nov 30, 2017

Traceback (most recent call last):
File "train.py", line 36, in
main()
File "train.py", line 32, in main
save_every=20, grad_clip=5.0
File "../utils/training.py", line 127, in train
neg_loss, dirichlet_loss = model(doc_indices, pivot_words, target_words)
File "/Users/macbook/anaconda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call
result = self.forward(input, **kwargs)
File "../utils/lda2vec_loss.py", line 72, in forward
neg_loss = self.neg(pivot_words, target_words, doc_vectors, w)
File "/Users/macbook/anaconda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in call
result = self.forward(input, **kwargs)
File "../utils/lda2vec_loss.py", line 142, in forward
noise = self.multinomial.draw(batch_size
window_size
self.num_sampled)
File "../utils/alias_multinomial.py", line 57, in draw
b = torch.bernoulli(q)
RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Volumes/OSX/Downloads/pytorch/aten/src/TH/THRandom.c:300

@TropComplique
Copy link
Owner

I just tested the code and didn't get any errors.
Have you changed any parameters in the code?
Do you have up-to-date pytorch installed?

@thucnt
Copy link
Author

thucnt commented Dec 1, 2017

Thanks for your response. But I have upgrade the latest pytorch using condo -c soumith pytorch and get a new error:

RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Users/soumith/miniconda2/conda-bld/pytorch_1503975723910/work/torch/lib/TH/THRandom.c:270

Because I run your code on my computer without GPU so I have to change your code by deleting anything relating to cuda(). Because I have just used pytorch, please tell me is it right?

@TropComplique
Copy link
Owner

Hi. Have you changed any parameters in the code?

@TropComplique
Copy link
Owner

Let's debug together.
Add to utils/alias_multinomial.py before
line 57 (line with b = torch.bernoulli(q))
the following print(q).

@thucnt
Copy link
Author

thucnt commented Dec 1, 2017

This is result before program raise error:
0.3298
0.5141
0.6557

0.3008
0.8198
0.8300
[torch.FloatTensor of size 1075200]
main()
File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/20newsgroups/train.py", line 32, in main
save_every=20, grad_clip=5.0
File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/training.py", line 127, in train
neg_loss, dirichlet_loss = model(doc_indices, pivot_words, target_words)
File "/Users/macbook/anaconda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(input, **kwargs)
File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/lda2vec_loss.py", line 72, in forward
neg_loss = self.neg(pivot_words, target_words, doc_vectors, w)
File "/Users/macbook/anaconda/envs/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py", line 224, in call
result = self.forward(input, **kwargs)
File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/lda2vec_loss.py", line 142, in forward
noise = self.multinomial.draw(batch_size
window_size
self.num_sampled)
File "/Volumes/OSX/Users/thucnt/git/lda2vec-pytorch/utils/alias_multinomial.py", line 58, in draw
b = torch.bernoulli(q)
RuntimeError: invalid argument 1: must be >= 0 and <= 1 at /Users/soumith/miniconda2/conda-bld/pytorch_1503975723910/work/torch/lib/TH/THRandom.c:270

@TropComplique
Copy link
Owner

Now try print(q.min(), q.max()).

@thucnt
Copy link
Author

thucnt commented Dec 1, 2017

number of documents: 12829
number of windows: 1023189
number of topics: 25
vocabulary size: 7460
word embedding dim: 50
number of batches: 143

epoch 1
0%| | 0/143 [00:00<?, ?it/s]Min and Max
0.20730416476726532 1.0001881122589111

@TropComplique
Copy link
Owner

Add q = q.clamp(0.0, 1.0) before b = torch.bernoulli(q).
It must solve the problem.

@thucnt
Copy link
Author

thucnt commented Dec 1, 2017

Wow. A great support!!!
Thank you very much. It runs now.

@Oliveche
Copy link

Oliveche commented Jan 8, 2018

Hello, thucnt
Would you like to send me a copy of your modified program on CPU, thank you.

@Oliveche
Copy link

Oliveche commented Jan 8, 2018

I want to know If I want to run on CPU, is it ok if I just delete the.Cuda () in the code?

@TropComplique
Copy link
Owner

@Oliveche I don't recommend to run this on CPU because it will be very slow.
But yeah, if you delete cuda in right places the code will run on CPU.

@Oliveche
Copy link

Thanks! I have deleted. But there is still the following problem,

number of documents: 12829
number of windows: 1023189
number of topics: 25
vocabulary size: 7460
word embedding dim: 50
number of batches: 143

epoch 1
0%| | 0/143 [00:00<?, ?it/s]

Please help me , thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants