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

RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:193 #1

Closed
xiaolibird opened this issue May 30, 2019 · 4 comments

Comments

@xiaolibird
Copy link

When I feed my own data embedded by LINE
it happens:

And the problem arises at GrpahSGAN.py line 32
self.embedding_layer = nn.Embedding(dataset.n, dataset.d)

After searching, I found that the first parameter is actually related to vocabulary size, which I have no idea and could not find in LINE codes.

@Sleepychord
Copy link
Collaborator

I cannot not fully understand your problem. The first parameter is ``the number of nodes'' in the graph. You should build the dataset following the description in README.

@xiaolibird
Copy link
Author

Sorry for my poor expression.
But I am building the dataset according to the description in README
dataset.n == dataset.embeddings.shape[0] == #nodes in graph
And there is something wrong with nn.Embedding(num_embeddings, embedding_dim) when processing inappropriate num_embeddings

And here is the traceback
Traceback (most recent call last):
File "GraphSGAN.py", line 224, in
gan.train()
File "GraphSGAN.py", line 109, in train
ll, lu, acc = self.trainD((id0, xf), y, idf_unlabel1)
File "GraphSGAN.py", line 48, in trainD
x_label, x_unlabel, y = self.make_input(*idf_label), self.make_input(*idf_unlabel), Variable(y, requires_grad = False)
File "GraphSGAN.py", line 91, in make_input
embedding = self.embedding_layer(Variable(ids, volatile = volatile)).detach() # detach temporarily
File "/path/to/python/site-packages/torch/nn/modules/module.py", line 493, in call
result = self.forward(*input, **kwargs)
File "/path/to/python/site-packages/torch/nn/modules/sparse.py", line 117, in forward
self.norm_type, self.scale_grad_by_freq, self.sparse)
File "/path/to/python/site-packages/torch/nn/functional.py", line 1506, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: index out of range at /pytorch/aten/src/TH/generic/THTensorEvenMoreMath.cpp:193

===
It seems that this issue arises at many embedding tasks, and some say it involves the vocabulary size of your embedding and it confuses me since I was using LINE for embedding and I am not doing a word embedding task.

chenxijun1029/DeepFM_with_PyTorch#1
https://stackoverflow.com/questions/51456059/pytorch-nn-embedding-error

@Sleepychord
Copy link
Collaborator

this error just means that you are asking for an embedding of a node whose Id is larger than vocabulary size...
you'd better double check all the parameters relevant to the number of nodes. I think this is not a big problem.

来自GitHub小程序客户端:

image

@xiaolibird
Copy link
Author

Found it
Seems it load pretrianed network as default
Thanks a lot for your patience!

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

2 participants