What’s the best way to accomplish this when iterating over modules?
for module in model.modules():
    classname = module.__class__.__name__
    if 'Linear' in classname:
        module = nn.Sequential(...) # replacing Linear with multiple layers defined in Sequential

Is this the correct approach to modify model on-the-fly?
Edit: Assigning to module as shown didn’t work, probably it creates a copy to iterate over?