Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-john-wbdocs-2044-rename-serverless-products.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
W&B は、2 つの軽量なインテグレーションを通じて Ray と統合できます。
WandbLoggerCallback 関数は、Tune に報告されたメトリクスを自動的に Wandb API にログします。
- 関数 API と併用できる
setup_wandb() 関数は、Tune のトレーニング情報を使って Wandb API を自動的に初期化します。その後は、通常どおり Wandb API を使用できます。たとえば、run.log() を使ってトレーニングプロセスをログできます。
from ray.air.integrations.wandb import WandbLoggerCallback
Wandb の設定は、tune.run() の config パラメーターに wandb キーを渡して行います (以下の例を参照) 。
wandb の config エントリの内容は、キーワード引数として wandb.init() に渡されます。例外として、以下の設定は WandbLoggerCallback 自体の設定に使用されます。
project (str): Wandbプロジェクトの名。必須です。
api_key_file (str): Wandb APIキーを含むファイルへのパス。
api_key (str): Wandb APIキー。api_key_file を設定する代わりに使用します。
excludes (list): ログから除外するメトリクスのリスト。
log_config (bool): 結果の辞書の config パラメーターをログするかどうか。デフォルトは False です。
upload_checkpoints (bool): True の場合、モデル チェックポイントがArtifactsとしてアップロードされます。デフォルトは False です。
from ray import tune, train
from ray.air.integrations.wandb import WandbLoggerCallback
def train_fc(config):
for i in range(10):
train.report({"mean_accuracy": (i + config["alpha"]) / 10})
tuner = tune.Tuner(
train_fc,
param_space={
"alpha": tune.grid_search([0.1, 0.2, 0.3]),
"beta": tune.uniform(0.5, 1.0),
},
run_config=train.RunConfig(
callbacks=[
WandbLoggerCallback(
project="<your-project>", api_key="<your-api-key>", log_config=True
)
]
),
)
results = tuner.fit()
from ray.air.integrations.wandb import setup_wandb
このユーティリティ関数は、Ray Tune で Wandb を使用する際の初期化に役立ちます。基本的な使い方としては、トレーニング関数内で setup_wandb() を呼び出します。
from ray.air.integrations.wandb import setup_wandb
def train_fn(config):
# wandbを初期化する
wandb = setup_wandb(config)
run = wandb.init(
project=config["wandb"]["project"],
api_key_file=config["wandb"]["api_key_file"],
)
for i in range(10):
loss = config["a"] + config["b"]
run.log({"loss": loss})
tune.report(loss=loss)
run.finish()
tuner = tune.Tuner(
train_fn,
param_space={
# 探索空間をここで定義する
"a": tune.choice([1, 2, 3]),
"b": tune.choice([4, 5, 6]),
# wandbの設定
"wandb": {"project": "Optimization_Project", "api_key_file": "/path/to/file"},
},
)
results = tuner.fit()
インテグレーションの動作を確認できるよう、いくつかの例を用意しています。
- Colab: インテグレーションを試せるシンプルなデモです。
- ダッシュボード: この例から生成されたダッシュボードを確認できます。