This snippet demonstrates the problem:
test = torch.zeros((10,10)).requires_grad_(True)
print(test.is_leaf) # True
test = test.to(data.device)
print(test.is_leaf) # False

When optimizing test using Adam later in my code, I get

ValueError: can’t optimize a non-leaf Tensor

Why is this the case? Is this a bug or intended?