You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During finetuning with complex models, a call to BaseFinetuning.unfreeze_and_add_param_group can raise the following warning:
/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2882: UserWarning: optimizer contains a parameter group with duplicate parameters; in future, this will cause an error; see github.com/pytorch/pytorch/issues/40967 for more information
exec(code_obj, self.user_global_ns, self.user_ns)
What happens is that due to the way the BaseFinetuning flattens the model before collecting the parameters, it's possible to list the same parameters twice. It iterates over all of the .modules(), but fails to filter it so that only leaf nodes in the model are returned when the model is nested and have custom blocks.
One example of model where the problem happens is:
A call to BaseFinetuning.flatten_modules(model) using the model above returns both the leaf nodes (conv2d, relu, batchnorm) and the ConvBlocks, listing all the layers twice.
Please reproduce using the BoringModel
The BoringModel is simple enough that the issue doesn't appear, so I added the most simple model that I could make reproducing the issue.
🐛 Bug
During finetuning with complex models, a call to
BaseFinetuning.unfreeze_and_add_param_groupcan raise the following warning:What happens is that due to the way the BaseFinetuning flattens the model before collecting the parameters, it's possible to list the same parameters twice. It iterates over all of the
.modules(), but fails to filter it so that only leaf nodes in the model are returned when the model is nested and have custom blocks.One example of model where the problem happens is:
A call to
BaseFinetuning.flatten_modules(model)using the model above returns both the leaf nodes (conv2d, relu, batchnorm) and the ConvBlocks, listing all the layers twice.Please reproduce using the BoringModel
The BoringModel is simple enough that the issue doesn't appear, so I added the most simple model that I could make reproducing the issue.
https://colab.research.google.com/drive/1-YR26kK41kCCNmaL8MYVCL8831FvbHNa?usp=sharing
Expected behavior
The BaseFinetuning don't try to add the same parameter twice when unfreezing complex models.
Environment
Bug reproduced using colab, with CPU only runtime
Additional context