第19章ハイパーパラメータ最適化
19.5. Asynchronous Successive Halving19.5 非同期の逐次半減法
As we have seen in Section 19.3, we can accelerate HPO by distributing the evaluation of hyperparameter configurations across either multiple instances or multiples CPUs / GPUs on a single instance. However, compared to random search, it is not straightforward to run successive halving (SH) asynchronously in a distributed setting. Before we can decide which configuration to run next, we first have to collect all observations at the current rung level. This requires to synchronize workers at each rung level. For example, for the lowest rung level , we first have to evaluate all configurations, before we can promote the of them to the next rung level.
英語のヒント
19.3節で見たように、ハイパーパラメータの設定の評価を、複数のインスタンス、または一つのインスタンスの複数のCPUやGPUに分散させることで、HPOを速められる。しかし、ランダム探索と比べて、逐次半減法(SH)を分散した設定で非同期に実行するのは簡単ではない。次にどの設定を実行するかを決める前に、まず現在の段の水準ですべての観測を集めなければならない。これには、各段の水準でワーカーを同期させる必要がある。たとえば、最も低い段の水準では、そのうちのを次の段の水準に昇格させる前に、まず個の設定をすべて評価しなければならない。
In any distributed system, synchronization typically implies idle time for workers. First, we often observe high variations in training time across hyperparameter configurations. For example, assuming the number of filters per layer is a hyperparameter, then networks with less filters finish training faster than networks with more filters, which implies idle worker time due to stragglers. Moreover, the number of slots in a rung level is not always a multiple of the number of workers, in which case some workers may even sit idle for a full batch.
英語のヒント
どんな分散システムでも、同期はふつうワーカーの遊び時間を意味する。第一に、ハイパーパラメータの設定ごとに訓練時間が大きくばらつくことがよくある。たとえば、層ごとのフィルタの数がハイパーパラメータだとすると、フィルタの少ないネットワークはフィルタの多いネットワークよりも速く訓練を終えるので、遅れるもののせいでワーカーに遊び時間が生じる。さらに、段の水準の枠の数はいつもワーカーの数の倍数とはかぎらず、その場合、バッチ一つ分のあいだずっと遊んでいるワーカーさえ出る。
Figure Fig. 19.5.1 shows the scheduling of synchronous SH with for four different trials with two workers. We start with evaluating Trial-0 and Trial-1 for one epoch and immediately continue with the next two trials once they are finished. We first have to wait until Trial-2 finishes, which takes substantially more time than the other trials, before we can promote the best two trials, i.e., Trial-0 and Trial-3 to the next rung level. This causes idle time for Worker-1. Then, we continue with Rung 1. Also, here Trial-3 takes longer than Trial-0, which leads to an additional ideling time of Worker-0. Once, we reach Rung-2, only the best trial, Trial-0, remains which occupies only one worker. To avoid that Worker-1 idles during that time, most implementaitons of SH continue already with the next round, and start evaluating new trials (e.g Trial-4) on the first rung.
英語のヒント
図19.5.1は、二つのワーカーで四つの異なる試行について、とした同期的なSHのスケジューリングを示している。まずTrial-0とTrial-1を1エポック評価し、それらが終わったらすぐに次の二つの試行に進む。最良の二つの試行、つまりTrial-0とTrial-3を次の段の水準に昇格させる前に、ほかの試行よりもかなり長くかかるTrial-2が終わるまで待たなければならない。これはWorker-1に遊び時間を生じさせる。それから、Rung 1に進む。ここでもTrial-3はTrial-0より長くかかり、Worker-0に追加の遊び時間が生じる。Rung-2に達すると、最良の試行であるTrial-0だけが残り、ワーカーを一つしか使わない。そのあいだにWorker-1が遊ぶのを避けるため、SHのたいていの実装は、すでに次のラウンドに進み、最初の段で新しい試行(たとえばTrial-4)の評価を始める。
Fig. 19.5.1図19.5.1
Synchronous successive halving with two workers.
英語のヒント
二つのワーカーでの同期的な逐次半減法。
Asynchronous successive halving (ASHA) (Li et al., 2018) adapts SH to the asynchronous parallel scenario. The main idea of ASHA is to promote configurations to the next rung level as soon as we collected at least observations on the current rung level. This decision rule may lead to suboptimal promotions: configurations can be promoted to the next rung level, which in hindsight do not compare favourably against most others at the same rung level. On the other hand, we get rid of all synchronization points this way. In practice, such suboptimal initial promotions have only a modest impact on performance, not only because the ranking of hyperparameter configurations is often fairly consistent across rung levels, but also because rungs grow over time and reflect the distribution of metric values at this level better and better. If a worker is free, but no configuration can be promoted, we start a new configuration with , i.e the first rung level.
英語のヒント
非同期の逐次半減法(ASHA)(Li et al., 2018)は、SHを非同期の並列の状況に適応させる。ASHAの主な考え方は、現在の段の水準で少なくとも個の観測を集めたらすぐに、設定を次の段の水準に昇格させることである。この決定規則は最適でない昇格につながりうる。つまり、後から見れば同じ段の水準のほかのたいていの設定より見劣りする設定が、次の段の水準に昇格されることがありうる。一方、このやり方ですべての同期点をなくせる。実際には、そうした最初の最適でない昇格は性能にわずかな影響しか与えない。ハイパーパラメータの設定の順位が段の水準をまたいでかなり一貫していることが多いからだけでなく、段は時間とともに大きくなり、その水準での指標の値の分布をますますよく反映するようになるからでもある。ワーカーが空いているのに昇格できる設定がなければ、、つまり最初の段の水準で新しい設定を始める。
Fig. 19.5.2 shows the scheduling of the same configurations for ASHA. Once Trial-1 finishes, we collect the results of two trials (i.e Trial-0 and Trial-1) and immediately promote the better of them (Trial-0) to the next rung level. After Trial-0 finishes on rung 1, there are too few trials there in order to support a further promotion. Hence, we continue with rung 0 and evaluate Trial-3. Once Trial-3 finishes, Trial-2 is still pending. At this point we have 3 trials evaluated on rung 0 and one trial evaluated already on rung 1. Since Trial-3 performs worse than Trial-0 at rung 0, and , we cannot promote any new trial yet, and Worker-1 starts Trial-4 from scratch instead. However, once Trial-2 finishes and scores worse than Trial-3, the latter is promoted towards rung 1. Afterwards, we collected 2 evaluations on rung 1, which means we can now promote Trial-0 towards rung 2. At the same time, Worker-1 continues with evaluating new trials (i.e., Trial-5) on rung 0.
英語のヒント
図19.5.2は、ASHAでの同じ設定のスケジューリングを示している。Trial-1が終わると、二つの試行(つまりTrial-0とTrial-1)の結果を集め、そのうちのよいほう(Trial-0)をすぐに次の段の水準に昇格させる。Trial-0がrung 1で終わった後、そこには試行が少なすぎて、さらなる昇格を支えられない。したがって、rung 0に戻ってTrial-3を評価する。Trial-3が終わっても、Trial-2はまだ終わっていない。この時点で、rung 0で3個の試行が評価され、rung 1ですでに1個の試行が評価されている。rung 0でTrial-3はTrial-0より性能が悪く、なので、まだ新しい試行を昇格させられず、代わりにWorker-1はTrial-4を一から始める。しかし、Trial-2が終わってTrial-3より悪いスコアになると、後者がrung 1へ昇格される。その後、rung 1で2個の評価を集めたので、今度はTrial-0をrung 2へ昇格させられる。同時に、Worker-1はrung 0で新しい試行(つまりTrial-5)の評価を続ける。
Fig. 19.5.2図19.5.2
Asynchronous successive halving (ASHA) with two workers.
英語のヒント
二つのワーカーでの非同期の逐次半減法(ASHA)。
import logging
from d2l import torch as d2l
logging.basicConfig(level=logging.INFO)
import matplotlib.pyplot as plt
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 ASHAINFO: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]'