> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> 既存のW&Bプロジェクトからsweepジョブを作成する方法を説明するチュートリアル。

# チュートリアル: プロジェクトからsweepジョブを作成する

このチュートリアルでは、既存のW\&Bプロジェクトからsweepジョブを作成する方法を説明します。[Fashion MNISTデータセット](https://github.com/zalandoresearch/fashion-mnist)を使用して、画像を分類するPyTorchの畳み込みニューラルネットワークをトレーニングします。必要なコードとデータセットは、[W\&B examplesリポジトリ (PyTorch CNN Fashion)](https://github.com/wandb/examples/tree/master/examples/pytorch/pytorch-cnn-fashion) にあります。

結果はこの[W\&Bダッシュボード](https://app.wandb.ai/carey/pytorch-cnn-fashion)で確認できます。

<div id="1-create-a-project">
  ## 1. プロジェクトを作成する
</div>

まず、ベースラインを作成します。W\&B examples の GitHub repository から PyTorch MNIST データセットのサンプルモデルをダウンロードします。次に、モデルをトレーニングします。トレーニングスクリプトは `examples/pytorch/pytorch-cnn-fashion` ディレクトリにあります。

1. このリポジトリをクローンします `git clone https://github.com/wandb/examples.git`
2. このサンプルのディレクトリに移動します `cd examples/pytorch/pytorch-cnn-fashion`
3. run を手動で実行します `python train.py`

必要に応じて、W\&B App UI のダッシュボードでこのサンプルを確認してください。

[サンプルのプロジェクトページを表示 →](https://app.wandb.ai/carey/pytorch-cnn-fashion)

<div id="2-create-a-sweep">
  ## 2. sweep を作成する
</div>

プロジェクトページで、プロジェクトのサイドバーにある [Sweep タブ](./visualize-sweep-results) を開き、**Create Sweep** を選択します。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-hivemind-launch/R2JcDHqq5H9e7IgE/images/sweeps/sweep1.png?fit=max&auto=format&n=R2JcDHqq5H9e7IgE&q=85&s=52ec99f7779a8094375642261992bb50" alt="Sweep の概要" width="1589" height="636" data-path="images/sweeps/sweep1.png" />
</Frame>

自動生成された設定は、完了済みの run に基づいて、sweep する値を推定します。試したいハイパーパラメーターの範囲を指定するように設定を編集します。sweep を起動すると、W\&B のホスト型 sweep サーバー上で新しいプロセスが開始されます。この集中管理型サービスが、agent (トレーニング ジョブを実行しているマシン) を調整します。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-hivemind-launch/R2JcDHqq5H9e7IgE/images/sweeps/sweep2.png?fit=max&auto=format&n=R2JcDHqq5H9e7IgE&q=85&s=c3991207efe08f9c73d901a02919dc52" alt="Sweep の設定" width="2308" height="1768" data-path="images/sweeps/sweep2.png" />
</Frame>

<div id="3-launch-agents">
  ## 3. agentを起動する
</div>

次に、ローカルでagentを起動します。作業を分散して sweep ジョブをより早く完了したい場合は、異なるマシン上で最大 20 個のagentを並列に起動できます。agentは、次に試行するパラメーターのセットを出力します。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-hivemind-launch/R2JcDHqq5H9e7IgE/images/sweeps/sweep3.png?fit=max&auto=format&n=R2JcDHqq5H9e7IgE&q=85&s=5fa2c472d65705be7baa42734b044b4b" alt="agentを起動する" width="2082" height="1046" data-path="images/sweeps/sweep3.png" />
</Frame>

これで sweep を実行中です。次の画像は、サンプルの sweep ジョブの実行中にダッシュボードがどのように表示されるかを示しています。[プロジェクトページの例を表示 →](https://app.wandb.ai/carey/pytorch-cnn-fashion)

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-hivemind-launch/R2JcDHqq5H9e7IgE/images/sweeps/sweep4.png?fit=max&auto=format&n=R2JcDHqq5H9e7IgE&q=85&s=d519ef178117ac64c3fa0cec6ed2b9d7" alt="sweep ダッシュボード" width="3346" height="1512" data-path="images/sweeps/sweep4.png" />
</Frame>

<div id="seed-a-new-sweep-with-existing-runs">
  ## 既存のrunを使って新しいsweepを初期化する
</div>

これまでにログした既存のrunを使用して、新しいsweepを開始します。

1. プロジェクトの表を開きます。
2. 表の左側にあるチェックボックスで、使用するrunを選択します。
3. ドロップダウンをクリックして、新しいsweepを作成します。

これで、sweepがサーバー上に設定されます。あとは、1つ以上のagentを起動して、runを実行するだけです。

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-hivemind-launch/R2JcDHqq5H9e7IgE/images/sweeps/tutorial_sweep_runs.png?fit=max&auto=format&n=R2JcDHqq5H9e7IgE&q=85&s=e274f58b88b27f8b51215e36cfaeb315" alt="runからsweepを初期化" width="1786" height="1086" data-path="images/sweeps/tutorial_sweep_runs.png" />
</Frame>

<Note>
  新しいsweepをベイズsweepとして開始すると、選択したrunはガウス過程の初期化にも使用されます。
</Note>
