Load weights to a custom model

The more I read papers, the more frequently I encounter that authors, let`s say, implement a custom attention mechanism and measure its performance in a trained original model (T5 for instance). It is not clear to me how can I load weights to a model that has a slightly different structure than the original one. So is there a way to load weights only to those layers that are identical between an original model and a custom?