Shared parameter model and submodel BP
<SCODE>class mm(nn.Module):
    def __init__(self):
        super(mm, self).__init__()
        self.m = nn.Linear(3,2)
        self.m2 = nn.Linear(2,4)
    def forward(self, input):
        o1 = self.m(input)
        o2 = self.m2(o1)
        return o1, o2

mmodel = mm()
optimizer = optim.SGD(mmodel.parameters(), lr=1, momentum=0.8)
#optimizer = optim.Adam(mmodel.parameters(), lr=1, betas=(0.5, 0.999))
input = Variable(torch.randn(1,3))
print(mmodel.m.weight.data)
print(mmodel.m2.weight.data)
mmodel.zero_grad()
output1, output = mmodel(input)
output1.backward(torch.ones(1,2))
#output.backward(torch.ones(1,4))
optimizer.step()
print(mmodel.m.weight.data)
print(mmodel.m2.weight.data)
<ECODE>
Marvin