Skip to content

Commit

Permalink
Raise TypeError for calling moduletype in dynamo (pytorch#107393)
Browse files Browse the repository at this point in the history
Fixes pytorch#107314

Pull Request resolved: pytorch#107393
Approved by: https://github.com/williamwen42
  • Loading branch information
wconstab authored and pytorchmergebot committed Aug 19, 2023
1 parent 3349725 commit eee2f57
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/dynamo/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ def fn(a, b, c, cls):
self.assertEqual(counter.frame_count, 1)
self.assertEqual(counter.op_count, 3)

def test_module_not_callable(self):
def fn(x):
return torch.fft(x)

counter = CompileCounter()
a = torch.randn(10, 10)
opt_fn = torch._dynamo.optimize(counter)(fn)
self.assertRaisesRegex(
TypeError, "'module' object is not callable", lambda: opt_fn(a)
)

def test_inplace(self):
def inplace1(a, b):
o = torch.empty((10, 10))
Expand Down
2 changes: 2 additions & 0 deletions torch/_dynamo/variables/torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,8 @@ def map_fn(v):
return v

return torch.utils._pytree.tree_map(map_fn, tree)
elif isinstance(self.value, types.ModuleType):
unimplemented("TypeError(\"'module' object is not callable\")")
else:
any_symints_or_symfloats = any(isinstance(x, SymNodeVariable) for x in args)
all_ints_or_floats = all(
Expand Down

0 comments on commit eee2f57

Please sign in to comment.