Solved by ptrblck in post #2 
              
              
                torch.jit.is_scripting() can be used as a guard for Python-only methods, which are not exportable. 
Since the JIT cannot export all arbitrary Python objects, you could thus use different “paths” in your code for the Python execution and the scripting of the mdoel. 
handle_torch_function sounds like …