[dynamo][easy] forbid_in_graph check to use getattr_static (#124445)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/124445
Approved by: https://github.com/yanboliang, https://github.com/jansel
This commit is contained in:
Animesh Jain 2024-04-19 08:55:53 -07:00 committed by PyTorch MergeBot
parent 97ccfad915
commit febc4d8759
22 changed files with 5 additions and 2 deletions

View File

@ -3064,7 +3064,7 @@ def is_callable_disallowed(obj) -> bool:
def is_forbidden(obj) -> bool:
_maybe_init_lazy_module(obj)
return getattr(obj, "_dynamo_forbidden", False)
return inspect.getattr_static(obj, "_dynamo_forbidden", False)
def is_builtin_callable(obj) -> bool:

View File

@ -791,7 +791,10 @@ class UnspecializedNNModuleVariable(UserDefinedObjectVariable):
kwargs,
)
if id(method.__code__) in self._nn_module_method_ids():
if (
hasattr(method, "__code__")
and id(method.__code__) in self._nn_module_method_ids()
):
unimplemented(f"UnspecializedNNModuleVariable missing {name}")
# "_parameters" in self.value.__dict__ checks that module is initialized