第13章計算の性能
13.5.2. Data Parallelism13.5.2 データ並列
Assume that there are GPUs on a machine. Given the model to be trained, each GPU will maintain a complete set of model parameters independently though parameter values across the GPUs are identical and synchronized. As an example, Fig. 13.5.3 illustrates training with data parallelism when .
英語のヒント
一つのマシンに個のGPUがあるとする。訓練するモデルが与えられたとき、各GPUはモデルのパラメータの完全な組を独立に保持するが、GPUにわたるパラメータの値は同一で、同期されている。例として、図13.5.3は、のときのデータ並列による訓練を示している。
Fig. 13.5.3図13.5.3
Calculation of minibatch stochastic gradient descent using data parallelism on two GPUs.
英語のヒント
二つのGPUでデータ並列を使った、ミニバッチ確率的勾配降下法の計算。
In general, the training proceeds as follows:
英語のヒント
一般に、訓練は次のように進む。
- In any iteration of training, given a random minibatch, we split the examples in the batch into portions and distribute them evenly across the GPUs.
英語のヒント
訓練のどの反復でも、ランダムなミニバッチが与えられたら、バッチの事例を個の部分に分け、GPUに均等に配る。 - Each GPU calculates loss and gradient of the model parameters based on the minibatch subset it was assigned.
英語のヒント
各GPUは、割り当てられたミニバッチの部分集合にもとづいて、損失とモデルのパラメータの勾配を計算する。 - The local gradients of each of the GPUs are aggregated to obtain the current minibatch stochastic gradient.
英語のヒント
個のGPUそれぞれの局所的な勾配を集めて、現在のミニバッチの確率的勾配を得る。 - The aggregate gradient is re-distributed to each GPU.
英語のヒント
集めた勾配を各GPUに配り直す。 - Each GPU uses this minibatch stochastic gradient to update the complete set of model parameters that it maintains.
英語のヒント
各GPUは、このミニバッチの確率的勾配を使って、自分が保持するモデルのパラメータの完全な組を更新する。
Note that in practice we increase the minibatch size -fold when training on GPUs such that each GPU has the same amount of work to do as if we were training on a single GPU only. On a 16-GPU server this can increase the minibatch size considerably and we may have to increase the learning rate accordingly. Also note that batch normalization in Section 8.5 needs to be adjusted, e.g., by keeping a separate batch normalization coefficient per GPU. In what follows we will use a toy network to illustrate multi-GPU training.
英語のヒント
実際には、個のGPUで訓練するとき、各GPUが一つのGPUだけで訓練する場合と同じ量の仕事をするように、ミニバッチの大きさを倍にすることに注意してほしい。16GPUのサーバーでは、これでミニバッチの大きさがかなり大きくなり、それに応じて学習率を上げる必要があるかもしれない。また、8.5節のバッチ正規化は、たとえばGPUごとに別々のバッチ正規化の係数を保つなどして、調整する必要があることにも注意してほしい。以下では、おもちゃのネットワークを使って、複数GPUでの訓練を示す。
%matplotlib inline
import torch
from torch import nn
from torch.nn import functional as F
from d2l import torch as d2l