The code raises an error on the CPU as well as the GPU using the latest stable version (1.7.0).
Note that assert statements in CUDA code were mostly disabled in 1.5.0 due to a bug, so that your code doesn’t raise the proper error if you are using the GPU.
The reason for the error is that your weight lookup table in the embedding layer contains feature vectors for 51 indices, so your inputs are limited to [0, 50], while you are passing positions with values in the range [1, 200].
Also, note that torch.FloatTensor(torch.Size([51, 512])) will create a tensor in the specified shape with uninitialized values, which might contain invalid values such as NaNs and Infs, so you should properly initialize sinusoid_table or use a tensor factory method to create it such as torch.randn.
Yes, device assert statements were unfortunately disabled by accident (this should be fixed in 1.5.1 and all newer versions).
I would strongly recommend to update PyTorch and to make sure your code is running properly.
Your current code might run into an illegal memory access without reporting it and might thus create major issues.