I copied your code and ran, it works fine. Could you show the version of your environment packages?
Here is a script you can use: https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py 3
Just run the code using python collect_env.py and paste output here.