class Run
A unit of computation logged by W&B. Typically, this is an ML experiment.
Call wandb.init()
to create a new run. wandb.init()
starts a new run and returns a wandb.Run
object. Each run is associated with a unique ID (run ID). W&B recommends using a context (with
statement) manager to automatically finish the run.
For distributed training experiments, you can either track each process separately using one run per process or track all processes to a single run. See Log distributed training experiments for more information.
You can log data to a run with wandb.Run.log()
. Anything you log using wandb.Run.log()
is sent to that run. See Create an experiment or wandb.init
API reference page or more information.
There is a another Run
object in the wandb.apis.public
namespace. Use this object is to interact with runs that have already been created.
Attributes:
summary
: (Summary) A summary of the run, which is a dictionary-like object. For more information, see[Log summary metrics](https
: //docs.wandb.ai/models/track/log/log-summary/).
wandb.init()
:
property Run.config
Config object associated with this run. Returns:wandb_config.Config
: The config property value.
property Run.config_static
Static config object associated with this run. Returns:wandb_config.ConfigStatic
: The config_static property value.
property Run.dir
The directory where files associated with the run are saved. Returns:str
: The dir property value.
property Run.disabled
True if the run is disabled, False otherwise. Returns:bool
: The disabled property value.
property Run.entity
The name of the W&B entity associated with the run. Entity can be a username or the name of a team or organization. Returns:str
: The entity property value.
property Run.group
Returns the name of the group associated with this run. Grouping runs together allows related experiments to be organized and visualized collectively in the W&B UI. This is especially useful for scenarios such as distributed training or cross-validation, where multiple runs should be viewed and managed as a unified experiment. In shared mode, where all processes share the same run object, setting a group is usually unnecessary, since there is only one run and no grouping is required. Returns:str
: The group property value.
property Run.id
Identifier for this run. Returns:str
: The id property value.
property Run.job_type
Name of the job type associated with the run. View a run’s job type in the run’s Overview page in the W&B App. You can use this to categorize runs by their job type, such as “training”, “evaluation”, or “inference”. This is useful for organizing and filtering runs in the W&B UI, especially when you have multiple runs with different job types in the same project. For more information, see Organize runs. Returns:str
: The job_type property value.
property Run.name
Display name of the run. Display names are not guaranteed to be unique and may be descriptive. By default, they are randomly generated. Returns:str | None
: The name property value.
property Run.notes
Notes associated with the run, if there are any. Notes can be a multiline string and can also use markdown and latex equations inside$$
, like $x + 3$
.
Returns:
str | None
: The notes property value.
property Run.offline
True if the run is offline, False otherwise. Returns:bool
: The offline property value.
property Run.path
Path to the run. Run paths include entity, project, and run ID, in the formatentity/project/run_id
.
Returns:
str
: The path property value.
property Run.project
Name of the W&B project associated with the run. Returns:str
: The project property value.
property Run.project_url
URL of the W&B project associated with the run, if there is one. Offline runs do not have a project URL. Returns:str | None
: The project_url property value.
property Run.resumed
True if the run was resumed, False otherwise. Returns:bool
: The resumed property value.
property Run.settings
A frozen copy of run’s Settings object. Returns:Settings
: The settings property value.
property Run.start_time
Unix timestamp (in seconds) of when the run started. Returns:float
: The start_time property value.
property Run.sweep_id
Identifier for the sweep associated with the run, if there is one. Returns:str | None
: The sweep_id property value.
property Run.sweep_url
URL of the sweep associated with the run, if there is one. Offline runs do not have a sweep URL. Returns:str | None
: The sweep_url property value.
property Run.tags
Tags associated with the run, if there are any. Returns:tuple | None
: The tags property value.
property Run.url
The url for the W&B run, if there is one. Offline runs will not have a url. Returns:str | None
: The url property value.
method Run.alert
title
: The title of the alert, must be less than 64 characters long.text
: The text body of the alert.level
: The alert level to use, either:INFO
,WARN
, orERROR
.wait_duration
: The time to wait (in seconds) before sending another alert with this title.
method Run.define_metric
wandb.Run.log()
.
Args:
name
: The name of the metric to customize.step_metric
: The name of another metric to serve as the X-axis for this metric in automatically generated charts.step_sync
: Automatically insert the last value of step_metric intowandb.Run.log()
if it is not provided explicitly. Defaults to True if step_metric is specified.hidden
: Hide this metric from automatic plots.summary
: Specify aggregate metrics added to summary. Supported aggregations include “min”, “max”, “mean”, “last”, “first”, “best”, “copy” and “none”. “none” prevents a summary from being generated. “best” is used together with the goal parameter, “best” is deprecated and should not be used, use “min” or “max” instead. “copy” is deprecated and should not be used.goal
: Specify how to interpret the “best” summary type. Supported options are “minimize” and “maximize”. “goal” is deprecated and should not be used, use “min” or “max” instead.overwrite
: If false, then this call is merged with previousdefine_metric
calls for the same metric by using their values for any unspecified parameters. If true, then unspecified parameters overwrite values specified by previous calls.
method Run.display
method Run.finish
- Running: Active run that is logging data and/or sending heartbeats.
- Crashed: Run that stopped sending heartbeats unexpectedly.
- Finished: Run completed successfully (
exit_code=0
) with all data synced. - Failed: Run completed with errors (
exit_code!=0
). - Killed: Run was forcibly stopped before it could finish.
exit_code
: Integer indicating the run’s exit status. Use 0 for success, any other value marks the run as failed.quiet
: Deprecated. Configure logging verbosity usingwandb.Settings(quiet=...)
.
method Run.finish_artifact
artifact_or_path
: A path to the contents of this artifact, can be in the following forms:/local/directory
/local/directory/file.txt
s3://bucket/path
You can also pass an Artifact object created by callingwandb.Artifact
.
name
: An artifact name. May be prefixed with entity/project. Valid names can be in the following forms:- name:version
- name:alias
- digest This will default to the basename of the path prepended with the current run id if not specified.
type
: The type of artifact to log, examples includedataset
,model
aliases
: Aliases to apply to this artifact, defaults to["latest"]
distributed_id
: Unique string that all distributed jobs share. If None, defaults to the run’s group name.
Artifact
object.
method Run.link_artifact
artifact
: the (public or local) artifact which will be linkedtarget_path
:str
- takes the following forms:{portfolio}
,{project}/{portfolio}
, or{entity}/{project}/{portfolio}
aliases
:List[str]
- optional alias(es) that will only be applied on this linked artifact inside the portfolio. The alias “latest” will always be applied to the latest version of an artifact that is linked.
method Run.link_model
- Check if ‘name’ model artifact has been logged. If so, use the artifact version that matches the files located at ‘path’ or log a new version. Otherwise log files under ‘path’ as a new model artifact, ‘name’ of type ‘model’.
- Check if registered model with name ‘registered_model_name’ exists in the ‘model-registry’ project. If not, create a new registered model with name ‘registered_model_name’.
- Link version of model artifact ‘name’ to registered model, ‘registered_model_name’.
- Attach aliases from ‘aliases’ list to the newly linked model artifact version.
path
: (str) A path to the contents of this model, can be in the following forms:/local/directory
/local/directory/file.txt
s3://bucket/path
registered_model_name
: The name of the registered model that the model is to be linked to. A registered model is a collection of model versions linked to the model registry, typically representing a team’s specific ML Task. The entity that this registered model belongs to will be derived from the run.name
: The name of the model artifact that files in ‘path’ will be logged to. This will default to the basename of the path prepended with the current run id if not specified.aliases
: Aliases that will only be applied on this linked artifact inside the registered model. The alias “latest” will always be applied to the latest version of an artifact that is linked.
AssertionError
: If registered_model_name is a path or if model artifact ‘name’ is of a type that does not contain the substring ‘model’.ValueError
: If name has invalid special characters.
None
.
method Run.log
log
to log data from runs, such as scalars, images, video, histograms, plots, and tables. See Log objects and media for code snippets, best practices, and more.
Basic usage:
wandb.Table
to log structured data. See Log tables, visualize and query data tutorial for more details.
W&B organizes metrics with a forward slash (/
) in their name into sections named using the text before the final slash. For example, the following results in two sections named “train” and “validate”:
run.log({"a/b/c": 1})
produces a section named “a/b”.
run.log()
is not intended to be called more than a few times per second. For optimal performance, limit your logging to once every N iterations, or collect data over multiple iterations and log it in a single step.
By default, each call to log
creates a new “step”. The step must always increase, and it is not possible to log to a previous step. You can use any metric as the X axis in charts. See Custom log axes for more details.
In many cases, it is better to treat the W&B step like you’d treat a timestamp rather than a training step.
wandb.Run.log()
invocations to log to the same step with the step
and commit
parameters. The following are all equivalent:
data
: Adict
withstr
keys and values that are serializablePython objects including
:int
,float
andstring
; any of thewandb.data_types
; lists, tuples and NumPy arrays of serializable Python objects; otherdict
s of this structure.step
: The step number to log. IfNone
, then an implicit auto-incrementing step is used. See the notes in the description.commit
: If true, finalize and upload the step. If false, then accumulate data for the step. See the notes in the description. Ifstep
isNone
, then the default iscommit=True
; otherwise, the default iscommit=False
.
wandb.Error
: If called beforewandb.init()
.ValueError
: If invalid data is passed.
method Run.log_artifact
artifact_or_path
: (str or Artifact) A path to the contents of this artifact, can be in the following forms:/local/directory
/local/directory/file.txt
s3://bucket/path
You can also pass an Artifact object created by callingwandb.Artifact
.
name
: (str, optional) An artifact name. Valid names can be in the following forms:- name:version
- name:alias
- digest This will default to the basename of the path prepended with the current run id if not specified.
type
: (str) The type of artifact to log, examples includedataset
,model
aliases
: (list, optional) Aliases to apply to this artifact, defaults to["latest"]
tags
: (list, optional) Tags to apply to this artifact, if any.
Artifact
object.
method Run.log_code
.py
.
Args:
root
: The relative (toos.getcwd()
) or absolute path to recursively find code from.name
: (str, optional) The name of our code artifact. By default, we’ll name the artifactsource-$PROJECT_ID-$ENTRYPOINT_RELPATH
. There may be scenarios where you want many runs to share the same artifact. Specifying name allows you to achieve that.include_fn
: A callable that accepts a file path and (optionally) root path and returns True when it should be included and False otherwise. Thisdefaults to
lambda path, root: path.endswith(".py")
.exclude_fn
: A callable that accepts a file path and (optionally) root path and returnsTrue
when it should be excluded andFalse
otherwise. This defaults to a function that excludes all files within<root>/.wandb/
and<root>/wandb/
directories.
Artifact
object if code was logged
method Run.log_model
path
: (str) A path to the contents of this model, can be in the following forms:/local/directory
/local/directory/file.txt
s3://bucket/path
name
: A name to assign to the model artifact that the file contents will be added to. This will default to the basename of the path prepended with the current run id if not specified.aliases
: Aliases to apply to the created model artifact, defaults to["latest"]
ValueError
: If name has invalid special characters.
method Run.mark_preempting
method Run.restore
name
: The name of the file.run_path
: Optional path to a run to pull files from, i.e.username/project_name/run_id
if wandb.init has not been called, this is required.replace
: Whether to download the file even if it already exists locallyroot
: The directory to download the file to. Defaults to the current directory or the run directory if wandb.init was called.
CommError
: If W&B can’t connect to the W&B backend.ValueError
: If the file is not found or can’t find run_path.
method Run.save
save
is called regardless of the policy
. In particular, new files are not picked up automatically.
A base_path
may be provided to control the directory structure of uploaded files. It should be a prefix of glob_str
, and the directory structure beneath it is preserved.
When given an absolute path or glob and no base_path
, one directory level is preserved as in the example above.
Args:
glob_str
: A relative or absolute path or Unix glob.base_path
: A path to use to infer a directory structure; see examples.policy
: One oflive
,now
, orend
.- live: upload the file as it changes, overwriting the previous version
- now: upload the file once now
- end: upload file when the run ends
method Run.status
method Run.unwatch
models
: Optional list of pytorch models that have had watch called on them.
method Run.upsert_artifact
artifact_or_path
: A path to the contents of this artifact, can be in the following forms:/local/directory
/local/directory/file.txt
s3://bucket/path
name
: An artifact name. May be prefixed with “entity/project”. Defaults to the basename of the path prepended with the current run ID if not specified. Valid names can be in the following forms:- name:version
- name:alias
- digest
type
: The type of artifact to log. Common examples includedataset
,model
.aliases
: Aliases to apply to this artifact, defaults to["latest"]
.distributed_id
: Unique string that all distributed jobs share. If None, defaults to the run’s group name.
Artifact
object.
method Run.use_artifact
download
or file
on the returned object to get the contents locally.
Args:
artifact_or_name
: The name of the artifact to use. May be prefixed with the name of the project the artifact was logged to (“<entity>
” or “<entity>/<project>
”). If no entity is specified in the name, the Run or API setting’s entity is used. Valid names can be in the following forms- name:version
- name:alias
type
: The type of artifact to use.aliases
: Aliases to apply to this artifactuse_as
: This argument is deprecated and does nothing.
Artifact
object.
Examples:
method Run.use_model
name
: A model artifact name. ‘name’ must match the name of an existing logged model artifact. May be prefixed withentity/project/
. Valid names can be in the following forms- model_artifact_name:version
- model_artifact_name:alias
path
(str): Path to downloaded model artifact file(s).
AssertionError
: If model artifact ‘name’ is of a type that does not contain the substring ‘model’.
method Run.watch
models
: A single model or a sequence of models to be monitored.criterion
: The loss function being optimized (optional).log
: Specifies whether to log “gradients”, “parameters”, or “all”. Set to None to disable logging. (default=“gradients”).log_freq
: Frequency (in batches) to log gradients and parameters. (default=1000)idx
: Index used when tracking multiple models withwandb.watch
. (default=None)log_graph
: Whether to log the model’s computational graph. (default=False)
wandb.init()
has not been called or if any of the models are not instances of torch.nn.Module
.