メインコンテンツへスキップ

class Run

entity とプロジェクトに関連付けられた 1 つの run。

method Run.__init__

__init__(
    client: 'RetryingClient',
    entity: 'str',
    project: 'str',
    run_id: 'str',
    attrs: 'Mapping | None' = None,
    include_sweeps: 'bool' = True,
    lazy: 'bool' = True,
    service_api: 'ServiceApi | None' = None
)
引数:
  • client: W&B API クライアント。
  • entity: run に関連付けられた entity。
  • project: run に関連付けられたプロジェクト。
  • run_id: run の一意の識別子。
  • attrs: run の属性。
  • include_sweeps: run に Sweeps を含めるかどうか。
属性:
  • tags ([str]): run に関連付けられたタグのリスト
  • url (str): この run の URL
  • id (str): run の一意の識別子 (デフォルトは 8 文字)
  • name (str): run の名前
  • state (str): 次のいずれか: running, finished, crashed, killed, preempting, preempted
  • config (dict): run に関連付けられたハイパーパラメーターの dict
  • created_at (str): run が開始された日時を示す ISO Timestamp
  • system_metrics (dict): run に対して記録された最新のシステムメトリクス
  • summary (dict): 現在の summary を保持する、変更可能な dict 風のプロパティ。update を呼び出すと、変更内容が永続化されます。
  • project (str): run に関連付けられたプロジェクト
  • entity (str): run に関連付けられた entity の名前
  • project_internal_id (int): プロジェクトの内部 ID
  • user (str): run を作成したユーザーの名前
  • path (str): 一意の識別子 [entity]/[project]/[run_id]
  • notes (str): run に関するメモ
  • read_only (boolean): run を編集可能かどうか
  • history_keys (str): wandb.Run.log({"key": "value"}) でログされた履歴メトリクスのキー
  • metadata (str): wandb-metadata.json から取得した run のメタデータ
Run オブジェクトを初期化します。 Run は、api が wandb.Api のインスタンスである場合、常に api.runs() を呼び出して初期化されます。

プロパティ Run.config

run の設定を取得します。lazy モードの場合は、完全なデータを自動的に読み込みます。 戻り値:
  • dict[str, Any]: config プロパティの値。

プロパティ Run.entity

run に関連付けられている entity。 戻り値:
  • str: entity プロパティの値。

プロパティ Run.id

run の一意の ID です。 戻り値:
  • str: id プロパティの値。

プロパティ Run.lastHistoryStep

run の履歴にログされた最後の step を返します。 戻り値:
  • int: lastHistoryStep プロパティの値。

property Run.metadata

wandb-metadata.json に含まれる run のメタデータ。 メタデータには、run の説明、tags、開始時刻、メモリ使用量などが含まれます。 戻り値:
  • dict[str, Any] | None: metadata プロパティの値。

プロパティ Run.name

run の名。 戻り値:
  • str | None: name プロパティの値。

プロパティ Run.path

run のパスです。パスは、entity、プロジェクト、run_id を含む list です。 戻り値:
  • list[str]: パスのプロパティ値です。

プロパティ Run.rawconfig

内部キーを含む run 設定の生データを取得します。lazy モードの場合は、完全なデータを自動的に読み込みます。 戻り値:
  • dict[str, Any]: rawconfig プロパティの値。

プロパティ Run.state

run の状態。次のいずれかになります: Finished、Failed、Crashed、または Running。 戻り値:
  • str: 状態を表すプロパティの値。

プロパティ Run.storage_id

run の一意なストレージ識別子。 戻り値:
  • str: storage_id プロパティの値。

プロパティ Run.summary

run の summary メトリクスを取得します。lazy モードの場合、完全なデータを自動的に読み込みます。 戻り値:
  • HTTPSummary: summary のプロパティ値。

プロパティ Run.summary_metrics

run の summary メトリクスを取得します。lazy モードの場合は、全データを自動的に読み込みます。 戻り値:
  • dict[str, Any]: summary_metrics プロパティの値。

プロパティ Run.sweep_name

sweep 名を取得します。sweepName は lightweight fragment に含まれているため、常に利用できます。 戻り値:
  • str | None: sweep_name プロパティの値。

