[14/N][Dynamo] Make trace_rules.lookup only handle function + callable type (#118366)

Step by step changes to unblock #118264

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118366
Approved by: https://github.com/angelayi
This commit is contained in:
Yanbo Liang
2024-01-27 23:02:44 +00:00
committed by PyTorch MergeBot
parent 62c1e4a578
commit ca1d70632d
6 changed files with 41 additions and 40 deletions

View File

@ -518,8 +518,16 @@ def is_numpy_float_type(value):
)
def is_function_or_wrapper(value):
return (
is_function(value)
or isinstance(value, functools._lru_cache_wrapper)
and is_function(inspect.getattr_static(value, "__wrapped__"))
)
def is_function(value):
return istype(
return isinstance(
value,
(
types.FunctionType,
@ -530,6 +538,12 @@ def is_function(value):
)
def unwrap_if_wrapper(value):
if isinstance(value, functools._lru_cache_wrapper):
value = inspect.getattr_static(value, "__wrapped__")
return value
def is_numpy_ndarray(value):
if not np:
return False