Is there any easy way to reliably detect if a function is a JIT ScriptFunction?
For example:
@torch.jit.script
def func1(x):
return x.sum()
def func2(x):
return x.sum()
def detect_jit_script(func):
pass # should return True for func1 and False for func2
I realize that func1
is compiled to a method (so it’s no longer a function).
However, using inspect.ismethod
doesn’t work because the input func
can be a method of a class.
And apparently the compiled func1
does not have any attributes other than __call__
which makes it harder to get and check the object.