针对于模型并行,我的理解是可以把神经网络的模型拆开,每一层放到一个worker中。例如模型有三层。可以放到3个worker中。worker1、worker2、worker3。
前向传播。worker1计算完成的输出是worker2的输入。worker2和worker3同理。
self.net1 = torch.nn.Linear(10, 10).to('cuda:0') # 将net1放置在第1个GPU上self.relu = torch.nn.ReLU()self.net2 = torch.nn.Linear(10, 5).to('cuda:1') # 将net2放置在第2个GPU上self.net3 = torch.nn.Linear(10, 5).to('cuda:2') # 将net3放置在第3个GPU上def forward(self, x):x = self.relu(self.net1(x.to('cuda:0'))x1= self.relu(self.net2(x.to('cuda:1'))return self.net3(x.to('cuda:2'))
反向传播 过程就是一层一层的反向传播。
我把它理解为这样:
![](https://img8.php1.cn/3cdc5/18414/3b4/862590b2f893f033.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3podWl5dW56aHVnYW5n,size_16,color_FFFFFF,t_70)
这个过程应该是最low的模型分布