pytorch
58acab46 - [dynamo] support [tensor].type(torch.FloatTensor) (#93043)

Commit
1 year ago
[dynamo] support [tensor].type(torch.FloatTensor) (#93043) for some tensor x, x.type(torch.FloatTensor) will essentially do the same thing as x.to(torch.float). x.type can be called with at least 3 types of inputs: * a string "torch.FloatTensor" * a dtype torch.float * a tensor type torch.FloatTensor the third option (torch.FloatTensor) fails in fx, because fx cannot trace torch.FloatTensor objects. So this PR will replace the torch.FloatTensor type with a string "torch.FloatTensor" Why not fix this in fx? Well, it's possible, but I'm not sure a nice way to do it. We would want to update [torch.fx.node.BaseArgumentTypes](https://github.com/pytorch/pytorch/blob/d88bc38b0c4774a0c9b576944ed5c4401b825b47/torch/fx/node.py#L17) to contain torch.FloatTensor etc. We could hard-code a list of tensor types there (the types vary depending on build type, e.g. whether or not cuda tensors are available), but that's not great in case our hardcoded list differs from the actual list registered by python_tensor.cpp. Another option is to dynamically populate the list of types with `Union[tuple(...)])`, and fill the tuple with `torch._tensor_classes` (which is directly populated by python_tensor.cpp), but apparently this breaks most typecheckers. Pull Request resolved: https://github.com/pytorch/pytorch/pull/93043 Approved by: https://github.com/jansel
Author
Committer
Parents
Loading