Rate this Page

torch.jit.unused#

torch.jit.unused(fn)[source]#

This decorator indicates to the compiler that a function or method shouldbe ignored and replaced with the raising of an exception. This allows youto leave code in your model that is not yet TorchScript compatible and stillexport your model.

Example (using@torch.jit.unused on a method):

importtorchimporttorch.nnasnnclassMyModule(nn.Module):def__init__(self,use_memory_efficient):super().__init__()self.use_memory_efficient=use_memory_efficient@torch.jit.unuseddefmemory_efficient(self,x):importpdbpdb.set_trace()returnx+10defforward(self,x):# Use not-yet-scriptable memory efficient modeifself.use_memory_efficient:returnself.memory_efficient(x)else:returnx+10m=torch.jit.script(MyModule(use_memory_efficient=False))m.save("m.pt")m=torch.jit.script(MyModule(use_memory_efficient=True))# exception raisedm(torch.rand(100))
Return type

Callable[[~_P],_R]