How to ignore specific method in TorchScript?


Let I have the Model and some method check_input_shape. I always want to use this method in pytorch but I want to ignore it in TorchScript. So, is there anything (maybe some decorator) to do it? I found torch.jit.unused but this decorator raise exception when trying to call decorated function :frowning:

@jit.ignore `````````````

Nope, it doesnโ€™t work. If you use the torch.jit.ignore and try to run TorchScript model you either use python interpreter (when pass argument drop=False) or raise exception (when pass argument drop=True).

sorry, I assumed you wanted to ignore compilation.

you can use something like

if not jit.is_scripting(): check_input_shape(x)

to skip execution.