-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Closed
Labels
oncall: jitAdd this issue/PR to JIT oncall triage queueAdd this issue/PR to JIT oncall triage queue
Description
Constant values are inlined in the graph without names, so they can't be accessed after compilation. This is a problem since a lot of nn.Module
s are scripted using constants instead of attributes, so users have no way of accessing these values once they have scripted a module.
class M(nn.Module):
__constants__ = ['my_const']
def __init__(self):
super().__init__()
self.my_const = 2
def forward(self, x):
return x + self.my_const
sm = torch.jit.script(M())
# AttributeError: 'RecursiveScriptModule' object has no attribute 'my_const'
print(sm.my_const)
An easy fix would be to delete all the __constants__
arrays in torch/nn
so everything would be made into an attribute.
cc @suo
Metadata
Metadata
Assignees
Labels
oncall: jitAdd this issue/PR to JIT oncall triage queueAdd this issue/PR to JIT oncall triage queue