wandb.Run
Last updated
Last updated
A unit of computation logged by wandb. Typically this is an ML experiment.
Create a run with wandb.init()
.
In distributed training, use wandb.init()
to create a run for each process, and set the group argument to organize runs into a larger experiment.
Currently there is a parallel Run object in the wandb.Api. Eventually these two objects will be merged.
Attributes | |
| (History) Time series values, created with |
| (Summary) Single values set for each |
| Returns: (Config): A config object (similar to a nested dict) of key value pairs associated with the hyperparameters of the run. |
| Returns: (str): The directory where all of the files associated with the run are placed. |
| Returns: (str): name of W&B entity associated with run. Entity is either a user name or an organization name. |
| Setting a group helps the W&B UI organize runs in a sensible way. If you are doing a distributed training you should give all of the runs in the training the same group. If you are doing crossvalidation you should give all the crossvalidation folds the same group. |
| id property. |
| For compatibility with |
| Returns: (str): the display name of the run. It does not need to be unique and ideally is descriptive. |
| Returns: (str): notes associated with the run. Notes can be a multiline string and can also use markdown and latex equations inside $$ like $\{x} |
| Returns: (str): the path to the run |
| Returns: (str): name of W&B project associated with run. |
| Returns: (bool): whether or not the run was resumed |
| Returns: (int): the unix time stamp in seconds when the run started |
| Returns: (int): the first step of the run |
| Every time you call wandb.log() it will by default increment the step counter. |
| Returns: (str, optional): the sweep id associated with the run or None |
| Returns: (Tuple[str]): tags associated with the run |
| Returns: (str): name of W&B url associated with run. |
alert
Launch an alert with the given title and text.
Arguments | |
| (str) The title of the alert, must be less than 64 characters long. |
| (str) The text body of the alert. |
| (str or wandb.AlertLevel, optional) The alert level to use, either: |
| (int, float, or timedelta, optional) The time to wait (in seconds) before sending another alert with this title. |
define_metric
Define metric properties which will later be logged with wandb.log()
.
Arguments | |
| Name of the metric. |
| Independent variable associated with the metric. |
| Automatically add |
| Hide this metric from automatic plots. |
| Specify aggregate metrics added to summary. Supported aggregations: "min,max,mean,best,last,none" Default aggregation is |
| Specify direction for optimizing the metric. Supported direections: "minimize,maximize" |
Returns | |
A metric object is returned that can be further specified. |
finish
Marks a run as finished, and finishes uploading all data. This is used when creating multiple runs in the same process. We automatically call this method when your script exits.
finish_artifact
Finish a non-finalized artifact as output of a run. Subsequent "upserts" with the same distributed ID will result in a new version
Arguments | |
| (str or Artifact) A path to the contents of this artifact, can be in the following forms: - |
| (str, optional) 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. |
| (str) The type of artifact to log, examples include |
| (list, optional) Aliases to apply to this artifact, defaults to |
| (string, optional) Unique string that all distributed jobs share. If None, defaults to the run's group name. |
Returns | |
An |
get_project_url
Returns: A url (str, optional) for the W&B project associated with the run or None if the run is offline
get_sweep_url
Returns: A url (str, optional) for the sweep associated with the run or None if there is no associated sweep or the run is offline.
get_url
Returns: A url (str, optional) for the W&B run or None if the run is offline
join
Deprecated alias for finish()
- please use finish
log
Log a dict to the global run's history.
Use wandb.log
to log data from runs, such as scalars, images, video, histograms, and matplotlib plots.
The most basic usage is wandb.log({'train-loss': 0.5, 'accuracy': 0.9})
. This will save a history row associated with the run with train-loss=0.5
and accuracy=0.9
. Visualize logged data in the workspace at wandb.ai, or locally on a self-hosted instance of the W&B app: https://docs.wandb.ai/self-hosted
Export data to explore in a Jupyter notebook, for example, with the API: https://docs.wandb.ai/ref/public-api
Each time you call wandb.log(), this adds a new row to history and updates the summary values for each key logged. In the UI, summary values show up in the run table to compare single values across runs. You might want to update summary manually to set the best value instead of the last value for a given metric. After you finish logging, you can set summary: wandb.run.summary["accuracy"] = 0.9
.
Logged values don't have to be scalars. Logging any wandb object is supported. For example wandb.log({"example": wandb.Image("myimage.jpg")})
will log an example image which will be displayed nicely in the wandb UI. See https://docs.wandb.com/library/reference/data_types for all of the different supported types.
Logging nested metrics is encouraged and is supported in the wandb API, so you could log multiple accuracy values with wandb.log({'dataset-1': {'acc': 0.9, 'loss': 0.3} ,'dataset-2': {'acc': 0.8, 'loss': 0.2}})
and the metrics will be organized in the wandb UI.
W&B keeps track of a global step so logging related metrics together is encouraged, so by default each time wandb.log is called a global step is incremented. If it's inconvenient to log related metrics together calling wandb.log({'train-loss': 0.5, commit=False})
and then wandb.log({'accuracy': 0.9})
is equivalent to calling wandb.log({'train-loss': 0.5, 'accuracy': 0.9})
wandb.log is not intended to be called more than a few times per second. If you want to log more frequently than that it's better to aggregate the data on the client side or you may get degraded performance.
Arguments | |
| (dict, optional) A dict of serializable python objects i.e |
| (boolean, optional) Save the metrics dict to the wandb server and increment the step. If false |
| (integer, optional) The global step in processing. This persists any non-committed earlier steps but defaults to not committing the specified step. |
| (boolean, True) This argument is deprecated and currently doesn't change the behaviour of |
Basic usage
Incremental logging
Histogram
Image
Video
Matplotlib Plot
PR Curve
3D Object
For more examples, see https://docs.wandb.com/library/log
Raises | |
| if called before |
| if invalid data is passed |
log_artifact
Declare an artifact as output of a run.
Arguments | |
| (str or Artifact) A path to the contents of this artifact, can be in the following forms: - |
| (str, optional) 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. |
| (str) The type of artifact to log, examples include |
| (list, optional) Aliases to apply to this artifact, defaults to |
Returns | |
An |
log_code
log_code() saves the current state of your code to a W&B artifact. By default it walks the current directory and logs all files that end with ".py".
Arguments | |
root (str, optional): The relative (to os.getcwd()) or absolute path to recursively find code from. name (str, optional): The name of our code artifact. By default we'll name the artifact "source-$RUN_ID". There may be scenarios where you want many runs to share the same artifact. Specifying name allows you to achieve that. include_fn (callable, optional): A callable that accepts a file path and returns True when it should be included and False otherwise. This defaults to: |
Basic usage
Advanced usage
Returns | |
An |
mark_preempting
Mark this run as preempting and tell the internal process to immediately report this to the server.
plot_table
Creates a custom plot on a table.
Arguments | |
| the name of the spec for the plot |
| the key used to log the data table |
| a wandb.Table object containing the data to be used on the visualization |
| a dict mapping from table keys to fields that the custom visualization needs |
| a dict that provides values for any string constants the custom visualization needs |
project_name
restore
Downloads the specified file from cloud storage into the current directory or run directory. By default this will only download the file if it doesn't already exist.
Arguments | |
| the name of the file |
| optional path to a run to pull files from, i.e. |
| whether to download the file even if it already exists locally |
| the directory to download the file to. Defaults to the current directory or the run directory if wandb.init was called. |
Returns | |
None if it can't find the file, otherwise a file object open for reading |
Raises | |
| if we can't connect to the wandb backend |
| if the file is not found or can't find run_path |
save
Ensure all files matching glob_str
are synced to wandb with the policy specified.
Arguments | |
| (string) a relative or absolute path to a unix glob or regular path. If this isn't specified the method is a noop. |
| (string) the base path to run the glob relative to |
| (string) on of |
upsert_artifact
Declare (or append tp) a non-finalized artifact as output of a run. Note that you must call run.finish_artifact() to finalize the artifact. This is useful when distributed jobs need to all contribute to the same artifact.
Arguments | |
| (str or Artifact) A path to the contents of this artifact, can be in the following forms: - |
| (str, optional) 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. |
| (str) The type of artifact to log, examples include |
| (list, optional) Aliases to apply to this artifact, defaults to |
| (string, optional) Unique string that all distributed jobs share. If None, defaults to the run's group name. |
Returns | |
An |
use_artifact
Declare an artifact as an input to a run, call download
or file
on the returned object to get the contents locally.
Arguments | |
| (str or Artifact) An artifact name. May be prefixed with entity/project. Valid names can be in the following forms: - name:version - name:alias - digest You can also pass an Artifact object created by calling |
| (str, optional) The type of artifact to use. |
| (list, optional) Aliases to apply to this artifact |
Returns | |
An |
watch
__enter__
__exit__