Skip to content

[jit] @staticmethods retrieved from self don't work on normal class #39308

@chenbohua3

Description

@chenbohua3

#37702 has fix @staticmethod for nn.Module, but this bugs still exist on normal class:

@torch.jit.script
class MyCell(object):
    @staticmethod
    def do_it(x, h):
        new_h = torch.tanh(x + h)
        return new_h, new_h

we get:

RuntimeError: 
Tried to access nonexistent attribute or method '__add__' of type '__torch__.MyCell'. Did you forget to initialize an attribute in __init__()?:
  File "test.py", line 8
    @staticmethod
    def do_it(x, h):
        new_h = torch.tanh(x + h)
                           ~~~~~ <--- HERE
        return new_h, new_h

PyTorch version: master on commit 8556664

cc @suo

Metadata

Metadata

Assignees

Labels

oncall: jitAdd this issue/PR to JIT oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions