実験を作成する
"""
Create an experiment in W&B. If the project does not exist, W&B creates it.
Note that this file only initializes the experiment; you can add code to log metrics,
artifacts, etc., within the `with` block.
"""
import wandb
# W&B run を初期化します
with wandb.init(project="<project>") as run:
# ここに実験のコードを記述します
pass
既存の run を特定の step からフォークする
"""Fork an existing W&B run from a specific step."""
import wandb
# 後でフォークする run を初期化します
with wandb.init(project="<project>", entity="<entity>") as original_run:
# ここにトレーニングとログ記録のコードを記述します。
pass
# 特定の step から run をフォークします。この例では step 200 からフォークしています。step の数値は必要に応じて変更してください。
with wandb.init(project="<project>",entity="<entity>", fork_from=f"{original_run.id}?_step=200") as forked_run:
# ここにトレーニングとログ記録のコードを記述します。
pass
run を初期化する
"""
Initializes a W&B run.
W&B automatically creates the project if it does not exist. Note that this
file only initializes the experiment; you can add code to log metrics,
artifacts, etc., within the `with` block.
"""
import wandb
# `with` 文を使用してリソース管理を確実に行うことに注意してください。
with wandb.init(project="<project>") as run:
# トレーニングとログを行うコードをここに記述します
pass
run が一時停止、停止、または失敗した場合の再開動作を設定する
"""
Set resume behaviour for a run if it is paused, stops, or fails.
This is useful for long-running experiments that may be interrupted. See
reference documentation for wandb.init(resume=) for a list of all resume options.
"""
import wandb
# 再開時の動作を指定して W&B run を初期化する
with wandb.init(project="<project>", resume="<resume_option>") as run:
# トレーニングとログ記録のコードをここに記述する
pass
run を巻き戻して履歴を変更する
"""
Rewind a run to modify the history of a run.
Specify the run ID and step to rewind to with the `resume_from` parameter in `wandb.init()`.
"""
import wandb
import math
# run を初期化し、いくつかのメトリクスをログします
with wandb.init(project="<project>", entity="<entity>") as run:
# トレーニングとログのコードをここに記述します
pass
run_ID = "<run_id>" # 元の run の run ID に置き換えます
step = int("<step>") # 巻き戻し先のステップを指定します
# 元の run の指定したステップから再開する新しい run を開始します
with wandb.init(project="<project>", entity="<entity>", resume_from=f"{run_ID}?_step={step}") as run:
# トレーニングとログのコードをここに記述します
pass
run に1つ以上のタグを追加する
"""
Add one or more tags to a run.
"""
import wandb
with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
# トレーニングとロギングのコードをここに記述します
pass
run をグループに追加する
"""
Add one or more runs to a group.
Pass the name of your group as an argument to the `group` parameter when you
initialize a run with `wandb.init(group="")`.
"""
import wandb
entity = "<entity>"
project = "<project>"
# 以下のコードは run のグループを 3 つ作成し、各グループに 3 つの run を含めます。
for group in ["<GroupA>", "<GroupB>", "<GroupC>"]: # 任意のグループ名に置き換えてください
# 各グループで 3 つの run を作成する処理をシミュレートします。
for i in range(3):
with wandb.init(entity=entity, project=project, group=group, name=f"{group}_run_{i}") as run:
# トレーニングとログ記録のコードをここに記述します
pass
ジョブのタイプ別に run を整理します
"""
Organize runs by their job type.
Add a job type to a run by passing the `job_type` parameter to `wandb.init(job_type="")`.
"""
import wandb
entity = "<entity>"
project = "<project>"
# run を作成し、ジョブタイプごとに整理します。
for job_type in ["<JobType1>", "<JobType2>"]: # ジョブタイプ名に置き換えてください
# ジョブタイプごとに 2 つの run を作成する処理をシミュレートします。
for i in range(2):
with wandb.init(entity=entity, project=project, job_type=job_type, name=f"{job_type}_run_{i}") as run:
# トレーニングとログ記録のコードをここに記述します
pass
実行中の run に 1 つ以上のタグを追加する
"""
アクティブなrunに1つ以上のタグを追加します。
runオブジェクトの `tags` プロパティはタプルです。既存のrunに新しいタグを追加するには、
既存のタグと新しいタグを含む新しいタプルで `tags` プロパティを更新します。
"""
import wandb
with wandb.init(entity="<entity>", project="<project>", tags=["<tag1>", "<tag2>"]) as run:
# トレーニングとログするコードはここに記述します
# 既存のタグに新しいタグを追加するには、既存のタグと新しいタグを含む新しいタプルを作成します。
run.tags += ("<tag3>",)
保存済みの run に 1 つ以上のタグを追加する
"""
Add one or more tags to previously saved runs.
Use the Public API to update tags on stored data after the run has finished or
when you are working outside the run process. This is useful when you need to
organize or categorize runs retroactively.
To add a new tag to a run, update the `tags` property with a new list that
includes the existing tags and the new tags. The run's path consists of
`entity/project/run_id`. After updating the tags, you must call the run's
`update()` method to save the changes.
"""
import wandb
entity = "<entity>"
project = "<project>"
run_id = "<run-id>" # 更新対象の run の ID に置き換えてください
# パスは entity/project/run_id の形式です
with wandb.Api().run(f"{entity}/{project}/{run_id}") as run:
run.tags.append("<tag>")
run.update()