Freeze a model consisting of two models

Hy guys,I have a model consisting of two models. How can I freeze the weight of first model and training only the second model?

The first model consisting of a load of .pth and I don’t want to train it more.
Sorry for my bad English.

Hi @Giuseppe

Let’s say supermodel is the model containing the two sub-models Model1 and Model2 and you only want to train Model2. You should be able to achieve it by adding this before training:

for param in supermodel.Model1.parameters():
    param.requires_grad = False
1 Like