> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-sdk-add-methods-properties.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Run methods

## <Badge color="yellow" size="lg" shape="rounded">Class</Badge> wandb.Run

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.alert()

Create an alert with the given title and text.

```python theme={null}
self,
title: 'str',
text: 'str',
level: 'str | AlertLevel | None' = None,
wait_duration: 'int | float | timedelta | None' = None
```

##### Arguments

<ResponseField name="title" type="str">
  The title of the alert, must be less than 64 characters long.
</ResponseField>

<ResponseField name="text" type="str">
  The text body of the alert.
</ResponseField>

<ResponseField name="level" type="str | AlertLevel | None">
  The alert level to use, either: `INFO`, `WARN`, or `ERROR`.
</ResponseField>

<ResponseField name="wait_duration" type="int | float | timedelta | None">
  The time to wait (in seconds) before sending another alert with this title.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.define\_metric()

Customize metrics logged with `wandb.Run.log()`.

```python theme={null}
self,
name: 'str',
step_metric: 'str | wandb_metric.Metric | None' = None,
step_sync: 'bool | None' = None,
hidden: 'bool | None' = None,
summary: 'str | None' = None,
goal: 'str | None' = None,
overwrite: 'bool | None' = None
```

##### Arguments

<ResponseField name="name" type="str">
  The name of the metric to customize.
</ResponseField>

<ResponseField name="step_metric" type="str | wandb_metric.Metric | None">
  The name of another metric to serve as the X-axis for this metric in automatically generated charts.
</ResponseField>

<ResponseField name="step_sync" type="bool | None">
  Automatically insert the last value of step\_metric into `wandb.Run.log()` if it is not provided explicitly. Defaults to True if step\_metric is specified.
</ResponseField>

<ResponseField name="hidden" type="bool | None">
  Hide this metric from automatic plots.
</ResponseField>

<ResponseField name="summary" type="str | None">
  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.
</ResponseField>

<ResponseField name="goal" type="str | None">
  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.
</ResponseField>

<ResponseField name="overwrite" type="bool | None">
  If false, then this call is merged with previous `define_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.
</ResponseField>

##### Returns

An object that represents this call but can otherwise be discarded.

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.display()

Display this run in Jupyter.

```python theme={null}
self,
height: 'int' = 420,
hidden: 'bool' = False
```

##### Arguments

<ResponseField name="height" type="int" />

<ResponseField name="hidden" type="bool" />

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.finish()

Finish a run and upload any remaining data.

Marks the completion of a W\&B run and ensures all data is synced to the server.
The run's final state is determined by its exit conditions and sync status.

Run States:

* 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.

```python theme={null}
self,
exit_code: 'int | None' = None,
quiet: 'bool | None' = None
```

##### Arguments

<ResponseField name="exit_code" type="int | None">
  Integer indicating the run's exit status. Use 0 for success, any other value marks the run as failed.
</ResponseField>

<ResponseField name="quiet" type="bool | None">
  Deprecated. Configure logging verbosity using `wandb.Settings(quiet=...)`.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.finish\_artifact()

Finishes a non-finalized artifact as output of a run.

Subsequent "upserts" with the same distributed ID will result in a new version.

```python theme={null}
self,
artifact_or_path: 'Artifact | str',
name: 'str | None' = None,
type: 'str | None' = None,
aliases: 'list[str] | None' = None,
distributed_id: 'str | None' = None
```

##### Arguments

<ResponseField name="artifact_or_path" type="Artifact | str">
  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 calling
    `wandb.Artifact`.
</ResponseField>

<ResponseField name="name" type="str | None">
  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.
</ResponseField>

<ResponseField name="type" type="str | None">
  The type of artifact to log, examples include `dataset`, `model`
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  Aliases to apply to this artifact, defaults to `["latest"]`
</ResponseField>

<ResponseField name="distributed_id" type="str | None">
  Unique string that all distributed jobs share. If None, defaults to the run's group name.
</ResponseField>

##### Returns

An `Artifact` object.

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.link\_artifact()

Link the artifact to a collection.

The term “link” refers to pointers that connect where W\&B stores the
artifact and where the artifact is accessible in the registry. W\&B
does not duplicate artifacts when you link an artifact to a collection.

View linked artifacts in the Registry UI for the specified collection.

```python theme={null}
self,
artifact: 'Artifact',
target_path: 'str',
aliases: 'list[str] | None' = None
```

##### Arguments

<ResponseField name="artifact" type="Artifact">
  The artifact object to link to the collection.
</ResponseField>

<ResponseField name="target_path" type="str">
  The path of the collection. Path consists of the prefix "wandb-registry-" along with the registry name and the collection name `wandb-registry-{REGISTRY_NAME}/{COLLECTION_NAME}`.
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  Add one or more aliases to the linked artifact. The "latest" alias is automatically applied to the most recent artifact you link.
</ResponseField>

##### Returns

The linked artifact.

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.link\_model()

Log a model artifact version and link it to a registered model in the model registry.

Linked model versions are visible in the UI for the specified registered model.

This method will:

* 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.

```python theme={null}
self,
path: 'StrPath',
registered_model_name: 'str',
name: 'str | None' = None,
aliases: 'list[str] | None' = None
```

##### Arguments

<ResponseField name="path" type="StrPath">
  (str) A path to the contents of this model, can be in the
  following forms:

  * `/local/directory`
  * `/local/directory/file.txt`
  * `s3://bucket/path`
