PyTorch 0.2 is really old by now and the .to() operation was introduced in newer version. I would recommend to update to the latest version. You’ll find the install instructions here.
If that’s not possible for whatever reason, you could use .cuda() and .cpu() instead.