It does not work in-place on tensors, so you have to reassign the result:
x = torch.randn(1, device='cpu')
print(x.device)
> cpu

x.to('cuda')
print(x.device)
> cpu

x = x.to('cuda')
print(x.device)
> cuda:0