プリンキピア

第13章計算の性能

13.7.1. Data-Parallel Training13.7.1 データ並列の訓練

Let’s review the data parallel training approach to distributed training. We will use this to the exclusion of all others in this section since it is significantly simpler to implement in practice. There are virtually no use cases (besides deep learning on graphs) where any other strategy for parallelism is preferred since GPUs have plenty of memory nowadays. Fig. 13.7.1 describes the variant of data parallelism that we implemented in Section 13.5. The key aspect in it is that the aggregation of gradients occurs on one single GPU (GPU 0) before the updated parameters are rebroadcast to all GPUs.
英語のヒント
分散訓練へのデータ並列の訓練のやり方を振り返ろう。実際に実装するのがずっと簡単なので、この節ではほかのすべてを除いてこれを使う。今日ではGPUのメモリは十分にあるので、(グラフでの深層学習を除いて)並列化のためにほかの戦略が好まれる使い道は事実上ない。図13.7.1は、13.5節で実装したデータ並列の変種を表している。その重要な点は、更新したパラメータをすべてのGPUにブロードキャストし直す前に、勾配の集約が一つのGPU(GPU 0)で行われることである。
Fig. 13.7.1図13.7.1
Left: single GPU training. Right: a variant of multi-GPU training: (1) we compute loss and gradient, (2) all gradients are aggregated on one GPU, (3) parameter update happens and the parameters are re-distributed to all GPUs.
英語のヒント
左:一つのGPUでの訓練。右:複数GPUでの訓練の一つの変種。(1)損失と勾配を計算し、(2)すべての勾配を一つのGPUに集め、(3)パラメータを更新し、パラメータをすべてのGPUに配り直す。
In retrospect, the decision to aggregate on GPU 0 seems rather ad-hoc. After all, we might just as well aggregate on the CPU. In fact, we could even decide to aggregate some of the parameters on one GPU and some others on another. Provided that the optimization algorithm supports this, there is no real reason for why we could not. For instance, if we have four parameter vectors with associated gradients 𝐠1,…,𝐠4 we could aggregate the gradients on one GPU for each 𝐠i (i=1,…,4).
英語のヒント
振り返ってみると、GPU 0で集約するという決定は、かなり場当たり的に見える。結局のところ、CPUで集約してもよかった。実際、パラメータの一部をあるGPUで、ほかの一部を別のGPUで集約すると決めることさえできる。最適化アルゴリズムがこれをサポートしていれば、できない本当の理由はない。たとえば、対応する勾配𝐠1,…,𝐠4をもつ四つのパラメータベクトルがあれば、各𝐠i(i=1,…,4)について、一つのGPUで勾配を集約できる。
This reasoning seems arbitrary and frivolous. After all, the mathematics is the same throughout. However, we are dealing with real physical hardware where different buses have different bandwidth as discussed in Section 13.4. Consider a real 4-way GPU server as described in Fig. 13.7.2. If it is particularly well connected, it might have a 100 GbE network card. More typical numbers are in the 1–10 GbE range with an effective bandwidth of 100 MB/s to 1 GB/s. Since the CPUs have too few PCIe lanes to connect to all GPUs directly (e.g., consumer-grade Intel CPUs have 24 lanes) we need a multiplexer. The bandwidth from the CPU on a 16x Gen3 link is 16 GB/s. This is also the speed at which each of the GPUs is connected to the switch. This means that it is more effective to communicate between the devices.
英語のヒント
この推論は恣意的で軽薄に見える。結局のところ、数学はどこでも同じである。しかし、13.4節で論じたように、異なるバスが異なる帯域をもつ、実際の物理的なハードウェアを扱っている。図13.7.2で説明するような、実際の4GPUのサーバーを考えよう。特にうまく接続されていれば、100 GbEのネットワークカードがあるかもしれない。もっと典型的な数字は1〜10 GbEの範囲で、実質的な帯域は100 MB/sから1 GB/sである。CPUにはすべてのGPUに直接つなぐにはPCIeのレーンが少なすぎるので(たとえば一般向けのIntel CPUには24レーンある)、マルチプレクサが必要になる。16x Gen3リンクでのCPUからの帯域は16 GB/sである。これは、各GPUがスイッチにつながる速さでもある。これは、装置のあいだで通信するほうが効果的であることを意味する。
Fig. 13.7.2図13.7.2
A 4-way GPU server.
英語のヒント
4GPUのサーバー。
For the sake of the argument let’s assume that the gradients are of 160 MB. In this case it takes 30 ms to send the gradients from all 3 remaining GPUs to the fourth one (each transfer takes 10 ms = 160 MB / 16 GB/s). Adding another 30 ms to transmit the weight vectors back we arrive at a total of 60 ms. If we send all data to the CPU we incur a penalty of 40 ms since each of the four GPUs needs to send the data to the CPU, yielding a total of 80 ms. Lastly assume that we are able to split the gradients into 4 parts of 40 MB each. Now we can aggregate each of the parts on a different GPU simultaneously since the PCIe switch offers a full-bandwidth operation between all links. Instead of 30 ms this takes 7.5 ms, yielding a total of 15 ms for a synchronization operation. In short, depending on how we synchronize parameters the same operation can take anywhere from 15 ms to 80 ms. Fig. 13.7.3 depicts the different strategies for exchanging parameters.
英語のヒント
議論のため、勾配が160 MBだとしよう。この場合、残りの3個のGPUすべてから4個目に勾配を送るのに30 msかかる(各転送に10 ms = 160 MB / 16 GB/sかかる)。重みベクトルを送り返すのにさらに30 msを加えると、合計60 msになる。すべてのデータをCPUに送ると、4個のGPUのそれぞれがデータをCPUに送る必要があるので40 msのペナルティを招き、合計80 msになる。最後に、勾配をそれぞれ40 MBの四つの部分に分けられるとしよう。PCIeスイッチはすべてのリンクのあいだで全帯域の動作を与えるので、これで各部分を異なるGPUで同時に集約できる。30 msの代わりに7.5 msで済み、同期の操作は合計15 msになる。要するに、パラメータをどう同期させるかによって、同じ操作に15 msから80 msまでかかりうる。図13.7.3は、パラメータを交換するさまざまな戦略を描いている。
Fig. 13.7.3図13.7.3
Parameter synchronization strategies.
英語のヒント
パラメータの同期の戦略。
Note that we have yet another tool at our disposal when it comes to improving performance: in a deep network it takes some time to compute all gradients from the top to the bottom. We can begin synchronizing gradients for some parameter groups even while we are still busy computing them for others. See e.g., Sergeev and Del Balso (2018) for details on how to do this in Horovod.
英語のヒント
性能を上げることについては、さらに別の道具を使えることに注意してほしい。深いネットワークでは、すべての勾配を上から下まで計算するのに時間がかかる。ほかのパラメータグループの勾配をまだ計算しているあいだにも、一部のパラメータグループの勾配の同期を始められる。Horovodでこれをどう行うかの詳細は、たとえばSergeev and Del Balso (2018)を参照。