プロパティ Run.system_metrics

run のシステムメトリクスを取得します。lazy モードの場合は、完全なデータを自動的に読み込みます。 戻り値:
  • dict[str, Any]: system_metrics プロパティの値。

プロパティ Run.url

run の URL。 run の URL は、entity、プロジェクト、run_id から生成されます。SaaS ユーザーの場合は、https://wandb.ai/entity/project/run_id の形式になります。 戻り値:
  • str: url プロパティの値。

プロパティ Run.username

この API は非推奨です。代わりに entity を使用してください。 戻り値:
  • str: username のプロパティの値。

method Run.beta_scan_history

beta_scan_history(
    keys: 'list[str] | None' = None,
    page_size: 'int' = 1000,
    min_step: 'int' = 0,
    max_step: 'int | None' = None,
    use_cache: 'bool' = True
) → public.BetaHistoryScan
run のすべての履歴レコードを反復処理できる iterable なコレクションを返します。 この関数は現在も開発中のため、想定どおりに動作しない場合があります。wandb-core を使用して、run からエクスポートされた parquet 形式の履歴をローカルで読み取ります。 引数:
  • keys: run の履歴から読み取るメトリクスのリストです。keys が指定されていない場合は、すべてのメトリクスを返します。
  • page_size: 一度に読み取る履歴レコード数です。
  • min_step: 履歴の読み取りを開始する最小の step (この値を含む) です。
  • max_step: 履歴を読み取る最大の step (この値は含まない) です。
  • use_cache: True に設定すると、WANDB_CACHE_DIR に run の履歴があるか確認します。キャッシュ内に run の履歴が見つからない場合は、サーバーからダウンロードされます。False に設定すると、run の履歴は毎回ダウンロードされます。
戻り値: 履歴レコードを取得するために反復処理できる BetaHistoryScan オブジェクト。

クラスメソッド Run.create

create(
    api: 'public.Api',
    run_id: 'str | None' = None,
    project: 'str | None' = None,
    entity: 'str | None' = None,
    state: "Literal['running', 'pending']" = 'running'
) → Self
指定されたプロジェクトに対して run を作成します。 ほとんどのユースケースでは、wandb.init() を使用してください。wandb.init() のほうが、run の作成と更新をより堅牢に処理できます。wandb.apis.public.Run.create は、スケジュールできない可能性があるジョブ (たとえば、GPU が不足している Kubernetes クラスター内のジョブや、競合が激しいジョブ) に対して “pending” 状態の run を作成する場合など、特定のシナリオ向けです。これらの pending run は、後で再開して W&B でトラッキングできます。 この method で作成された run には機能上の制限があります。この方法で作成した run に対して update() を呼び出しても、期待どおりに動作しない場合があります。 引数:
  • api: W&B API インスタンス。
  • run_id: 省略可能な run ID。指定しない場合は、ランダムな ID が生成されます。
  • project: 省略可能なプロジェクト名。デフォルトは API 設定のプロジェクト、または “uncategorized” です。
  • entity: 省略可能な entity (ユーザーまたはチーム) 名。
  • state: run の初期状態。後で再開する run には “pending”、すぐに実行する場合は “running” を使用します。
戻り値: 作成された run を表す Run object。 例: 後で実行するための pending run を作成する
import wandb

api = wandb.Api()

run_name = "my-pending-run"

run = Run.create(
    api=api,
    project="project",
    entity="entity",
    state="pending",
    run_id=run_name,
)

method Run.delete

delete(delete_artifacts: 'bool' = False) → None
指定されたrunをwandbバックエンドから削除します。 引数:
  • delete_artifacts (bool, 任意): runに関連付けられたartifactも削除するかどうか。

method Run.download_history_exports

download_history_exports(
    download_dir: 'pathlib.Path | str',
    require_complete_history: 'bool' = True
) → runhistory.DownloadHistoryResult
run の parquet 形式の履歴ファイルをすべて、指定したディレクトリにダウンロードします。 引数:
  • download_dir: 履歴ファイルのダウンロード先ディレクトリ。
  • require_complete_history: 完全な履歴のダウンロードを必須にするかどうか。true の場合、run にまだ parquet ファイルへエクスポートされていないデータが含まれていると、IncompleteRunHistoryError が発生します。
