You could iterate the parameters you would like to freeze and set their .requires_grad attribute to False:
for name, param in model.layer1.named_parameters():
    param.requires_grad = False

for name, param in model.layer2.named_parameters():
    param.requires_grad = False

...

Depending how the model was created you could also directly use submodules as model.submodule.prameters().