Add a layer to model state dictionary in PyTorch
I have a neural network in PyTorch like,
class Net1(nn.Module):
    
    def __init__(self):
        super(Net, self).__init__()
        
        self.conv_g = ResBlock(2,81)
        self.conv_low1 = ResBlock(2,90)
        self.conv_low2 = ResBlock(2,90)
        self.conv_low3 = ResBlock(2,90)
        self.conv_low4 = ResBlock(2,90)
        self.conv_low5 = ResBlock(2,90)
        self.conv_low6 = ResBlock(2,90)
        self.conv_low7 = ResBlock(2,90)
        self.conv_low8 = ResBlock(2,90)
        self.conv_low9 = ResBlock(2,90)
        
        self.stagIII = stageIII()
        
    def forward(self,x):
        ...
        
        return out

To this network I have added a new layer m whose weights I know.
class Net2(nn.Module):
    
    def __init__(self):
        super(Net, self).__init__()

        self.m = nn.Linear(5,1)
        
        self.conv_g = ResBlock(2,81)
        self.conv_low1 = ResBlock(2,90)
        self.conv_low2 = ResBlock(2,90)
        self.conv_low3 = ResBlock(2,90)
        self.conv_low4 = ResBlock(2,90)
        self.conv_low5 = ResBlock(2,90)
        self.conv_low6 = ResBlock(2,90)
        self.conv_low7 = ResBlock(2,90)
        self.conv_low8 = ResBlock(2,90)
        self.conv_low9 = ResBlock(2,90)
        
        self.stagIII = stageIII()
        
    def forward(self,x):
        ...
        
        return out

The state dictionary of m.state_dict() is
OrderedDict([('weight', tensor([[ 1.0000,  2.0000,  3.0000,  4.0000, 5.0000]])), ('bias', tensor([0.]))])

Now given that I have Net1.state_dict() and m.state_dict(), how can I append m dictionary to Net1 dictionary to obtain state dictionary of Net2?

You can manually add them:
net2 = Net2()
net2.load_state_dict(net1_state_dict,strict=False)  # load what you can from the state_dict of Net1
net2.m.load_state_dict(m_state_dict)   # load sub module
# save the entire one for future use
torch.save(net2.state_dict(), 'merged_net2.pth.tar')