戻り値: DownloadHistoryResult。 Raises:
  • IncompleteRunHistoryError: require_complete_history が True で、run にまだ parquet ファイルへエクスポートされていないデータが含まれている場合。
  • WandbApiFailedError: 履歴が不完全な場合以外の理由で API リクエストが失敗した場合。

method Run.file

file(name: 'str') → public.File
artifact 内で、指定した名前のファイルのパスを返します。 引数:
  • name (str): 取得するファイルの名前。
戻り値: name 引数に一致する File

method Run.files

files(
    names: 'list[str] | None' = None,
    pattern: 'str | None' = None,
    per_page: 'int' = 50
) → public.Files
指定した条件に一致する run 内のすべてのファイルに対応する Files オブジェクトを返します。 一致対象として、完全なファイル名のリストまたはパターンを指定できます。両方を指定した場合、パターンは無視されます。 引数:
  • names (list): 取得するファイル名のリスト。空の場合はすべてのファイルを返します
  • pattern (str, optional): W&B からファイルを返す際に使用するマッチングパターンです。このパターンには mySQL の LIKE 構文を使用します。たとえば、.json で終わるすべてのファイルに一致させるには %.json を指定します。namespattern の両方を指定すると、ValueError が発生します。
  • per_page (int): 1 ページあたりの結果数。
戻り値: File オブジェクトを反復するイテレータである Files オブジェクト。

method Run.history

history(
    samples: 'int' = 500,
    keys: 'list[str] | None' = None,
    x_axis: 'str' = '_step',
    pandas: 'bool' = True,
    stream: "Literal['default', 'system']" = 'default'
) → list[dict[str, Any]] | pd.DataFrame
run のサンプリングされた履歴メトリクスを返します。 履歴レコードがサンプリングされていても問題なければ、この方法のほうがシンプルで高速です。 引数:
  • samples : (int, optional) 返すサンプル数
  • pandas : (bool, optional) pandas dataframe を返す
  • keys : (list, optional) 特定のキーのメトリクスのみを返す
  • x_axis : (str, optional) このメトリクスを xAxis として使用します。デフォルトは _step です
  • stream : (str, optional) メトリクスの場合は “default”、マシンメトリクスの場合は “system”
戻り値:
  • pandas.DataFrame: pandas=True の場合、履歴メトリクスを pandas.DataFrame として返します。
  • list of dicts: pandas=False の場合、履歴メトリクスを dict のリストとして返します。

method Run.load

load(force: 'bool' = False) → dict[str, Any]
lazy モードに応じた適切なフラグメントを使用して run データを読み込みます。

method Run.load_full_data

load_full_data(force: 'bool' = False) → dict[str, Any]
設定、systemMetrics、summaryMetrics などの重いフィールドを含む run の完全なデータを読み込みます。 このmethodは、Runs を一覧表示する際に最初に lazy=True を指定したものの、特定の run について完全なデータにアクセスする必要がある場合に便利です。 引数:
  • force: データがすでに読み込まれている場合でも強制的に再読み込みします
戻り値: 読み込まれた run の属性

method Run.log_artifact

log_artifact(
    artifact: 'wandb.Artifact',
    aliases: 'Collection[str] | None' = None,
    tags: 'Collection[str] | None' = None
) → wandb.Artifact
artifact を run の出力として宣言します。 引数:
  • artifact (Artifact): wandb.Api().artifact(name) から返される artifact。
  • aliases (list, optional): この artifact に適用するエイリアス。
  • tags: (list, optional) 必要に応じてこの artifact に適用するタグ。
戻り値: Artifact オブジェクト。

method Run.logged_artifacts

logged_artifacts(per_page: 'int' = 100) → public.RunArtifacts
この run によってログされたすべての artifact を取得します。 run の実行中にログされたすべての出力 artifact を取得します。反復処理することも、1 つのリストにまとめることもできる、ページ分割された結果を返します。 引数:
  • per_page: API リクエストごとに取得する artifact の数。
戻り値: この run の実行中に出力としてログされた、すべての Artifact object を含む反復可能な collection。 例:
import wandb
import tempfile

