Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jit] Bad error when calling ScriptModules with attributes/parameters #19504

Open
driazati opened this issue Apr 19, 2019 · 1 comment
Open
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@driazati
Copy link
Contributor

driazati commented Apr 19, 2019

class Vocab(torch.jit.ScriptModule):
    def __init__(self):
        self.i = torch.jit.Attribute(2, int)

    @torch.jit.script_method
    def forward(self, x):
        return x + self.i

v = Vocab()

@torch.jit.script
def lookup(y):
    return v(y)

results in

for operator forward(Tensor x, int slot0) -> Tensor:
argument slot0 not provided.
@torch.jit.script
def lookup(y):
    return v(y)
           ~ <--- HERE
:
@torch.jit.script
def lookup(y):
    return v(y)

Script functions cannot call stateful modules, so this should produce an error but it should say something to that effect instead of a schema-mismatch.

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 19, 2019
@driazati
Copy link
Contributor Author

driazati commented Apr 22, 2019

Semi-related errors:

  1. Explicitly calling the forward method
class Vocab(torch.jit.ScriptModule):
    def __init__(self):
        self.i = torch.jit.Attribute(2, int)

    @torch.jit.script_method
    def forward(self, x):
        return x + self.i

v = Vocab()

@torch.jit.script
def lookup(y):
    return v.forward(y)
RuntimeError: 
attribute lookup is not defined on method:
@torch.jit.script
def lookup(y):
    return v.forward(y)
           ~~~~~~~~~ <--- HERE
  1. Calling a non-forward method
class Vocab(torch.jit.ScriptModule):
    def __init__(self):
        self.i = torch.jit.Attribute(2, int)

    @torch.jit.script_method
    def my_method(self, x):
        return x + self.i

v = Vocab()

def lookup(y):
    return v.my_method(y)
RuntimeError: 
 expected this module to have a forward function..

@ailzhang ailzhang added high priority triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Apr 28, 2019
@driazati driazati changed the title [jit] Cannot call ScriptModules with attributes/parameters [jit] Bad error when calling ScriptModules with attributes/parameters May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oncall: jit Add this issue/PR to JIT oncall triage queue triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

No branches or pull requests

3 participants