mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
[Dynamo] Fix Tensor.T trace (#88642)
Summary: Tensor.T considered T as a GetAttr and didn't progate "example_value" Via https://pytorch.org/docs/stable/tensors.html#torch.Tensor.T > If n is the number of dimensions in x, x.T is equivalent to > x.permute(n-1, n-2, ..., 0). Fixes pytorch/torchdynamo#1476 Test Plan: pytest test/dynamo/test_functions.py::FunctionTests::test_T Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D41130306](https://our.internmc.facebook.com/intern/diff/D41130306) Pull Request resolved: https://github.com/pytorch/pytorch/pull/88642 Approved by: https://github.com/tugsbayasgalan, https://github.com/yanboliang, https://github.com/jansel
This commit is contained in:
parent
c7fc710459
commit
7006ac6ee5
|
|
@ -329,6 +329,10 @@ class FunctionTests(torch._dynamo.test_case.TestCase):
|
|||
if x.ndim == 2 and x.ndimension() == 2 and x.dim() == 2:
|
||||
return x + 1
|
||||
|
||||
@make_test
|
||||
def test_T(x):
|
||||
return torch.ones_like(x.T)
|
||||
|
||||
@make_test
|
||||
def test_is_sparse(x):
|
||||
if not x.is_sparse:
|
||||
|
|
|
|||
|
|
@ -438,6 +438,9 @@ class TensorVariable(VariableTracker):
|
|||
result = self.call_method(tx, "size", [], {})
|
||||
elif name == "ndim" and self.ndim is None:
|
||||
result = self.call_method(tx, "dim", [], {})
|
||||
elif name == "T":
|
||||
args = [variables.ConstantVariable(i) for i in range(self.ndim - 1, -1, -1)]
|
||||
result = self.call_method(tx, "permute", args, {})
|
||||
|
||||
if name == "__class__":
|
||||
return TorchVariable(self.python_type(), **options)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user