I’m not sure how your model is implemented, but by iterating all modules and submodules, you will skip all functional API calls from the original forward method.
E.g. if a flatten operation was used via torch.flatten or out = out.view(out.size(0), -1), this operation won’t show up in the modules and you might end up with shape mismatch errors.
Could you check the forward implementation and search for these functional calls?