Fix a minor bug about method generation. (#99704)
Fixes #ISSUE_NUMBER
when create a torch.device obj, like `x=torch.device("foo")`, the device index is None.
So in this scenario, we need to get the current device index again.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99704
Approved by: https://github.com/albanD