</ResponseField>

<ResponseField name="registered_model_name" type="str">
  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.
</ResponseField>

<ResponseField name="name" type="str | None">
  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.
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  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.
</ResponseField>

##### Returns

The linked artifact if linking was successful, otherwise `None`.

##### Raises

<ResponseField name="AssertionError">
  If registered\_model\_name is a path or if model artifact 'name' is of a type that does not contain the substring 'model'.
</ResponseField>

<ResponseField name="ValueError">
  If name has invalid special characters.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.log()

Upload run data.

Use `log` to log data from runs, such as scalars, images, video,
histograms, plots, and tables. See [Log objects and media](https://docs.wandb.ai/models/track/log) for
code snippets, best practices, and more.

Basic usage:

```python theme={null}
import wandb

with wandb.init() as run:
    run.log({"train-loss": 0.5, "accuracy": 0.9})
```

The previous code snippet saves the loss and accuracy to the run's
history and updates the summary values for these metrics.

Visualize logged data in a workspace at [wandb.ai](https://wandb.ai),
or locally on a [self-hosted instance](https://docs.wandb.ai/platform/hosting)
of the W\&B app, or export data to visualize and explore locally, such as in a
Jupyter notebook, with the [Public API](https://docs.wandb.ai/models/track/public-api-guide).

Logged values don't have to be scalars. You can log any
[W\&B supported Data Type](https://docs.wandb.ai/models/ref/python/data-types)
such as images, audio, video, and more. For example, you can use
`wandb.Table` to log structured data. See
[Log tables, visualize and query data](https://docs.wandb.ai/models/tables/tables-walkthrough)
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":

```python theme={null}
with wandb.init() as run:
    # Log metrics in the "train" section.
    run.log(
        {
            "train/accuracy": 0.9,
            "train/loss": 30,
            "validate/accuracy": 0.8,
            "validate/loss": 20,
        }
    )
```

Only one level of nesting is supported; `run.log({"a/b/c": 1})`
produces a section named "a".

`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](https://docs.wandb.ai/models/track/log/customize-logging-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.

```python theme={null}
with wandb.init() as run:
    # Example: log an "epoch" metric for use as an X axis.
    run.log({"epoch": 40, "train-loss": 0.5})
```

It is possible to use multiple `wandb.Run.log()` invocations to log to
the same step with the `step` and `commit` parameters.
The following are all equivalent:

```python theme={null}
with wandb.init() as run:
    # Normal usage:
    run.log({"train-loss": 0.5, "accuracy": 0.8})
    run.log({"train-loss": 0.4, "accuracy": 0.9})

    # Implicit step without auto-incrementing:
    run.log({"train-loss": 0.5}, commit=False)
    run.log({"accuracy": 0.8})
    run.log({"train-loss": 0.4}, commit=False)
    run.log({"accuracy": 0.9})

    # Explicit step:
    run.log({"train-loss": 0.5}, step=current_step)
    run.log({"accuracy": 0.8}, step=current_step)
    current_step += 1
    run.log({"train-loss": 0.4}, step=current_step)
    run.log({"accuracy": 0.9}, step=current_step, commit=True)
```

```python theme={null}
self,
data: 'dict[str, Any]',
step: 'int | None' = None,
commit: 'bool | None' = None
```

##### Arguments

<ResponseField name="data" type="dict[str, Any]">
  A `dict` with `str` keys and values that are serializable Python objects including: `int`, `float` and `string`; any of the `wandb.data_types`; lists, tuples and NumPy arrays of serializable Python objects; other `dict`s of this structure.
</ResponseField>

<ResponseField name="step" type="int | None">
  The step number to log. If `None`, then an implicit auto-incrementing step is used. See the notes in the description.
</ResponseField>

<ResponseField name="commit" type="bool | None">
  If true, finalize and upload the step. If false, then accumulate data for the step. See the notes in the description. If `step` is `None`, then the default is `commit=True`; otherwise, the default is `commit=False`.
</ResponseField>

##### Raises

<ResponseField name="wandb.Error">
  If called before `wandb.init()`.
</ResponseField>

<ResponseField name="ValueError">
  If invalid data is passed.
</ResponseField>

##### Examples

For more and more detailed examples, see
[our guides to logging](https://docs.wandb.ai/models/track/log).

Basic usage

```python theme={null}
import wandb

with wandb.init() as run:
    run.log({"train-loss": 0.5, "accuracy": 0.9
```

Incremental logging

```python theme={null}
import wandb

with wandb.init() as run:
    run.log({"loss": 0.2}, commit=False)
    # Somewhere else when I'm ready to report this step:
    run.log({"accuracy": 0.8})
```

Histogram

```python theme={null}
import numpy as np
import wandb

# sample gradients at random from normal distribution
gradients = np.random.randn(100, 100)
with wandb.init() as run:
    run.log({"gradients": wandb.Histogram(gradients)})
```

Image from NumPy

```python theme={null}
import numpy as np
import wandb

with wandb.init() as run:
    examples = []
    for i in range(3):
        pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
        image = wandb.Image(pixels, caption=f"random field {i}")
        examples.append(image)
    run.log({"examples": examples})
```

Image from PIL

```python theme={null}
import numpy as np
from PIL import Image as PILImage
import wandb

with wandb.init() as run:
    examples = []
    for i in range(3):
        pixels = np.random.randint(
            low=0,
            high=256,
            size=(100, 100, 3),
            dtype=np.uint8,
        )
        pil_image = PILImage.fromarray(pixels, mode="RGB")
        image = wandb.Image(pil_image, caption=f"random field {i}")
        examples.append(image)
    run.log({"examples": examples})
```

Video from NumPy

```python theme={null}
import numpy as np
import wandb

with wandb.init() as run:
    # axes are (time, channel, height, width)
    frames = np.random.randint(
        low=0,
        high=256,
        size=(10, 3, 100, 100),
        dtype=np.uint8,
    )
    run.log({"video": wandb.Video(frames, fps=4)})
```

Matplotlib plot

```python theme={null}
from matplotlib import pyplot as plt
import numpy as np
import wandb

with wandb.init() as run:
    fig, ax = plt.subplots()
    x = np.linspace(0, 10)
    y = x * x
    ax.plot(x, y)  # plot y = x^2
    run.log({"chart": fig})
```

PR Curve

```python theme={null}
import wandb

with wandb.init() as run:
    run.log({"pr": wandb.plot.pr_curve(y_test, y_probas, labels)})
```

3D Object

```python theme={null}
import wandb

with wandb.init() as run:
    run.log(
        {
            "generated_samples": [
                wandb.Object3D(open("sample.obj")),
                wandb.Object3D(open("sample.gltf")),
                wandb.Object3D(open("sample.glb")),
            ]
        }
    )
```

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.log\_artifact()

Declare an artifact as an output of a run.

```python theme={null}
self,
artifact_or_path: 'Artifact | StrPath',
name: 'str | None' = None,
type: 'str | None' = None,
aliases: 'list[str] | None' = None,
tags: 'list[str] | None' = None
```

##### Arguments

<ResponseField name="artifact_or_path" type="Artifact | StrPath">
  (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 calling
    `wandb.Artifact`.
</ResponseField>

<ResponseField name="name" type="str | None">
  (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.
</ResponseField>

<ResponseField name="type" type="str | None">
  (str) The type of artifact to log, examples include `dataset`, `model`
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  (list, optional) Aliases to apply to this artifact, defaults to `["latest"]`
</ResponseField>

<ResponseField name="tags" type="list[str] | None">
  (list, optional) Tags to apply to this artifact, if any.
</ResponseField>

##### Returns

An `Artifact` object.

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.log\_code()

Save 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`.

```python theme={null}
self,
root: 'str | None' = '.',
name: 'str | None' = None,
include_fn: 'Callable[[str, str], bool] | Callable[[str], bool]' = _is_py_requirements_or_dockerfile,
exclude_fn: 'Callable[[str, str], bool] | Callable[[str], bool]' = exclude_wandb_fn
```

##### Arguments

<ResponseField name="root" type="str | None">
  The relative (to `os.getcwd()`) or absolute path to recursively find code from.
</ResponseField>

<ResponseField name="name" type="str | None">
  (str, optional) The name of our code artifact. By default, we'll name the artifact `source-$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.
</ResponseField>

<ResponseField name="include_fn" type="Callable[[str, str], bool] | Callable[[str], bool]">
  A callable that accepts a file path and (optionally) root path and returns True when it should be included and False otherwise. This defaults to `lambda path, root: path.endswith(".py")`.
</ResponseField>

<ResponseField name="exclude_fn" type="Callable[[str, str], bool] | Callable[[str], bool]">
  A callable that accepts a file path and (optionally) root path and returns `True` when it should be excluded and `False` otherwise. This defaults to a function that excludes all files within `<root>/.wandb/` and `<root>/wandb/` directories.
</ResponseField>

##### Returns

An `Artifact` object if code was logged

##### Examples

Basic usage

```python theme={null}
import wandb

with wandb.init() as run:
    run.log_code()
```

Advanced usage

```python theme={null}
import wandb

with wandb.init() as run:
    run.log_code(
        root="../",
        include_fn=lambda path: path.endswith(".py") or path.endswith(".ipynb"),
        exclude_fn=lambda path, root: os.path.relpath(path, root).startswith(
            "cache/"
        ),
    )
```

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.log\_model()

Logs a model artifact containing the contents inside the 'path' to a run and marks it as an output to this run.

The name of model artifact can only contain alphanumeric characters,
underscores, and hyphens.

```python theme={null}
self,
path: 'StrPath',
name: 'str | None' = None,
aliases: 'list[str] | None' = None
```

##### Arguments

<ResponseField name="path" type="StrPath">
  (str) A path to the contents of this model,
  can be in the following forms:

  * `/local/directory`
  * `/local/directory/file.txt`
  * `s3://bucket/path`
</ResponseField>

<ResponseField name="name" type="str | None">
  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.
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  Aliases to apply to the created model artifact, defaults to `["latest"]`
</ResponseField>

##### Returns

None

##### Raises

<ResponseField name="ValueError">
  If name has invalid special characters.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.mark\_preempting()

Mark this run as preempting.

Also tells the internal process to immediately report this to server.

```python theme={null}
self
```

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.pin\_config\_keys()

Pin config keys to display in the References section on Run Overview.

Pinned keys appear prominently above Notes on the Run Overview page.
String values are rendered as markdown; non-strings are rendered as
plain text. Calling this again replaces the previously pinned list.

```python theme={null}
self,
keys: 'Sequence[str]' = ()
```

##### Arguments

<ResponseField name="keys" type="Sequence[str]">
  Config key names to pin, matching keys set via `run.config`. These are exact key strings (dots and slashes are treated literally, not as path separators). Order is preserved and determines display order.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.restore()

Download the specified file from cloud storage.

File is placed into the current directory or run directory.
By default, will only download the file if it doesn't already exist.

```python theme={null}
self,
name: 'str',
run_path: 'str | None' = None,
replace: 'bool' = False,
root: 'str | None' = None
```

##### Arguments

<ResponseField name="name" type="str">
  The name of the file.
</ResponseField>

<ResponseField name="run_path" type="str | None">
  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.
</ResponseField>

<ResponseField name="replace" type="bool">
  Whether to download the file even if it already exists locally
</ResponseField>

<ResponseField name="root" type="str | None">
  The directory to download the file to.  Defaults to the current directory or the run directory if wandb.init was called.
</ResponseField>

##### Returns

None if it can't find the file, otherwise a file object open for reading.

##### Raises

<ResponseField name="CommError">
  If W\&B can't connect to the W\&B backend.
</ResponseField>

<ResponseField name="ValueError">
  If the file is not found or can't find run\_path.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.save()

Sync one or more files to W\&B.

Relative paths are relative to the current working directory.

A Unix glob, such as "myfiles/\*", is expanded at the time `save` is
called regardless of the `policy`. In particular, new files are not
picked up automatically.

`glob_str` is expanded using Python's `glob` module: see
[https://docs.python.org/3/library/glob.html](https://docs.python.org/3/library/glob.html) for the exact syntax and
behavior. Notably, the characters `*`, `?`, and `[]` are treated as
glob metacharacters, not literal characters, even if they appear in a
real filename (e.g. "myfile\[1].txt"). If your file's name contains
any of these characters and you want to match it literally rather
than as a pattern, either escape it yourself with `glob.escape()`
before calling `save`, or pass `glob=False` to disable pattern
expansion entirely and treat `glob_str` as a literal path.

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.

Files are automatically deduplicated: calling `save()` multiple times
on the same file without modifications will not re-upload it.

```python theme={null}
self,
glob_str: 'str | os.PathLike',
base_path: 'str | os.PathLike | None' = None,
policy: 'PolicyName' = 'live',
glob: 'bool' = True
```

##### Arguments

<ResponseField name="glob_str" type="str | os.PathLike">
  A relative or absolute path or Unix glob.
</ResponseField>

<ResponseField name="base_path" type="str | os.PathLike | None">
  A path to use to infer a directory structure; see examples.
</ResponseField>

<ResponseField name="policy" type="PolicyName">
  One of `live`, `now`, or `end`.

  * live: upload the file as it changes, overwriting the previous version
  * now: upload the file once now
  * end: upload file when the run ends
</ResponseField>

<ResponseField name="glob" type="bool">
  Whether to treat `glob_str` as a glob pattern. Defaults to `True` for backward compatibility. Set to `False` to treat `glob_str` as a literal path, e.g. when its name contains glob metacharacters like `[`, `]`, `*`, or `?` that you don't want interpreted as a pattern.
</ResponseField>

##### Returns

Paths to the symlinks created for the matched files. For historical reasons, this may return a boolean in legacy code. `python import wandb run = wandb.init() run.save("these/are/myfiles/*") # => Saves files in a "these/are/myfiles/" folder in the run. run.save("these/are/myfiles/*", base_path="these") # => Saves files in an "are/myfiles/" folder in the run. run.save("/Users/username/Documents/run123/*.txt") # => Saves files in a "run123/" folder in the run. See note below. run.save("/Users/username/Documents/run123/*.txt", base_path="/Users") # => Saves files in a "username/Documents/run123/" folder in the run. run.save("files/*/saveme.txt") # => Saves each "saveme.txt" file in an appropriate subdirectory #    of "files/". run.save("files/myfile[1].txt", glob=False) # => Saves the literal file "files/myfile[1].txt" without #    interpreting "[1]" as a glob character class. # Explicitly finish the run since a context manager is not used. run.finish() `

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.status()

Get sync info from the internal backend, about the current run's sync status.

```python theme={null}
self
```

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.unwatch()

Remove pytorch model topology, gradient and parameter hooks.

```python theme={null}
self,
models: 'torch.nn.Module | Sequence[torch.nn.Module] | None' = None
```

##### Arguments

<ResponseField name="models" type="torch.nn.Module | Sequence[torch.nn.Module] | None">
  Optional list of pytorch models that have had watch called on them.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.upsert\_artifact()

Declare (or append to) 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.

```python theme={null}
self,
artifact_or_path: 'Artifact | str',
name: 'str | None' = None,
type: 'str | None' = None,
aliases: 'list[str] | None' = None,
distributed_id: 'str | None' = None
```

##### Arguments

<ResponseField name="artifact_or_path" type="Artifact | str">
  A path to the contents of this artifact,
  can be in the following forms:

  * `/local/directory`
  * `/local/directory/file.txt`
  * `s3://bucket/path`
</ResponseField>

<ResponseField name="name" type="str | None">
  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
</ResponseField>

<ResponseField name="type" type="str | None">
  The type of artifact to log. Common examples include `dataset`, `model`.
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  Aliases to apply to this artifact, defaults to `["latest"]`.
</ResponseField>

<ResponseField name="distributed_id" type="str | None">
  Unique string that all distributed jobs share. If None, defaults to the run's group name.
</ResponseField>

##### Returns

An `Artifact` object.

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.use\_artifact()

Declare an artifact as an input to a run.

Call `download` or `file` on the returned object to get the contents locally.

```python theme={null}
self,
artifact_or_name: 'str | Artifact',
type: 'str | None' = None,
aliases: 'list[str] | None' = None,
use_as: 'str | None' = None
```

##### Arguments

<ResponseField name="artifact_or_name" type="str | Artifact">
  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
</ResponseField>

<ResponseField name="type" type="str | None">
  The type of artifact to use.
</ResponseField>

<ResponseField name="aliases" type="list[str] | None">
  Aliases to apply to this artifact
</ResponseField>

<ResponseField name="use_as" type="str | None">
  This argument is deprecated and does nothing.
</ResponseField>

##### Returns

An `Artifact` object.

##### Examples

```python theme={null}
import wandb

run = wandb.init(project="<example>")

# Use an artifact by name and alias
artifact_a = run.use_artifact(artifact_or_name="<name>:<alias>")

# Use an artifact by name and version
artifact_b = run.use_artifact(artifact_or_name="<name>:v<version>")

# Use an artifact by entity/project/name:alias
artifact_c = run.use_artifact(
    artifact_or_name="<entity>/<project>/<name>:<alias>"
)

# Use an artifact by entity/project/name:version
artifact_d = run.use_artifact(
    artifact_or_name="<entity>/<project>/<name>:v<version>"
)

# Explicitly finish the run since a context manager is not used.
run.finish()
```

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.use\_model()

Download the files logged in a model artifact 'name'.

```python theme={null}
self,
name: 'str'
```

##### Arguments

<ResponseField name="name" type="str">
  A model artifact name. 'name' must match the name of an existing logged
  model artifact. May be prefixed with `entity/project/`. Valid names
  can be in the following forms

  * model\_artifact\_name:version
  * model\_artifact\_name:alias
</ResponseField>

##### Returns

`path`: Path to downloaded model artifact file(s).

##### Raises

<ResponseField name="AssertionError">
  If model artifact 'name' is of a type that does not contain the substring 'model'.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.watch()

Hook into given PyTorch model to monitor gradients and the model's computational graph.

This function can track parameters, gradients, or both during training.

```python theme={null}
self,
models: 'torch.nn.Module | Sequence[torch.nn.Module]',
criterion: 'torch.F | None' = None,
log: "Literal['gradients', 'parameters', 'all'] | None" = 'gradients',
log_freq: 'int' = 1000,
idx: 'int | None' = None,
log_graph: 'bool' = False
```

##### Arguments

<ResponseField name="models" type="torch.nn.Module | Sequence[torch.nn.Module]">
  A single model or a sequence of models to be monitored.
</ResponseField>

<ResponseField name="criterion" type="torch.F | None">
  The loss function being optimized (optional).
</ResponseField>

<ResponseField name="log" type="Literal['gradients', 'parameters', 'all'] | None">
  Specifies whether to log "gradients", "parameters", or "all". Set to None to disable logging. (default="gradients").
</ResponseField>

<ResponseField name="log_freq" type="int">
  Frequency (in batches) to log gradients and parameters. (default=1000)
</ResponseField>

<ResponseField name="idx" type="int | None">
  Index used when tracking multiple models with `wandb.watch`. (default=None)
</ResponseField>

<ResponseField name="log_graph" type="bool">
  Whether to log the model's computational graph. (default=False)
</ResponseField>

##### Raises

<ResponseField name="ValueError">
  If `wandb.init()` has not been called or if any of the models are not instances of `torch.nn.Module`.
</ResponseField>

## <Badge color="blue" size="lg" shape="rounded">method</Badge> Run.write\_logs()

Write text to the run's Logs tab.

Use `write_logs` to directly write text to the Logs tab instead of
relying on automatic stdout/stderr capture. Calls after the run has
finished are silently ignored.

Consider using the `capture_loggers` setting which integrates with
Python's `logging` module.

```python theme={null}
self,
text: 'str'
```

##### Arguments

<ResponseField name="text" type="str">
  The text to write. A trailing newline is added if not present.
</ResponseField>
