Skip to content

bizarre behavior with torch module's Attribute Error Junie #4

@AlexanderPrendota

Description

@AlexanderPrendota

🐛 Describe the bug

🐛 Describe the bug
when executing the following code:

import torch

class A(torch.nn.Module):
def init(self):
super().init()

@property
def foo(self):
    return self.bar # attr error

a = A()
print(a.foo)
I obtain

Traceback (most recent call last):
File "test.py", line 12, in
print(a.foo)
File "xxx/python3.8/site-packages/torch/nn/modules/module.py", line 1729, in getattr
raise AttributeError(f"'{type(self).name}' object has no attribute '{name}'")
AttributeError: 'A' object has no attribute 'foo'
but the expected behavior would be AttributeError: 'A' object has no attribute 'bar'.

Versions

Versions
versions is seemingly irrelevant. Anyhow i use
[conda] torch 2.4.0+cu118 pypi_0 pypi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions