Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend assert statement to include ListVariable #100841

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/dynamo/test_repros.py
Original file line number Diff line number Diff line change
Expand Up @@ -3168,6 +3168,29 @@ def check_type(obj, types_or_checks):
res = opt_check_type(torch.randn(4), [torch.Tensor])
self.assertEqual(ref, res)

def test_kwargs_out_list_variable(self):
class Repro(torch.nn.Module):
def __init__(self):
super().__init__()

def forward(self, param):
z = torch.frexp(**param)
return z

model = Repro()
params = {"input": torch.tensor([[0.0, 1, 2, 4]])}
params["out"] = [
torch.empty(0, dtype=torch.float32), # mantissa
torch.empty(0, dtype=torch.int32), # exponent
]

model = torch.compile(model, backend="eager")
mantissa, exponent = model(params)
ref_mantissa = torch.tensor([[0.0000, 0.5000, 0.5000, 0.5000]])
ref_exponent = torch.tensor([[0, 1, 2, 3]], dtype=torch.int32)
self.assertEqual(ref_mantissa, mantissa)
self.assertEqual(ref_exponent, exponent)


if __name__ == "__main__":
from torch._dynamo.test_case import run_tests
Expand Down
2 changes: 1 addition & 1 deletion torch/_dynamo/variables/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def check_any_unspec(x):
# torch.sigmoid mutate the tensors in the out field. Track such
# tensors and rewrite the symbolic locals.
if isinstance(tensor_variable, TupleVariable):
assert isinstance(kwargs["out"], TupleVariable)
assert isinstance(kwargs["out"], (TupleVariable, ListVariable))
output_tensor_names = [
tx.find_symbolic_locals_name(x) for x in kwargs["out"].items
]
Expand Down