I want to subclass
Sequential to create a Residual sequential class in a few lines.
class Residual(nn.Sequential): def forward(self, x): return x + super().__call__(x)
However, this crashes with:
RecursionError: maximum recursion depth exceeded while calling a Python object
If I understand well, the
super().__call__ actually calls
nn.Module.__call__ which then calls the
self … which is the one I overrode, that calls the
__call__ again …
forward solves the problem :
class Residual(nn.Sequential): def forward(self, x): return x + super().forward(x)
But I will lose the hooks then, is that right ?
Is my global understanding correct ?
Could it poses any problem to modules such as
DataParallel that the
Sequential is callled directly ?
Thank you much in advance !