Wrapping the submodules in nn.Sequential blocks can easily fail, if functional calls are used in the original forward method.
In particular, this torch.flatten() operation 3 will be missing in your code and might cause the shape mismatch.