with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as tmp:
    tmp.write("This is a test artifact")
    tmp_path = tmp.name
run = wandb.init(project="artifact-example")
artifact = wandb.Artifact("test_artifact", type="dataset")
artifact.add_file(tmp_path)
run.log_artifact(artifact)
run.finish()

api = wandb.Api()

finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")

for logged_artifact in finished_run.logged_artifacts():
    print(logged_artifact.name)

method Run.save

save() → None
run オブジェクトへの変更を W&B バックエンドに保存します。

method Run.scan_history

scan_history(
    keys: 'list[str] | None' = None,
    page_size: 'int' = 1000,
    min_step: 'int | None' = None,
    max_step: 'int | None' = None
) → Iterator[dict[str, Any]]
run のすべての履歴レコードを反復可能なコレクションとして返します。 引数:
  • keys ([str], 任意): これらのキーのみを取得し、かつそれらすべてのキーが定義されている行のみを取得します。
  • page_size (int, 任意): API から取得するページサイズ。
  • min_step (int, 任意): 一度にスキャンするページ数の最小値。
  • max_step (int, 任意): 一度にスキャンするページ数の最大値。
戻り値: 履歴レコード (dict) を反復可能なコレクション。 例: サンプル run のすべての損失値をエクスポートします。
run = api.run("entity/project-name/run-id")
history = run.scan_history(keys=["Loss"])
losses = [row["Loss"] for row in history]

method Run.to_html

to_html(height: 'int' = 420, hidden: 'bool' = False) → str
このrunを表示するiframeを含むHTMLを生成します。

method Run.update

update() → None
run オブジェクトへの変更を wandb バックエンドに保存します。

method Run.update_state

update_state(state: "Literal['pending']") → bool
run の状態を更新します。 run の状態を ‘failed’ または ‘crashed’ から ‘pending’ に遷移できます。 引数:
  • state: 遷移先の run の状態です。サポートされるのは "pending" のみです。
戻り値: 状態の更新に成功した場合は True を返します。 Raises:
  • wandb.Error: 要求された状態遷移が許可されていない場合、またはサーバーがこの操作をサポートしていない場合。

method Run.upload_file

upload_file(path: 'str', root: 'str' = '.') → public.File
ローカルファイルを W&B にアップロードし、この run に関連付けます。 引数:
  • path (str): アップロードするファイルのパス。絶対パスまたは相対パスを指定できます。
  • root (str): ファイルの保存先の基準となるルートパス。たとえば、ファイルを run 内で “my_dir/file.txt” として保存し、現在 “my_dir” にいる場合は、root を ”../” に設定します。デフォルトは現在のディレクトリ (”.”) です。
戻り値: アップロードされたファイルを表す File オブジェクト。

method Run.use_artifact

use_artifact(
    artifact: 'wandb.Artifact',
    use_as: 'str | None' = None
) → wandb.Artifact
artifact を run の入力として宣言します。 引数:
  • artifact (Artifact): wandb.Api().artifact(name) が返す artifact
  • use_as (string, optional): スクリプト内で artifact の使用方法を識別する文字列。ベータ版の wandb Launch の artifact スワップ機能を使用する際に、run で使用される artifact を簡単に区別するために使われます。
戻り値: Artifact オブジェクト。

method Run.used_artifacts

used_artifacts(per_page: 'int' = 100) → public.RunArtifacts
この run で明示的に使用された artifact を取得します。 通常は run.use_artifact() を使用して、run 中に使用すると明示的に宣言された入力 artifact のみを取得します。イテレートすることも、1 つの list にまとめることもできる、ページネーションされた結果を返します。 引数:
  • per_page: API リクエストごとに取得する artifact の数。
戻り値: この run で入力として明示的に使用された Artifact オブジェクトの、反復可能なコレクション。 例:
import wandb

run = wandb.init(project="artifact-example")
run.use_artifact("test_artifact:latest")
run.finish()

api = wandb.Api()
finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")
for used_artifact in finished_run.used_artifacts():
    print(used_artifact.name)
test_artifact

method Run.wait_until_finished

wait_until_finished() → None
run が完了するまで、その状態を確認します。