I tried to play around with your code to see, what might be wrong, but get an error running it:
RuntimeError: CUDA error: an illegal memory access was encountered

for PyTorch 1.0.0.dev20190207.
Is the code running fine on your machine?