Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
This repository was archived by the owner on Aug 1, 2025. It is now read-only.

[Bug]: torchdynamo.export doesn't work with model attribute initialized outside of constructor #1740

@tugsbayasgalan

Description

@tugsbayasgalan

🐛 Describe the bug

class Foo(torch.nn.Module):
    a = 4

    def __init__(self):
        super().__init__()

    def forward(self, x):
        return x.cos() + self.a 

torchdynamo.config.dynamic_shapes = True
torchdynamo.export(Foo(), torch.randn(3, 4), aten_graph=True)

Error logs

  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/symbolic_convert.py", line 308, in step
    getattr(self, inst.opname)(inst)
  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/symbolic_convert.py", line 805, in LOAD_ATTR
    result = BuiltinVariable(getattr).call_function(
  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/variables/builtin.py", line 337, in call_function
    result = handler(tx, *args, **kwargs)
  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/variables/builtin.py", line 661, in call_getattr
    return obj.var_getattr(tx, name).add_options(options)
  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/variables/nn_module.py", line 153, in var_getattr
    unimplemented(f"class property {typestr(base)} {typestr(subobj)}")
  File "/mnt/xarfuse/uid-23137/7756fc57-seed-nspid4026533012_cgpid17879168-ns-4026533009/torchdynamo/exc.py", line 71, in unimplemented
    raise Unsupported(msg)
torchdynamo.exc.Unsupported: class property Foo int

Did Dynamo succeed?

  • Does dynamo.optimize("eager") succeed?

Did AOT succeed?

  • Did dynamo.optimize("aot_eager") succeed?

Did Inductor succeed?

  • Does dynamo.optimize("inductor") succeed?

Minified repro

Repro above

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions