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

Name collision with .output in real world modules #330

Open
Skylion007 opened this issue Nov 10, 2024 · 1 comment
Open

Name collision with .output in real world modules #330

Skylion007 opened this issue Nov 10, 2024 · 1 comment

Comments

@Skylion007
Copy link

Skylion007 commented Nov 10, 2024

Currently, hooks store values in module.output this causes an issue when using any model that uses .output to store an nn.Module attribute. It's a very generic name that can collide with a variety of modules. As such, I cannot run backpack-for-pytorch on huggingface bert models. It would be better if the name was something more specific, even just backpack_for_pytorch_output or even backpack_output to prevent collisions with attributes of the module.

Creates an error similar:

/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py in __setattr__(self, name, value)
   1982             elif modules is not None and name in modules:
   1983                 if value is not None:
-> 1984                     raise TypeError(
   1985                         f"cannot assign '{torch.typename(value)}' as child module '{name}' "
   1986                         "(torch.nn.Module or None expected)"

TypeError: cannot assign 'torch.FloatTensor' as child module 'output' (torch.nn.Module or None expected)
@f-dangel
Copy link
Owner

Hi,

thanks for suggesting this. I think this would be a good improvement (I'd favour the shorter backpack_output option). Would you be interested in setting up a PR?

Best,
Felix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants