Your code is a bit long to debug it completely.
However it looks like you are trying to define the residual connection in an __init__ method:
residual = residual + nxt

which won’t work.
Instead create the residual connection in the forward method on the module as use in the resnet implementation 3.