Create different nn.Modules for B and main network. So you don’t have to worry about them.
class modelB(nn.Module):
    # code

class mainModel(nn.Module):
    # Call modelB in this code

When you said I’m freezing the entire network except B, you freeez layer 1 and layer 2. and A. Now if you have a separate model class for B you can train it like any other network.