プリンキピア

第19章ハイパーパラメータ最適化

19.3. Asynchronous Random Search19.3 非同期のランダム探索

As we have seen in the previous Section 19.2, we might have to wait hours or even days before random search returns a good hyperparameter configuration, because of the expensive evaluation of hyperparameter configurations. In practice, we have often access to a pool of resources such as multiple GPUs on the same machine or multiple machines with a single GPU. This begs the question: How do we efficiently distribute random search?
英語のヒント
前の19.2節で見たように、ハイパーパラメータの設定の評価は高くつくので、ランダム探索がよいハイパーパラメータの設定を返すまで、何時間も、あるいは何日も待たなければならないかもしれない。実際には、同じマシンの複数のGPUや、GPUを一つずつもつ複数のマシンのような、資源の蓄えにアクセスできることが多い。そこで次の疑問が生じる。ランダム探索をどうすれば効率よく分散できるか。
In general, we distinguish between synchronous and asynchronous parallel hyperparameter optimization (see Fig. 19.3.1). In the synchronous setting, we wait for all concurrently running trials to finish, before we start the next batch. Consider configuration spaces that contain hyperparameters such as the number of filters or number of layers of a deep neural network. Hyperparameter configurations that contain a larger number of layers of filters will naturally take more time to finish, and all other trials in the same batch will have to wait at synchronisation points (grey area in Fig. 19.3.1) before we can continue the optimization process.
英語のヒント
一般に、同期的な並列ハイパーパラメータ最適化と非同期的な並列ハイパーパラメータ最適化を区別する(図19.3.1を参照)。同期的な設定では、次のバッチを始める前に、並行して実行しているすべての試行が終わるのを待つ。深層ニューラルネットワークのフィルタの数や層の数のようなハイパーパラメータを含む設定空間を考えよう。層やフィルタの数が多いハイパーパラメータの設定は、当然終わるまでに時間がかかり、同じバッチのほかの試行はすべて、最適化の過程を続けられるようになるまで同期点(図19.3.1の灰色の部分)で待たなければならない。
In the asynchronous setting we immediately schedule a new trial as soon as resources become available. This will optimally exploit our resources, since we can avoid any synchronisation overhead. For random search, each new hyperparameter configuration is chosen independently of all others, and in particular without exploiting observations from any prior evaluation. This means we can trivially parallelize random search asynchronously. This is not straight-forward with more sophisticated methods that make decision based on previous observations (see Section 19.5). While we need access to more resources than in the sequential setting, asynchronous random search exhibits a linear speed-up, in that a certain performance is reached K times faster if K trials can be run in parallel.
英語のヒント
非同期的な設定では、資源が使えるようになったらすぐに新しい試行をスケジュールする。同期のオーバーヘッドをすべて避けられるので、これは資源を最適に利用する。ランダム探索では、新しいハイパーパラメータの設定はそれぞれ、ほかのすべての設定とは独立に、特に過去の評価からの観測をまったく利用せずに選ばれる。これは、ランダム探索をたやすく非同期に並列化できることを意味する。過去の観測にもとづいて決定を下す、もっと凝った方法では、これは簡単ではない(19.5節を参照)。逐次的な設定よりも多くの資源にアクセスする必要があるが、非同期のランダム探索は線形の高速化を示す。つまり、K個の試行を並列に実行できれば、ある性能にK倍速く到達する。
Fig. 19.3.1図19.3.1
Distributing the hyperparameter optimization process either synchronously or asynchronously. Compared to the sequential setting, we can reduce the overall wall-clock time while keep the total compute constant. Synchronous scheduling might lead to idling workers in the case of stragglers.
英語のヒント
ハイパーパラメータ最適化の過程を、同期的または非同期的に分散する。逐次的な設定と比べて、総計算量を一定に保ちながら、全体の実時間を減らせる。同期的なスケジューリングでは、遅れる試行があるとワーカーが遊んでしまうことがある。
In this notebook, we will look at asynchronous random search that, where trials are executed in multiple python processes on the same machine. Distributed job scheduling and execution is difficult to implement from scratch. We will use Syne Tune (Salinas et al., 2022), which provides us with a simple interface for asynchronous HPO. Syne Tune is designed to be run with different execution back-ends, and the interested reader is invited to study its simple APIs in order to learn more about distributed HPO.
英語のヒント
このノートブックでは、同じマシンの上の複数のPythonのプロセスで試行を実行する、非同期のランダム探索を見る。分散したジョブのスケジューリングと実行を一から実装するのは難しい。非同期のHPOのための簡単なインターフェースを与えてくれるSyne Tune(Salinas et al., 2022)を使う。Syne Tuneはさまざまな実行のバックエンドで動かせるように設計されており、興味のある読者は、分散HPOについてもっと学ぶためにその簡単なAPIを調べてみるとよい。
import logging
from d2l import torch as d2l

logging.basicConfig(level=logging.INFO)
from syne_tune import StoppingCriterion, Tuner
from syne_tune.backend.python_backend import PythonBackend
from syne_tune.config_space import loguniform, randint
from syne_tune.experiments import load_experiment
from syne_tune.optimizer.baselines import RandomSearch
INFO:root:SageMakerBackend is not imported since dependencies are missing. You can install them with
   pip install 'syne-tune[extra]'
AWS dependencies are not imported since dependencies are missing. You can install them with
   pip install 'syne-tune[aws]'
or (for everything)
   pip install 'syne-tune[extra]'
AWS dependencies are not imported since dependencies are missing. You can install them with
   pip install 'syne-tune[aws]'
or (for everything)
   pip install 'syne-tune[extra]'
INFO:root:Ray Tune schedulers and searchers are not imported since dependencies are missing. You can install them with
   pip install 'syne-tune[raytune]'
or (for everything)
   pip install 'syne-tune[extra]'