How to load and freeze part of network

I have a network consist of two parts.I want to train the first part alone to get a pth file.then,modify the code to add the second part into my network,the first part is not modified.now load and freeze the first pre-trained part,train the second one,and finally generate a whole pth file.I’m confused about how to write the code in my training loop.I use pretrained vgg inside my network, but I write down the load and freeze code inside the architecture,not the train loop.What if I want to load my own pth file and freeze some part of my network in the training code?

As per my understanding here is my answer(Suggestion)
Have Two Separate Networks

Network -I (Your First Part)
Network -II (Your First Part + Second Part)

So when you train your Network I and get the “.pth” file

Load it into the Second network II .After loading set require.grad=False for the first part of network in Network II which would freeze the network.Finish the training generate new files required by you.