Loading optimizer state-dict for different model

Suppose I train model M1 with optimizer O1. I save the state_dict of both.

Now I add a few layers to M1 to create model M2. It is possible to load the weights of M1 to M2.

Is it possible to do the equivalent operation for the optimizer? Ideally we would create optimizer O2 for model M2 and then load the state dict of O1 onto O2 to correspond to the parameters of M1.

Many thanks