You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The c30e3cc commit breaks saliency map generation. The behavior of object.__setattr__ for setting the bias parameter in canonizers.MergeBatchNorm differs from using direct assignment or setattr() (object.__setattr__ bypasses custom nn.Module.__setattr__). Since the bias is None, this will lead to inconsistencies in parameter registration.
Input
Result
Expected result
Reproducible Example
importtorchimporttorch.nnasnnclassCustomModule(nn.Module):
def__init__(self):
super().__init__()
self.weight=nn.Parameter(torch.randn(1))
def__setattr__(self, name, value):
super().__setattr__(name, value)
module=CustomModule()
# Method 1: Direct assignmentmodule.bias1=nn.Parameter(torch.zeros(1))
# Method 2: Using setattrsetattr(module, 'bias2', nn.Parameter(torch.zeros(1)))
# Method 3: Using object.__setattr__ bias3 won't be registered as a parameterobject.__setattr__(module, 'bias3', nn.Parameter(torch.zeros(1)))
print("Registered parameters:", module._parameters.keys()) # => ['weight', 'bias1', 'bias2']
The text was updated successfully, but these errors were encountered:
karray
pushed a commit
to karray/zennit
that referenced
this issue
Jul 19, 2024
thanks a lot for spotting this, and for the PR. I guess the issue is that we modify the bias, but it remains unused by the module unless it is explicitly registered as a Parameter. As we are using a Canonizer, I think just adding the Parameter is the right call. I will leave you a small comment on the PR.
Description
The c30e3cc commit breaks saliency map generation. The behavior of
object.__setattr__
for setting thebias
parameter in canonizers.MergeBatchNorm differs from using direct assignment orsetattr()
(object.__setattr__
bypasses customnn.Module.__setattr__
). Since thebias
isNone
, this will lead to inconsistencies in parameter registration.Reproducible Example
The text was updated successfully, but these errors were encountered: