[Dynamo] Support optimizing over any Tensor with requires_grad = True (#87141)
Fixes https://github.com/pytorch/torchdynamo/issues/1604
Re-submit for https://github.com/pytorch/torchdynamo/pull/1646
Pull Request resolved: https://github.com/pytorch/pytorch/pull/87141
Approved by: https://github.com/jansel