I’m not sure I understand the error description properly, but nn.Embedding modules expect an input tensor containing indices in the range [0, num_embeddings-1].
If you are using an older PyTorch version, please update to the latest stable release, and rerun the code.
In the 1.5.0 release some CUDA assert statements were disabled accidentally (fixed in later versions), so you might be hitting a sticky error in your code snippet.