Hi, all.
I want to freeze a model. I have two questions about this.

Is this the right way to freeze?

class Network(nn.Module):
 ...
class NetworkToFreeze(nn.Module):
 ...

for p in network.parameters():
    p.requires_grad = True
for p in network_to_freeze.parameters():
    p.requires_grad = True
...
for epoch in train_process:
       if epoch < 50:
           train all network code(Same code here*)
       if epoch >= 50:
           for p in network_to_freeze.parameters():
               p.requires_grad = False
           train all network code(Same code here*)

######################################################
2. Or just not applying loss value to the backward() is ok ?
   if epoch < 50:
       train all network code(Same code here*)
       total_loss = network_loss + network_to_freeze_loss
       total_loss.backward()
   if epoch >=50:
       train all network code(Same code here*)
       total_loss = network_loss
       total_loss.backward()