Will torch.jit.unused support normal object class?

It seems that torch.jit.unused does not support normal object class. Is there any plans to support it? For now, the following codes will cause an error: 'torch.jit.frontend.UnsupportedNodeError: with statements aren’t supported:'

@torch.jit.script
class MyObject(object):
    def __init__(self):
        super().__init__()

    @torch.jit.unused
    def unsupported(self):
        with torch.no_grad():
            print('This is not supported by jit.')

    def supported(self, x):
        print('This is supported by jit.')

By the way, could anyone give some advices to handle this situation where classes with torchscript-unsupported attributes are used during torchscript inference process.

Right now everything that is in a @torch.jit.scripted class has to be TorchScript compatible, but we’re working on fixing it so @ignore and @unused work as they should. The best way around it for now is probably to use free-standing functions (which you can @ignore) that take the object as the first argument

Got it, thank you very much:)

@driazati Thanks for the answer. Is there an issue where we can track the progress of the Python Object class @ignore and @unused support?

This feature will be released in TensorFlow 1.7. The pull request can be found here.

I thought TF1.7 was already released in 2018 :wink:

1 Like

@ptrblck Haha :rofl:, typo, pytorch 1.7 ofcourse :grin:.

2 Likes