How to replace the weights of certain layers in a model

Suppose I loaded a model A using the transformer library, which has weight parameters weightA. Now I have another model’s weight parameters weightB, and I want to replace some layers’ weights in A with those from B. How should I go about doing this?