プリンキピア

第13章計算の性能

13.5.1. Splitting the Problem13.5.1 問題を分ける

Let’s start with a simple computer vision problem and a slightly archaic network, e.g., with multiple layers of convolutions, pooling, and possibly a few fully connected layers in the end. That is, let’s start with a network that looks quite similar to LeNet (LeCun et al., 1998) or AlexNet (Krizhevsky et al., 2012). Given multiple GPUs (2 if it is a desktop server, 4 on an AWS g4dn.12xlarge instance, 8 on a p3.16xlarge, or 16 on a p2.16xlarge), we want to partition training in a manner as to achieve good speedup while simultaneously benefitting from simple and reproducible design choices. Multiple GPUs, after all, increase both memory and computation ability. In a nutshell, we have the following choices, given a minibatch of training data that we want to classify.
英語のヒント
単純なコンピュータビジョンの問題と、少し古風なネットワーク、たとえば畳み込みとプーリングの層が複数あり、最後におそらく全結合層がいくつかあるネットワークから始めよう。つまり、LeNet(LeCun et al., 1998)やAlexNet(Krizhevsky et al., 2012)によく似たネットワークから始めよう。複数のGPU(デスクトップのサーバーなら2個、AWSのg4dn.12xlargeインスタンスなら4個、p3.16xlargeなら8個、p2.16xlargeなら16個)が与えられたとき、単純で再現できる設計の選択の恩恵を受けながら、よい高速化を達成するように訓練を分割したい。結局のところ、複数のGPUは、メモリと計算能力の両方を増やす。手短に言えば、分類したい訓練データのミニバッチが与えられたとき、次の選択肢がある。
First, we could partition the network across multiple GPUs. That is, each GPU takes as input the data flowing into a particular layer, processes data across a number of subsequent layers and then sends the data to the next GPU. This allows us to process data with larger networks when compared with what a single GPU could handle. Besides, memory footprint per GPU can be well controlled (it is a fraction of the total network footprint).
英語のヒント
第一に、ネットワークを複数のGPUに分割できる。つまり、各GPUは、特定の層に流れ込むデータを入力としてとり、後に続くいくつかの層でデータを処理し、それから次のGPUにデータを送る。これにより、一つのGPUで扱えるものと比べて、もっと大きなネットワークでデータを処理できる。さらに、GPUあたりのメモリの使用量をうまく制御できる(ネットワーク全体の使用量の一部になる)。
However, the interface between layers (and thus GPUs) requires tight synchronization. This can be tricky, in particular if the computational workloads are not properly matched between layers. The problem is exacerbated for large numbers of GPUs. The interface between layers also requires large amounts of data transfer, such as activations and gradients. This may overwhelm the bandwidth of the GPU buses. Moreover, compute-intensive, yet sequential operations are nontrivial to partition. See e.g., Mirhoseini et al. (2017) for a best effort in this regard. It remains a difficult problem and it is unclear whether it is possible to achieve good (linear) scaling on nontrivial problems. We do not recommend it unless there is excellent framework or operating system support for chaining together multiple GPUs.
英語のヒント
しかし、層(したがってGPU)のあいだのインターフェースには、厳密な同期が必要になる。特に、層のあいだで計算の作業量がうまく釣り合っていないと、これは厄介になりうる。この問題は、GPUの数が多いとさらに悪化する。層のあいだのインターフェースには、活性化や勾配のような大量のデータ転送も必要になる。これはGPUのバスの帯域を圧倒するかもしれない。さらに、計算が重く、しかも逐次的な演算は、分割するのが自明ではない。この点での最善の努力は、たとえばMirhoseini et al. (2017)を参照。それは依然として難しい問題であり、自明でない問題でよい(線形の)スケーリングを達成できるかどうかははっきりしない。複数のGPUを連結することについて、フレームワークやオペレーティングシステムのすぐれたサポートがない限り、これは勧めない。
Second, we could split the work layerwise. For instance, rather than computing 64 channels on a single GPU we could split up the problem across 4 GPUs, each of which generates data for 16 channels. Likewise, for a fully connected layer we could split the number of output units. Fig. 13.5.1 (taken from Krizhevsky et al. (2012)) illustrates this design, where this strategy was used to deal with GPUs that had a very small memory footprint (2 GB at the time). This allows for good scaling in terms of computation, provided that the number of channels (or units) is not too small. Besides, multiple GPUs can process increasingly larger networks since the available memory scales linearly.
英語のヒント
第二に、仕事を層ごとに分けられる。たとえば、一つのGPUで64チャネルを計算する代わりに、問題を4個のGPUに分け、それぞれが16チャネル分のデータを生成するようにできる。同じように、全結合層では、出力ユニットの数を分けられる。図13.5.1(Krizhevsky et al. (2012)より)はこの設計を示しており、そこではこの戦略は、メモリがとても小さい(当時2 GB)GPUに対処するために使われた。これにより、チャネル(あるいはユニット)の数が小さすぎなければ、計算の点でよいスケーリングが得られる。さらに、使えるメモリが線形に増えるので、複数のGPUで次第に大きなネットワークを処理できる。
Fig. 13.5.1図13.5.1
Model parallelism in the original AlexNet design due to limited GPU memory.
英語のヒント
限られたGPUのメモリのための、元のAlexNetの設計でのモデル並列化。
However, we need a very large number of synchronization or barrier operations since each layer depends on the results from all the other layers. Moreover, the amount of data that needs to be transferred is potentially even larger than when distributing layers across GPUs. Thus, we do not recommend this approach due to its bandwidth cost and complexity.
英語のヒント
しかし、各層はほかのすべての層の結果に依存するので、同期やバリアの演算がとても多く必要になる。さらに、転送する必要のあるデータの量は、層をGPUに分散する場合よりさらに大きくなるかもしれない。したがって、帯域のコストと複雑さのため、このやり方は勧めない。
Last, we could partition data across multiple GPUs. This way all GPUs perform the same type of work, albeit on different observations. Gradients are aggregated across GPUs after each minibatch of training data. This is the simplest approach and it can be applied in any situation. We only need to synchronize after each minibatch. That said, it is highly desirable to start exchanging gradients parameters already while others are still being computed. Moreover, larger numbers of GPUs lead to larger minibatch sizes, thus increasing training efficiency. However, adding more GPUs does not allow us to train larger models.
英語のヒント
最後に、データを複数のGPUに分割できる。こうすると、異なる観測についてではあるが、すべてのGPUが同じ種類の仕事を行う。勾配は、訓練データの各ミニバッチの後にGPUにわたって集められる。これは最も単純なやり方であり、どんな状況にも当てはめられる。各ミニバッチの後に同期するだけでよい。とはいえ、ほかの勾配がまだ計算されているあいだに、すでに勾配のパラメータを交換し始めるのがとても望ましい。さらに、GPUの数が多いほどミニバッチの大きさが大きくなり、訓練の効率が上がる。しかし、GPUを増やしても、もっと大きなモデルを訓練できるようにはならない。
Fig. 13.5.2図13.5.2
Parallelization on multiple GPUs. From left to right: original problem, network partitioning, layerwise partitioning, data parallelism.
英語のヒント
複数のGPUでの並列化。左から右へ、元の問題、ネットワークの分割、層ごとの分割、データ並列。
A comparison of different ways of parallelization on multiple GPUs is depicted in Fig. 13.5.2. By and large, data parallelism is the most convenient way to proceed, provided that we have access to GPUs with sufficiently large memory. See also (Li et al., 2014) for a detailed description of partitioning for distributed training. GPU memory used to be a problem in the early days of deep learning. By now this issue has been resolved for all but the most unusual cases. We focus on data parallelism in what follows.
英語のヒント
複数のGPUでのさまざまな並列化のやり方の比較を図13.5.2に描いた。大まかに言って、十分大きなメモリのGPUを使えるなら、データ並列が最も便利な進め方である。分散訓練のための分割の詳しい説明は、(Li et al., 2014)も参照。GPUのメモリは、深層学習の初期には問題だった。いまでは、ごく特殊な場合を除いて、この問題は解決されている。以下では、データ並列に焦点を当てる。