open-mmlab / mmengine

OpenMMLab Foundational Library for Training Deep Learning Models
https://mmengine.readthedocs.io/
Apache License 2.0
1.15k stars 340 forks source link

[BUG] Use the Paramwise_cfg option to call the ADD_PARAMS method of defaultOPTIMWRAPPERUCTOR #1137

Open LinhanXu3928 opened 1 year ago

LinhanXu3928 commented 1 year ago

Prerequisite

Environment

English version:To simplify the problem, if my network consists of two blocks, each consisting of a convolutional layer and a linear transformation layer, but when defining the model, I only instantiate one linear transformation layer, and the two linear transformation layers are actually one object. In this way, I call the model. parameters() method to obtain a parameter set of convolution 2+linear 1=3 (without considering bias). But using paramwise After the cfg option, the add of the defaultOptimWrapperConstructor will be called The params method yields a parameter set of convolution 2+linear 2=4. I only save parameter groups based on the network structure, but I don't realize that some layers are actually an object. Using add_ When the parameter group obtained by the params method is fed into the adam optimizer, an error will be reported: some parameters appear in more than one parameter group. Because the linear layer was saved once more.

Reproduces the problem - code sample

I gave a simplified example of the problem with the model I built myself

Reproduces the problem - command or script

I gave a simplified example of the problem with the model I built myself

Reproduces the problem - error message

some parameters appear in more than one parameter group

Additional information

Hope to solve this bug.The add_params method should return the same value as the Model.parameter () method.

mm-assistant[bot] commented 1 year ago

We recommend using English or English & Chinese for issues so that we could have broader discussion.