Here’a code excerpt
model = // define your model here
for param in model.parameters():
     param.requires_grad = False

This freezes all the layers of the model. To freeze only a portion of it, you can do conditioning in the loop.