第6章構築者のための手引き
6.7. GPUs6.7 GPU
In
tab_intro_decade, we illustrated the rapid growth of computation over the past two decades. In a nutshell, GPU performance has increased by a factor of 1000 every decade since 2000. This offers great opportunities but it also suggests that there was significant demand for such performance.英語のヒント
tab_intro_decadeでは、過去20年の計算能力の急速な成長を示した。一言で言えば、GPUの性能は2000年以来、10年ごとに1000倍になってきた。これは大きな機会をもたらすが、そうした性能への大きな需要があったことも示唆している。In this section, we begin to discuss how to harness this computational performance for your research. First by using a single GPU and at a later point, how to use multiple GPUs and multiple servers (with multiple GPUs).
英語のヒント
この節では、この計算性能を研究に活用する方法を論じ始める。まずは一つのGPUを使う方法を、後には複数のGPUと(複数のGPUを積んだ)複数のサーバーを使う方法を扱う。
Specifically, we will discuss how to use a single NVIDIA GPU for calculations. First, make sure you have at least one NVIDIA GPU installed. Then, download the NVIDIA driver and CUDA and follow the prompts to set the appropriate path. Once these preparations are complete, the
nvidia-smi command can be used to view the graphics card information.英語のヒント
具体的には、一つのNVIDIA製GPUを計算に使う方法を論じる。まず、少なくとも一つのNVIDIA製GPUが取り付けられていることを確かめる。次に、NVIDIAのドライバとCUDAをダウンロードし、案内に従って適切なパスを設定する。これらの準備が済んだら、
nvidia-smiコマンドを使ってグラフィックスカードの情報を見られる。In PyTorch, every array has a device; we often refer it as a context. So far, by default, all variables and associated computation have been assigned to the CPU. Typically, other contexts might be various GPUs. Things can get even hairier when we deploy jobs across multiple servers. By assigning arrays to contexts intelligently, we can minimize the time spent transferring data between devices. For example, when training neural networks on a server with a GPU, we typically prefer for the model’s parameters to live on the GPU.
英語のヒント
PyTorchでは、すべての配列にデバイスがある。これをコンテキストと呼ぶことも多い。ここまでは、既定で、すべての変数とそれに伴う計算がCPUに割り当てられてきた。ふつう、ほかのコンテキストはさまざまなGPUである。複数のサーバーにまたがって仕事を展開すると、事情はさらにこじれる。配列を賢くコンテキストに割り当てれば、デバイスのあいだでデータを転送するのに費やす時間を最小にできる。たとえば、GPUを積んだサーバーでニューラルネットワークを訓練するときには、ふつうモデルのパラメータがGPU上にあるほうが望ましい。
To run the programs in this section, you need at least two GPUs. Note that this might be extravagant for most desktop computers but it is easily available in the cloud, e.g., by using the AWS EC2 multi-GPU instances. Almost all other sections do not require multiple GPUs, but here we simply wish to illustrate data flow between different devices.
英語のヒント
この節のプログラムを走らせるには、少なくとも二つのGPUが必要である。これはほとんどのデスクトップコンピュータにはぜいたくかもしれないが、クラウドなら、たとえばAWS EC2の複数GPUのインスタンスを使えば簡単に手に入ることに注意してほしい。ほかのほとんどすべての節は複数のGPUを必要としないが、ここでは単に、異なるデバイスのあいだのデータの流れを示したいのである。
import torch
from torch import nn
from d2l import torch as d2l