The identity variable in line 55 is mutable
def forward(self, x):
identity = x
It must be immutable as follows:
def forward(self, x):
identity = 1*x
Why do you think so? If I'm not mistaken no inplace operation is performed on identity and thus x is never changed inplace:
Additionally, if we go through with your proposal, it would be clearer to do
identity = x.clone()
than a multiplication by one.
Oh, my mistake, you are right. x is never changed. it was another implementation, with similar residual conenction that x was getting changed hence identitiy.
Thanks for helping out @pmeier !