Skip to content

Commit cdae8b9

Browse files
suofacebook-github-bot
authored andcommitted
improve recursive scripting error message (#21841)
Summary: Pull Request resolved: #21841 ghimport-source-id: fbca813 Test Plan: Imported from OSS Reviewed By: zdevito Differential Revision: D15857569 Pulled By: suo fbshipit-source-id: 152eba10565cf7119508079e98512f116eb3a5a8
1 parent c0420d9 commit cdae8b9

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

torch/jit/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,11 @@ def _try_compile_fn(fn):
995995
# Don't do anything for @ignore'd functions
996996
return None
997997

998+
if not inspect.isfunction(fn) and not inspect.ismethod(fn):
999+
raise RuntimeError("`{}` is not a function. Recursive scripting only supports "
1000+
"Python functions or methods currently.\n"
1001+
"Consider manually annotating `{}` with @torch.jit.script.".format(fn))
1002+
9981003
if isinstance(fn, torch.nn.Module):
9991004
# Since modules are callable pybind recognizes them as functions, but
10001005
# don't do anything for them

0 commit comments

Comments
 (0)