I find a mistake about tensors on GPU.

import torch
device = torch.device(“cuda”)
x = torch.rand(3, requires_grad=True)
x = x.to(device)
m = x.mean()
m.backward()
print(x)
print(m)
print(x.grad)

These codes output

tensor([0.6155, 0.2922, 0.6875], device=‘cuda:0’, grad_fn=<CopyBackwards>)
tensor(0.5317, device=‘cuda:0’, grad_fn=<MeanBackward1>)
None

x.grad=None, I wonder why?