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.