Detecting a torch.jit.script function

Is there any easy way to reliably detect if a function is a JIT ScriptFunction?
For example:

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.

Is isinstance(func1, torch.jit.ScriptFunction) working for you?

Best regards


Ah, yes, it actually works!
I tried it before and it returns False, I didn’t realize my code put func.__call__ into my function that’s why it fails.