diff --git a/content/en/ref/cli/_index.md b/content/en/ref/cli/_index.md index b57f282f03..e5e9e93b09 100644 --- a/content/en/ref/cli/_index.md +++ b/content/en/ref/cli/_index.md @@ -1,6 +1,5 @@ --- title: Command Line Interface -weight: 2 --- **Usage** @@ -33,15 +32,15 @@ weight: 2 | launch | Launch or queue a W&B Job. | | launch-agent | Run a W&B launch agent. | | launch-sweep | Run a W&B launch sweep (Experimental). | -| login | Login to Weights & Biases | -| offline | Disable W&B sync | -| online | Enable W&B sync | +| login | Verify and store your API key for authentication with W&B... | +| offline | Save data logged to W&B locally without uploading it to... | +| online | Undo `wandb offline`. | | pull | Pull files from Weights & Biases | | restore | Restore code, config and docker state for a run. | | scheduler | Run a W&B launch sweep scheduler (Experimental) | | server | Commands for operating a local W&B server | | status | Show configuration settings | | sweep | Initialize a hyperparameter sweep. | -| sync | Upload an offline training directory to W&B | +| sync | Synchronize W&B run data to the cloud. | | verify | Checks and verifies local instance of W&B. | diff --git a/content/en/ref/cli/wandb-beta/_index.md b/content/en/ref/cli/wandb-beta/_index.md index 7ea8c06397..1ce410aa5d 100644 --- a/content/en/ref/cli/wandb-beta/_index.md +++ b/content/en/ref/cli/wandb-beta/_index.md @@ -8,7 +8,7 @@ title: wandb beta **Summary** -Beta versions of wandb CLI commands. Requires wandb-core. +Beta versions of wandb CLI commands. **Options** @@ -21,5 +21,6 @@ Beta versions of wandb CLI commands. Requires wandb-core. | **Command** | **Description** | | :--- | :--- | +| leet | Launch W&B LEET: the Lightweight Experiment Exploration Tool. | | sync | Upload .wandb files specified by PATHS. | diff --git a/content/en/ref/cli/wandb-beta/wandb-beta-leet.md b/content/en/ref/cli/wandb-beta/wandb-beta-leet.md new file mode 100644 index 0000000000..240f9f62a1 --- /dev/null +++ b/content/en/ref/cli/wandb-beta/wandb-beta-leet.md @@ -0,0 +1,25 @@ +--- +title: wandb beta leet +--- + +**Usage** + +`wandb beta leet [OPTIONS] [PATH]` + +**Summary** + +Launch W&B LEET: the Lightweight Experiment Exploration Tool. + +LEET is a terminal UI for viewing a W&B run specified by an optional PATH. + +PATH can include a .wandb file or a run directory containing a .wandb file. +If PATH is not provided, the command will look for the latest run. + + +**Options** + +| **Option** | **Description** | +| :--- | :--- | + + + diff --git a/content/en/ref/cli/wandb-beta/wandb-beta-sync.md b/content/en/ref/cli/wandb-beta/wandb-beta-sync.md index 64f23b1f95..399f6ca193 100644 --- a/content/en/ref/cli/wandb-beta/wandb-beta-sync.md +++ b/content/en/ref/cli/wandb-beta/wandb-beta-sync.md @@ -4,7 +4,7 @@ title: wandb beta sync **Usage** -`wandb beta sync [OPTIONS] WANDB_DIR` +`wandb beta sync [OPTIONS] [PATHS]...` **Summary** diff --git a/content/en/ref/cli/wandb-login.md b/content/en/ref/cli/wandb-login.md index 9b64f733e6..6445b32819 100644 --- a/content/en/ref/cli/wandb-login.md +++ b/content/en/ref/cli/wandb-login.md @@ -8,7 +8,15 @@ title: wandb login **Summary** -Login to Weights & Biases +Verify and store your API key for authentication with W&B services. + +By default, only store credentials locally without verifying them with W&B. +To verify credentials, set `--verify=True`. + +For server deployments (dedicated cloud or customer-managed instances), +specify the host URL using the `--host` flag. You can also set environment +variables `WANDB_BASE_URL` and `WANDB_API_KEY` instead of running the +`login` command with host parameters. **Options** diff --git a/content/en/ref/cli/wandb-offline.md b/content/en/ref/cli/wandb-offline.md index 91d8357e7c..b50458f7cb 100644 --- a/content/en/ref/cli/wandb-offline.md +++ b/content/en/ref/cli/wandb-offline.md @@ -8,7 +8,9 @@ title: wandb offline **Summary** -Disable W&B sync +Save data logged to W&B locally without uploading it to the cloud. + +Use `wandb online` or `wandb sync` to upload offline runs. **Options** diff --git a/content/en/ref/cli/wandb-online.md b/content/en/ref/cli/wandb-online.md index 7dea72436e..adfdda565e 100644 --- a/content/en/ref/cli/wandb-online.md +++ b/content/en/ref/cli/wandb-online.md @@ -8,7 +8,7 @@ title: wandb online **Summary** -Enable W&B sync +Undo `wandb offline`. **Options** diff --git a/content/en/ref/cli/wandb-sync.md b/content/en/ref/cli/wandb-sync.md index 598c8c8d82..3ef24101d0 100644 --- a/content/en/ref/cli/wandb-sync.md +++ b/content/en/ref/cli/wandb-sync.md @@ -8,8 +8,16 @@ title: wandb sync **Summary** -Upload an offline training directory to W&B +Synchronize W&B run data to the cloud. +If PATH is provided, sync runs found at the given path. If a path is not +specified, search for `./wandb` first, then search for a `wandb/` +subdirectory. + +To sync a specific run: +wandb sync ./wandb/run-20250813_124246-n67z9ude +Or equivalently: +wandb sync ./wandb/run-20250813_124246-n67z9ude/run-n67z9ude.wandb **Options** diff --git a/content/en/ref/python/.md b/content/en/ref/python/.md new file mode 100644 index 0000000000..20d34bf2a2 --- /dev/null +++ b/content/en/ref/python/.md @@ -0,0 +1,8 @@ +--- +title: +--- + + + + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/**init**.py >}} diff --git a/content/en/ref/python/_index.md b/content/en/ref/python/_index.md index a319ec8405..5fe4eb4ff8 100644 --- a/content/en/ref/python/_index.md +++ b/content/en/ref/python/_index.md @@ -1,37 +1,49 @@ --- -title: Python SDK 0.22.0 -module: -weight: 1 +title: Python Library --- -The W&B Python SDK, accessible at `wandb`, enables you to train and fine-tune models, and manage models from experimentation to production. -> After performing your training and fine-tuning operations with this SDK, you can use [the Public API]({{< relref "/ref/python/public-api" >}}) to query and analyze the data that was logged, and [the Reports and Workspaces API]({{< relref "/ref/wandb_workspaces" >}}) to generate a web-publishable [report]({{< relref "/guides/core/reports" >}}) summarizing your work. + -## Installation and setup -### Sign up and create an API key -To authenticate your machine with W&B, you must first generate an API key at https://wandb.ai/authorize. +Use wandb to track machine learning work. -### Install and import packages +Train and fine-tune models, manage models from experimentation to production. -Install the W&B library. +For guides and examples, see https://docs.wandb.ai. -``` -pip install wandb -``` +For scripts and interactive notebooks, see https://github.com/wandb/examples. -### Import W&B Python SDK: +For reference documentation, see https://docs.wandb.com/ref/python. -```python -import wandb +## Classes -# Specify your team entity -entity = "" +[`class Artifact`](./artifact.md): Flexible and lightweight building block for dataset and model versioning. -# Project that the run is recorded to -project = "my-awesome-project" +[`class Run`](./run.md): A unit of computation logged by W&B. Typically, this is an ML experiment. -with wandb.init(entity=entity, project=project) as run: - run.log({"accuracy": 0.9, "loss": 0.1}) -```` +## Functions + +[`agent(...)`](./agent.md): Start one or more sweep agents. + +[`controller(...)`](./controller.md): Public sweep controller constructor. + +[`finish(...)`](./finish.md): Finish a run and upload any remaining data. + +[`init(...)`](./init.md): Start a new run to track and log to W&B. + +[`log(...)`](./log.md): Upload run data. + +[`login(...)`](./login.md): Set up W&B login credentials. + +[`save(...)`](./save.md): Sync one or more files to W&B. + +[`sweep(...)`](./sweep.md): Initialize a hyperparameter sweep. + +[`watch(...)`](./watch.md): Hook into given PyTorch model to monitor gradients and the model's computational graph. + +| Other Members | | +| :--- | :--- | +| `__version__` | `'0.22.2'` | +| `config` | | +| `summary` | | diff --git a/content/en/ref/python/agent.md b/content/en/ref/python/agent.md new file mode 100644 index 0000000000..ddc7cfcdc2 --- /dev/null +++ b/content/en/ref/python/agent.md @@ -0,0 +1,29 @@ +--- +title: agent +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/wandb_agent.py#L560-L604 >}} + +Start one or more sweep agents. + +```python +agent( + sweep_id: str, + function: Optional[Callable] = None, + entity: Optional[str] = None, + project: Optional[str] = None, + count: Optional[int] = None +) -> None +``` + +The sweep agent uses the `sweep_id` to know which sweep it +is a part of, what function to execute, and (optionally) how +many agents to run. + +| Args | | +| :--- | :--- | +| `sweep_id` | The unique identifier for a sweep. A sweep ID is generated by W&B CLI or Python SDK. | +| `function` | A function to call instead of the "program" specified in the sweep config. | +| `entity` | The username or team name where you want to send W&B runs created by the sweep to. Ensure that the entity you specify already exists. If you don't specify an entity, the run will be sent to your default entity, which is usually your username. | +| `project` | The name of the project where W&B runs created from the sweep are sent to. If the project is not specified, the run is sent to a project labeled "Uncategorized". | +| `count` | The number of sweep config trials to try. | diff --git a/content/en/ref/python/artifact.md b/content/en/ref/python/artifact.md new file mode 100644 index 0000000000..bb139a6a20 --- /dev/null +++ b/content/en/ref/python/artifact.md @@ -0,0 +1,734 @@ +--- +title: Artifact +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L167-L2675 >}} + +Flexible and lightweight building block for dataset and model versioning. + +Construct an empty W&B Artifact. Populate an artifacts contents with methods that +begin with `add`. Once the artifact has all the desired files, you can call +`run.log_artifact()` to log it. + +| Args | | +| :--- | :--- | +| name (str): A human-readable name for the artifact. Use the name to identify a specific artifact in the W&B App UI or programmatically. You can interactively reference an artifact with the `use_artifact` Public API. A name can contain letters, numbers, underscores, hyphens, and dots. The name must be unique across a project. type (str): The artifact's type. Use the type of an artifact to both organize and differentiate artifacts. You can use any string that contains letters, numbers, underscores, hyphens, and dots. Common types include `dataset` or `model`. Include `model` within your type string if you want to link the artifact to the W&B Model Registry. Note that some types reserved for internal use and cannot be set by users. Such types include `job` and types that start with `wandb-`. description (str | None) = None: A description of the artifact. For Model or Dataset Artifacts, add documentation for your standardized team model or dataset card. View an artifact's description programmatically with the `Artifact.description` attribute or programmatically with the W&B App UI. W&B renders the description as markdown in the W&B App. metadata (dict[str, Any] | None) = None: Additional information about an artifact. Specify metadata as a dictionary of key-value pairs. You can specify no more than 100 total keys. | +| `incremental` | Use `Artifact.new_draft()` method instead to modify an existing artifact. | +| `use_as` | Deprecated. | +| `is_link` | Boolean indication of if the artifact is a linked artifact(`True`) or source artifact(`False`). | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +| Attributes | | +| :--- | :--- | +| `aliases` | List of one or more semantically-friendly references or identifying "nicknames" assigned to an artifact version. Aliases are mutable references that you can programmatically reference. Change an artifact's alias with the W&B App UI or programmatically. See [Create new artifact versions](https://docs.wandb.ai/guides/artifacts/create-a-new-artifact-version) for more information. | +| `collection` | The collection this artifact was retrieved from. A collection is an ordered group of artifact versions. If this artifact was retrieved from a portfolio / linked collection, that collection will be returned rather than the collection that an artifact version originated from. The collection that an artifact originates from is known as the source sequence. | +| `commit_hash` | The hash returned when this artifact was committed. | +| `created_at` | Timestamp when the artifact was created. | +| `description` | A description of the artifact. | +| `digest` | The logical digest of the artifact. The digest is the checksum of the artifact's contents. If an artifact has the same digest as the current `latest` version, then `log_artifact` is a no-op. | +| `distributed_id` | The distributed ID of the artifact. | +| `entity` | The name of the entity that the artifact collection belongs to. If the artifact is a link, the entity will be the entity of the linked artifact. | +| `file_count` | The number of files (including references). | +| `history_step` | The nearest step at which history metrics were logged for the source run of the artifact. `python run = artifact.logged_by() if run and (artifact.history_step is not None): history = run.sample_history( min_step=artifact.history_step, max_step=artifact.history_step + 1, keys=["my_metric"], ) ` | +| `id` | The artifact's ID. | +| `incremental` | Boolean flag indicating if the artifact is an incremental artifact. | +| `is_link` | Boolean flag indicating if the artifact is a link artifact. True: The artifact is a link artifact to a source artifact. False: The artifact is a source artifact. | +| `linked_artifacts` | Returns a list of all the linked artifacts of a source artifact. If the artifact is a link artifact (`artifact.is_link == True`), it will return an empty list. Limited to 500 results. | +| `manifest` | The artifact's manifest. The manifest lists all of its contents, and can't be changed once the artifact has been logged. | +| `metadata` | User-defined artifact metadata. Structured data associated with the artifact. | +| `name` | The artifact name and version of the artifact. A string with the format `{collection}:{alias}`. If fetched before an artifact is logged/saved, the name won't contain the alias. If the artifact is a link, the name will be the name of the linked artifact. | +| `project` | The name of the project that the artifact collection belongs to. If the artifact is a link, the project will be the project of the linked artifact. | +| `qualified_name` | The entity/project/name of the artifact. If the artifact is a link, the qualified name will be the qualified name of the linked artifact path. | +| `size` | The total size of the artifact in bytes. Includes any references tracked by this artifact. | +| `source_artifact` | Returns the source artifact. The source artifact is the original logged artifact. If the artifact itself is a source artifact (`artifact.is_link == False`), it will return itself. | +| `source_collection` | The artifact's source collection. The source collection is the collection that the artifact was logged from. | +| `source_entity` | The name of the entity of the source artifact. | +| `source_name` | The artifact name and version of the source artifact. A string with the format `{source_collection}:{alias}`. Before the artifact is saved, contains only the name since the version is not yet known. | +| `source_project` | The name of the project of the source artifact. | +| `source_qualified_name` | The source_entity/source_project/source_name of the source artifact. | +| `source_version` | The source artifact's version. A string with the format `v{number}`. | +| `state` | The status of the artifact. One of: "PENDING", "COMMITTED", or "DELETED". | +| `tags` | List of one or more tags assigned to this artifact version. | +| `ttl` | The time-to-live (TTL) policy of an artifact. Artifacts are deleted shortly after a TTL policy's duration passes. If set to `None`, the artifact deactivates TTL policies and will be not scheduled for deletion, even if there is a team default TTL. An artifact inherits a TTL policy from the team default if the team administrator defines a default TTL and there is no custom policy set on an artifact. | +| `type` | The artifact's type. Common types include `dataset` or `model`. | +| `updated_at` | The time when the artifact was last updated. | +| `url` | Constructs the URL of the artifact. | +| `use_as` | Deprecated. | +| `version` | The artifact's version. A string with the format `v{number}`. If the artifact is a link artifact, the version will be from the linked collection. | + +## Methods + +### `add` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1646-L1740) + +```python +add( + obj: WBValue, + name: StrPath, + overwrite: bool = (False) +) -> ArtifactManifestEntry +``` + +Add wandb.WBValue `obj` to the artifact. + +| Args | | +| :--- | :--- | +| `obj` | The object to add. Currently support one of Bokeh, JoinedTable, PartitionedTable, Table, Classes, ImageMask, BoundingBoxes2D, Audio, Image, Video, Html, Object3D | +| `name` | The path within the artifact to add the object. | +| `overwrite` | If True, overwrite existing objects with the same file path if applicable. | + +| Returns | | +| :--- | :--- | +| The added manifest entry | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | + +### `add_dir` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1493-L1558) + +```python +add_dir( + local_path: str, + name: (str | None) = None, + skip_cache: (bool | None) = (False), + policy: (Literal['mutable', 'immutable'] | None) = "mutable", + merge: bool = (False) +) -> None +``` + +Add a local directory to the artifact. + +| Args | | +| :--- | :--- | +| `local_path` | The path of the local directory. | +| `name` | The subdirectory name within an artifact. The name you specify appears in the W&B App UI nested by artifact's `type`. Defaults to the root of the artifact. | +| `skip_cache` | If set to `True`, W&B will not copy/move files to the cache while uploading | +| `policy` | By default, "mutable". - mutable: Create a temporary copy of the file to prevent corruption during upload. - immutable: Disable protection, rely on the user not to delete or change the file. | +| `merge` | If `False` (default), throws ValueError if a file was already added in a previous add_dir call and its content has changed. If `True`, overwrites existing files with changed content. Always adds new files and never removes files. To replace an entire directory, pass a name when adding the directory using `add_dir(local_path, name=my_prefix)` and call `remove(my_prefix)` to remove the directory, then add it again. | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | +| `ValueError` | Policy must be "mutable" or "immutable" | + +### `add_file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1436-L1491) + +```python +add_file( + local_path: str, + name: (str | None) = None, + is_tmp: (bool | None) = (False), + skip_cache: (bool | None) = (False), + policy: (Literal['mutable', 'immutable'] | None) = "mutable", + overwrite: bool = (False) +) -> ArtifactManifestEntry +``` + +Add a local file to the artifact. + +| Args | | +| :--- | :--- | +| `local_path` | The path to the file being added. | +| `name` | The path within the artifact to use for the file being added. Defaults to the basename of the file. | +| `is_tmp` | If true, then the file is renamed deterministically to avoid collisions. | +| `skip_cache` | If `True`, do not copy files to the cache after uploading. | +| `policy` | By default, set to "mutable". If set to "mutable", create a temporary copy of the file to prevent corruption during upload. If set to "immutable", disable protection and rely on the user not to delete or change the file. | +| `overwrite` | If `True`, overwrite the file if it already exists. | + +| Returns | | +| :--- | :--- | +| The added manifest entry. | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | +| `ValueError` | Policy must be "mutable" or "immutable" | + +### `add_reference` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1560-L1644) + +```python +add_reference( + uri: (ArtifactManifestEntry | str), + name: (StrPath | None) = None, + checksum: bool = (True), + max_objects: (int | None) = None +) -> Sequence[ArtifactManifestEntry] +``` + +Add a reference denoted by a URI to the artifact. + +Unlike files or directories that you add to an artifact, references are not +uploaded to W&B. For more information, +see [Track external files](https://docs.wandb.ai/guides/artifacts/track-external-files). + +By default, the following schemes are supported: + +- http(s): The size and digest of the file will be inferred by the + `Content-Length` and the `ETag` response headers returned by the server. +- s3: The checksum and size are pulled from the object metadata. + If bucket versioning is enabled, then the version ID is also tracked. +- gs: The checksum and size are pulled from the object metadata. If bucket + versioning is enabled, then the version ID is also tracked. +- https, domain matching `*.blob.core.windows.net` +- Azure: The checksum and size are be pulled from the blob metadata. + If storage account versioning is enabled, then the version ID is + also tracked. +- file: The checksum and size are pulled from the file system. This scheme + is useful if you have an NFS share or other externally mounted volume + containing files you wish to track but not necessarily upload. + +For any other scheme, the digest is just a hash of the URI and the size is left +blank. + +| Args | | +| :--- | :--- | +| `uri` | The URI path of the reference to add. The URI path can be an object returned from `Artifact.get_entry` to store a reference to another artifact's entry. | +| `name` | The path within the artifact to place the contents of this reference. | +| `checksum` | Whether or not to checksum the resource(s) located at the reference URI. Checksumming is strongly recommended as it enables automatic integrity validation. Disabling checksumming will speed up artifact creation but reference directories will not iterated through so the objects in the directory will not be saved to the artifact. We recommend setting `checksum=False` when adding reference objects, in which case a new version will only be created if the reference URI changes. | +| `max_objects` | The maximum number of objects to consider when adding a reference that points to directory or bucket store prefix. By default, the maximum number of objects allowed for Amazon S3, GCS, Azure, and local files is 10,000,000. Other URI schemas do not have a maximum. | + +| Returns | | +| :--- | :--- | +| The added manifest entries. | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | + +### `checkout` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2188-L2216) + +```python +checkout( + root: (str | None) = None +) -> str +``` + +Replace the specified root directory with the contents of the artifact. + +WARNING: This will delete all files in `root` that are not included in the +artifact. + +| Args | | +| :--- | :--- | +| `root` | The directory to replace with this artifact's files. | + +| Returns | | +| :--- | :--- | +| The path of the checked out contents. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `delete` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2323-L2347) + +```python +delete( + delete_aliases: bool = (False) +) -> None +``` + +Delete an artifact and its files. + +If called on a linked artifact, only the link is deleted, and the +source artifact is unaffected. + +Use `artifact.unlink()` instead of `artifact.delete()` to remove a link between a source artifact and a linked artifact. + +| Args | | +| :--- | :--- | +| `delete_aliases` | If set to `True`, deletes all aliases associated with the artifact. Otherwise, this raises an exception if the artifact has existing aliases. This parameter is ignored if the artifact is linked (a member of a portfolio collection). | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `download` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1915-L1967) + +```python +download( + root: (StrPath | None) = None, + allow_missing_references: bool = (False), + skip_cache: (bool | None) = None, + path_prefix: (StrPath | None) = None, + multipart: (bool | None) = None +) -> FilePathStr +``` + +Download the contents of the artifact to the specified root directory. + +Existing files located within `root` are not modified. Explicitly delete `root` +before you call `download` if you want the contents of `root` to exactly match +the artifact. + +| Args | | +| :--- | :--- | +| `root` | The directory W&B stores the artifact's files. | +| `allow_missing_references` | If set to `True`, any invalid reference paths will be ignored while downloading referenced files. | +| `skip_cache` | If set to `True`, the artifact cache will be skipped when downloading and W&B will download each file into the default root or specified download directory. | +| `path_prefix` | If specified, only files with a path that starts with the given prefix will be downloaded. Uses unix format (forward slashes). | +| `multipart` | If set to `None` (default), the artifact will be downloaded in parallel using multipart download if individual file size is greater than 2GB. If set to `True` or `False`, the artifact will be downloaded in parallel or serially regardless of the file size. | + +| Returns | | +| :--- | :--- | +| The path to the downloaded contents. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2256-L2280) + +```python +file( + root: (str | None) = None +) -> StrPath +``` + +Download a single file artifact to the directory you specify with `root`. + +| Args | | +| :--- | :--- | +| `root` | The root directory to store the file. Defaults to `./artifacts/self.name/`. | + +| Returns | | +| :--- | :--- | +| The full path of the downloaded file. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | +| `ValueError` | If the artifact contains more than one file. | + +### `files` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2282-L2299) + +```python +files( + names: (list[str] | None) = None, + per_page: int = 50 +) -> ArtifactFiles +``` + +Iterate over all files stored in this artifact. + +| Args | | +| :--- | :--- | +| `names` | The filename paths relative to the root of the artifact you wish to list. | +| `per_page` | The number of files to return per request. | + +| Returns | | +| :--- | :--- | +| An iterator containing `File` objects. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `finalize` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1126-L1134) + +```python +finalize() -> None +``` + +Finalize the artifact version. + +You cannot modify an artifact version once it is finalized because the artifact +is logged as a specific artifact version. Create a new artifact version +to log more data to an artifact. An artifact is automatically finalized +when you log the artifact with `log_artifact`. + +### `get` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1834-L1879) + +```python +get( + name: str +) -> (WBValue | None) +``` + +Get the WBValue object located at the artifact relative `name`. + +| Args | | +| :--- | :--- | +| `name` | The artifact relative name to retrieve. | + +| Returns | | +| :--- | :--- | +| W&B object that can be logged with `run.log()` and visualized in the W&B UI. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | if the artifact isn't logged or the run is offline. | + +### `get_added_local_path_name` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1881-L1892) + +```python +get_added_local_path_name( + local_path: str +) -> (str | None) +``` + +Get the artifact relative name of a file added by a local filesystem path. + +| Args | | +| :--- | :--- | +| `local_path` | The local path to resolve into an artifact relative name. | + +| Returns | | +| :--- | :--- | +| The artifact relative name. | + +### `get_entry` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1813-L1832) + +```python +get_entry( + name: StrPath +) -> ArtifactManifestEntry +``` + +Get the entry with the given name. + +| Args | | +| :--- | :--- | +| `name` | The artifact relative name to get | + +| Returns | | +| :--- | :--- | +| A `W&B` object. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | if the artifact isn't logged or the run is offline. | +| `KeyError` | if the artifact doesn't contain an entry with the given name. | + +### `get_path` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1805-L1811) + +```python +get_path( + name: StrPath +) -> ArtifactManifestEntry +``` + +Deprecated. Use `get_entry(name)`. + +### `is_draft` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1136-L1142) + +```python +is_draft() -> bool +``` + +Check if artifact is not saved. + +| Returns | | +| :--- | :--- | +| Boolean. `False` if artifact is saved. `True` if artifact is not saved. | + +### `json_encode` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2553-L2560) + +```python +json_encode() -> dict[str, Any] +``` + +Returns the artifact encoded to the JSON format. + +| Returns | | +| :--- | :--- | +| A `dict` with `string` keys representing attributes of the artifact. | + +### `link` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2359-L2460) + +```python +link( + target_path: str, + aliases: (list[str] | None) = None +) -> Artifact +``` + +Link this artifact to a portfolio (a promoted collection of artifacts). + +| Args | | +| :--- | :--- | +| `target_path` | The path to the portfolio inside a project. The target path must adhere to one of the following schemas `{portfolio}`, `{project}/{portfolio}` or `{entity}/{project}/{portfolio}`. To link the artifact to the Model Registry, rather than to a generic portfolio inside a project, set `target_path` to the following schema `{"model-registry"}/{Registered Model Name}` or `{entity}/{"model-registry"}/{Registered Model Name}`. | +| `aliases` | A list of strings that uniquely identifies the artifact inside the specified portfolio. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +| Returns | | +| :--- | :--- | +| The linked artifact. | + +### `logged_by` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2526-L2551) + +```python +logged_by() -> (Run | None) +``` + +Get the W&B run that originally logged the artifact. + +| Returns | | +| :--- | :--- | +| The name of the W&B run that originally logged the artifact. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `new_draft` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L544-L577) + +```python +new_draft() -> Artifact +``` + +Create a new draft artifact with the same content as this committed artifact. + +Modifying an existing artifact creates a new artifact version known +as an "incremental artifact". The artifact returned can be extended or +modified and logged as a new version. + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `new_file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1392-L1434) + +```python +@contextlib.contextmanager +new_file( + name: str, + mode: str = "x", + encoding: (str | None) = None +) -> Iterator[IO] +``` + +Open a new temporary file and add it to the artifact. + +| Args | | +| :--- | :--- | +| `name` | The name of the new file to add to the artifact. | +| `mode` | The file access mode to use to open the new file. | +| `encoding` | The encoding used to open the new file. | + +| Returns | | +| :--- | :--- | +| A new file object that can be written to. Upon closing, the file is automatically added to the artifact. | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | + +### `remove` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1776-L1803) + +```python +remove( + item: (StrPath | ArtifactManifestEntry) +) -> None +``` + +Remove an item from the artifact. + +| Args | | +| :--- | :--- | +| `item` | The item to remove. Can be a specific manifest entry or the name of an artifact-relative path. If the item matches a directory all items in that directory will be removed. | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | +| `FileNotFoundError` | If the item isn't found in the artifact. | + +### `save` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1147-L1187) + +```python +save( + project: (str | None) = None, + settings: (wandb.Settings | None) = None +) -> None +``` + +Persist any changes made to the artifact. + +If currently in a run, that run will log this artifact. If not currently in a +run, a run of type "auto" is created to track this artifact. + +| Args | | +| :--- | :--- | +| `project` | A project to use for the artifact in the case that a run is not already in context. | +| `settings` | A settings object to use when initializing an automatic run. Most commonly used in testing harness. | + +### `unlink` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2462-L2478) + +```python +unlink() -> None +``` + +Unlink this artifact if it is currently a member of a promoted collection of artifacts. + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | +| `ValueError` | If the artifact is not linked, in other words, it is not a member of a portfolio collection. | + +### `used_by` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2495-L2524) + +```python +used_by() -> list[Run] +``` + +Get a list of the runs that have used this artifact and its linked artifacts. + +| Returns | | +| :--- | :--- | +| A list of `Run` objects. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | + +### `verify` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L2218-L2254) + +```python +verify( + root: (str | None) = None +) -> None +``` + +Verify that the contents of an artifact match the manifest. + +All files in the directory are checksummed and the checksums are then +cross-referenced against the artifact's manifest. References are not verified. + +| Args | | +| :--- | :--- | +| `root` | The directory to verify. If None artifact will be downloaded to './artifacts/self.name/'. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact is not logged. | +| `ValueError` | If the verification fails. | + +### `wait` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1197-L1221) + +```python +wait( + timeout: (int | None) = None +) -> Artifact +``` + +If needed, wait for this artifact to finish logging. + +| Args | | +| :--- | :--- | +| `timeout` | The time, in seconds, to wait. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +### `__getitem__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1361-L1373) + +```python +__getitem__( + name: str +) -> (WBValue | None) +``` + +Get the WBValue object located at the artifact relative `name`. + +| Args | | +| :--- | :--- | +| `name` | The artifact relative name to get. | + +| Returns | | +| :--- | :--- | +| W&B object that can be logged with `run.log()` and visualized in the W&B UI. | + +| Raises | | +| :--- | :--- | +| `ArtifactNotLoggedError` | If the artifact isn't logged or the run is offline. | + +### `__setitem__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/artifacts/artifact.py#L1375-L1390) + +```python +__setitem__( + name: str, + item: WBValue +) -> ArtifactManifestEntry +``` + +Add `item` to the artifact at path `name`. + +| Args | | +| :--- | :--- | +| `name` | The path within the artifact to add the object. | +| `item` | The object to add. | + +| Returns | | +| :--- | :--- | +| The added manifest entry | + +| Raises | | +| :--- | :--- | +| `ArtifactFinalizedError` | You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead. | diff --git a/content/en/ref/python/automations/_index.md b/content/en/ref/python/automations/_index.md index 1f0a41e9df..0ebca0dc1e 100644 --- a/content/en/ref/python/automations/_index.md +++ b/content/en/ref/python/automations/_index.md @@ -1,96 +1,31 @@ --- -title: Automations -module: wandb.automations -weight: 4 -no_list: true +title: automations --- -The W&B Automations API enables programmatic creation and management of automated workflows that respond to events in your ML pipeline. Configure actions to trigger when specific conditions are met, such as model performance thresholds or artifact creation. + -### Core Classes -| Class | Description | -|-------|-------------| -| [`Automation`](./automation/) | Represents a saved automation instance with its configuration. | -| [`NewAutomation`](./newautomation/) | Builder class for creating new automations. | +## Classes -### Events (Triggers) +[`class Automation`](./automation.md): A local instance of a saved W&B automation. -| Event | Description | -|-------|-------------| -| [`OnRunMetric`](./onrunmetric/) | Trigger when a run metric satisfies a defined condition (threshold, change, etc.). | -| [`OnCreateArtifact`](./oncreateartifact/) | Trigger when a new artifact is created in a collection. | -| [`OnLinkArtifact`](./onlinkartifact/) | Trigger when an artifact is linked to a registry. | -| [`OnAddArtifactAlias`](./onaddartifactalias/) | Trigger when an alias is added to an artifact. | +[`class DoNothing`](./donothing.md): Defines an automation action that intentionally does nothing. -### Actions +[`class MetricChangeFilter`](./metricchangefilter.md): Defines a filter that compares a change in a run metric against a user-defined threshold. -| Action | Description | -|--------|-------------| -| [`SendNotification`](./sendnotification/) | Send notifications via Slack or other integrated channels. | -| [`SendWebhook`](./sendwebhook/) | Send HTTP webhook requests to external services. | -| [`DoNothing`](./donothing/) | Placeholder action for testing automation configurations. | +[`class MetricThresholdFilter`](./metricthresholdfilter.md): Defines a filter that compares a run metric against a user-defined threshold value. -### Filters +[`class NewAutomation`](./newautomation.md): A new automation to be created. -| Filter | Description | -|--------|-------------| -| [`MetricThresholdFilter`](./metricthresholdfilter/) | Filter runs based on metric value comparisons against thresholds. | -| [`MetricChangeFilter`](./metricchangefilter/) | Filter runs based on metric value changes over time. | +[`class OnAddArtifactAlias`](./onaddartifactalias.md): A new alias is assigned to an artifact. -## Common Use Cases +[`class OnCreateArtifact`](./oncreateartifact.md): A new artifact is created. -### Model Performance Monitoring -- Alert when model accuracy drops below a threshold -- Notify team when training loss plateaus -- Trigger retraining pipelines based on performance metrics +[`class OnLinkArtifact`](./onlinkartifact.md): A new artifact is linked to a collection. -### Artifact Management -- Send notifications when new model versions are created -- Trigger deployment workflows when artifacts are tagged -- Automate downstream processing when datasets are updated +[`class OnRunMetric`](./onrunmetric.md): A run metric satisfies a user-defined condition. -### Experiment Tracking -- Alert on failed or crashed runs -- Notify when long-running experiments complete -- Send daily summaries of experiment metrics +[`class SendNotification`](./sendnotification.md): Defines an automation action that sends a (Slack) notification. -### Integration Workflows -- Update external tracking systems via webhooks -- Sync model registry with deployment platforms -- Trigger CI/CD pipelines based on W&B events - -## Example Usage - -The following example creates an automation that sends a Slack notification whenever a metric called `custom-metric` exceeds 10. `custom-metric` is expected to be logged during training using `wandb.Run.log({"custom-metric": value })`. - -```python -import wandb -from wandb.automations import OnRunMetric, RunEvent, SendNotification - -api = wandb.Api() - -project = api.project("", entity="") - -# Use the first Slack integration for the team -slack_hook = next(api.slack_integrations(entity="")) - -# Create a trigger event -event = OnRunMetric( - scope=project, - filter=RunEvent.metric("custom-metric") > 10, -) - -# Create an action that responds to the event -action = SendNotification.from_integration(slack_hook) - -# Create the automation -automation = api.create_automation( - event >> action, - name="my-automation", - description="Send a Slack message whenever 'custom-metric' exceeds 10.", -) -``` - -For more information about using the Automations API, see the [Automations Guide]({{< relref "/guides/core/automations" >}}). \ No newline at end of file +[`class SendWebhook`](./sendwebhook.md): Defines an automation action that sends a webhook request. diff --git a/content/en/ref/python/automations/automation.md b/content/en/ref/python/automations/automation.md index df2566ebe1..381b895f1e 100644 --- a/content/en/ref/python/automations/automation.md +++ b/content/en/ref/python/automations/automation.md @@ -1,46 +1,16 @@ --- title: Automation -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/automations.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/automations.py#L19-L48 >}} - - -## class `Automation` A local instance of a saved W&B automation. - -### method `Automation.__init__` - -```python -__init__( - typename__: 'Literal['Trigger']' = 'Trigger', - id: 'str', - created_at: 'datetime', - updated_at: 'datetime | None' = None, - name: 'str', - description: 'str | None', - enabled: 'bool', - scope: '_ArtifactSequenceScope | _ArtifactPortfolioScope | ProjectScope', - event: 'SavedEvent', - action: 'SavedLaunchJobAction | SavedNotificationAction | SavedWebhookAction | SavedNoOpAction' -) → None -``` - -**Args:** - - - `typename__` (Literal['Trigger']): - - `id` (str): - - `created_at` (datetime): The date and time when this automation was created. - - `updated_at` (Optional[datetime]): The date and time when this automation was last updated, if applicable. - - `name` (str): The name of this automation. - - `description` (Optional[str]): An optional description of this automation. - - `enabled` (bool): Whether this automation is enabled. Only enabled automations will trigger. - - `scope` (Union[_ArtifactSequenceScope, _ArtifactPortfolioScope, ProjectScope]): The scope in which the triggering event must occur. - - `event` (SavedEvent): The event that will trigger this automation. - - `action` (Union[SavedLaunchJobAction, SavedNotificationAction, SavedWebhookAction, SavedNoOpAction]): The action that will execute when this automation is triggered. - -**Returns:** - An `Automation` object. +| Attributes | | +| :--- | :--- | +| `name` | The name of this automation. | +| `description` | An optional description of this automation. | +| `enabled` | Whether this automation is enabled. Only enabled automations will trigger. | +| `scope` | The scope in which the triggering event must occur. | +| `event` | The event that will trigger this automation. | +| `action` | The action that will execute when this automation is triggered. | diff --git a/content/en/ref/python/automations/donothing.md b/content/en/ref/python/automations/donothing.md index 08324b59f7..98994e7d9a 100644 --- a/content/en/ref/python/automations/donothing.md +++ b/content/en/ref/python/automations/donothing.md @@ -1,31 +1,12 @@ --- title: DoNothing -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/actions.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/actions.py#L192-L201 >}} - - -## class `DoNothing` Defines an automation action that intentionally does nothing. - -### method `DoNothing.__init__` - -```python -__init__( - no_op: 'bool' = True, - action_type: 'Literal[NO_OP]' = NO_OP -) → None -``` - -**Args:** - - - `no_op` (bool): Placeholder field which exists only to satisfy backend schema requirements. - There should never be a need to set this field explicitly, as its value is ignored. - - `action_type` (Literal[NO_OP]): - -**Returns:** - An `DoNothing` object. +| Attributes | | +| :--- | :--- | +| `no_op` | Placeholder field which exists only to satisfy backend schema requirements. There should never be a need to set this field explicitly, as its value is ignored. | +| `action_type` | The kind of action to be triggered. | diff --git a/content/en/ref/python/automations/metricchangefilter.md b/content/en/ref/python/automations/metricchangefilter.md index b12cf5669b..665d550c91 100644 --- a/content/en/ref/python/automations/metricchangefilter.md +++ b/content/en/ref/python/automations/metricchangefilter.md @@ -1,46 +1,18 @@ --- title: MetricChangeFilter -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/_filters/run_metrics.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/_filters/run_metrics.py#L142-L188 >}} - - -## class `MetricChangeFilter` Defines a filter that compares a change in a run metric against a user-defined threshold. The change is calculated over "tumbling" windows, i.e. the difference between the current window and the non-overlapping prior window. - -### method `MetricChangeFilter.__init__` - -```python -__init__( - name: 'str', - agg: 'Agg | None' = None, - window: 'int' = 1, - cmp: 'None' = None, - threshold: 'Annotated | Annotated', - prior_window: 'int' = None, - change_type: 'ChangeType', - change_dir: 'ChangeDir' -) → None -``` - -**Args:** - - - `name` (str): - - `agg` (Optional[Agg]): - - `window` (int): - - `cmp` (None): Ignored. - - `threshold` (Union[Annotated, Annotated]): - - `prior_window` (int): Size of the prior window over which the metric is aggregated (ignored if `agg is None`). - If omitted, defaults to the size of the current window. - - `change_type` (ChangeType): - - `change_dir` (ChangeDir): - -**Returns:** - An `MetricChangeFilter` object. +| Attributes | | +| :--- | :--- | +| `prior_window` | Size of the prior window over which the metric is aggregated (ignored if `agg is None`). If omitted, defaults to the size of the current window. | +| `name` | Name of the observed metric. | +| `agg` | Aggregate operation, if any, to apply over the window size. | +| `window` | Size of the window over which the metric is aggregated (ignored if `agg is None`). | +| `threshold` | Threshold value to compare against. | diff --git a/content/en/ref/python/automations/metricthresholdfilter.md b/content/en/ref/python/automations/metricthresholdfilter.md index f46217d0cf..5e75555ff5 100644 --- a/content/en/ref/python/automations/metricthresholdfilter.md +++ b/content/en/ref/python/automations/metricthresholdfilter.md @@ -1,36 +1,15 @@ --- title: MetricThresholdFilter -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/_filters/run_metrics.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/_filters/run_metrics.py#L119-L139 >}} - - -## class `MetricThresholdFilter` Defines a filter that compares a run metric against a user-defined threshold value. - -### method `MetricThresholdFilter.__init__` - -```python -__init__( - name: 'str', - agg: 'Agg | None' = None, - window: 'int' = 1, - cmp: 'Literal['$gte', '$gt', '$lt', '$lte']', - threshold: 'Annotated | Annotated' -) → None -``` - -**Args:** - - - `name` (str): - - `agg` (Optional[Agg]): - - `window` (int): - - `cmp` (Literal['$gte', '$gt', '$lt', '$lte']): Comparison operator used to compare the metric value (left) vs. the threshold value (right). - - `threshold` (Union[Annotated, Annotated]): - -**Returns:** - An `MetricThresholdFilter` object. +| Attributes | | +| :--- | :--- | +| `cmp` | Comparison operator used to compare the metric value (left) vs. the threshold value (right). | +| `name` | Name of the observed metric. | +| `agg` | Aggregate operation, if any, to apply over the window size. | +| `window` | Size of the window over which the metric is aggregated (ignored if `agg is None`). | +| `threshold` | Threshold value to compare against. | diff --git a/content/en/ref/python/automations/newautomation.md b/content/en/ref/python/automations/newautomation.md index d15f7cfc74..38981de720 100644 --- a/content/en/ref/python/automations/newautomation.md +++ b/content/en/ref/python/automations/newautomation.md @@ -1,43 +1,16 @@ --- title: NewAutomation -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/automations.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/automations.py#L51-L79 >}} - - -## class `NewAutomation` A new automation to be created. - -### method `NewAutomation.__init__` - -```python -__init__( - name: 'str | None' = None, - description: 'str | None' = None, - enabled: 'bool | None' = None, - event: 'Annotated | None' = None, - action: 'Annotated | None' = None -) → None -``` - -**Args:** - - - `name` (Optional[str]): The name of this automation. - - `description` (Optional[str]): An optional description of this automation. - - `enabled` (Optional[bool]): Whether this automation is enabled. Only enabled automations will trigger. - - `event` (Optional[Annotated]): The event that will trigger this automation. - - `action` (Optional[Annotated]): The action that will execute when this automation is triggered. - -**Returns:** - An `NewAutomation` object. - -### property `NewAutomation.scope` - -The scope in which the triggering event must occur. - -**Returns:** - - `Optional[AutomationScope]`: The scope property value. +| Attributes | | +| :--- | :--- | +| `name` | The name of this automation. | +| `description` | An optional description of this automation. | +| `enabled` | Whether this automation is enabled. Only enabled automations will trigger. | +| `event` | The event that will trigger this automation. | +| `action` | The action that will execute when this automation is triggered. | +| `scope` | The scope in which the triggering event must occur. | diff --git a/content/en/ref/python/automations/onaddartifactalias.md b/content/en/ref/python/automations/onaddartifactalias.md index 076403b555..3ea70f6e44 100644 --- a/content/en/ref/python/automations/onaddartifactalias.md +++ b/content/en/ref/python/automations/onaddartifactalias.md @@ -1,32 +1,26 @@ --- title: OnAddArtifactAlias -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/events.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L188-L191 >}} +A new alias is assigned to an artifact. +| Attributes | | +| :--- | :--- | +| `scope` | The scope of the event. | +| `filter` | Additional condition(s), if any, that must be met for this event to trigger an automation. | -## class `OnAddArtifactAlias` -A new alias is assigned to an artifact. +## Methods +### `then` -### method `OnAddArtifactAlias.__init__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L151-L158) ```python -__init__( - event_type: 'Literal[ADD_ARTIFACT_ALIAS]' = ADD_ARTIFACT_ALIAS, - scope: '_ArtifactSequenceScope | _ArtifactPortfolioScope | ProjectScope', - filter: 'And | Or | Nor | Not | Lt | Gt | Lte | Gte | Eq | Ne | In | NotIn | Exists | Regex | Contains | dict[str, Any] | FilterExpr' = And([]) -) → None +then( + action: InputAction +) -> NewAutomation ``` -**Args:** - - - `event_type` (Literal[ADD_ARTIFACT_ALIAS]): - - `scope` (Union[_ArtifactSequenceScope, _ArtifactPortfolioScope, ProjectScope]): The scope of the event. - - `filter` (Union[And, Or, Nor, Not, Lt, Gt, Lte, Gte, Eq, Ne, In, NotIn, Exists, Regex, Contains, Dict[str, Any], FilterExpr]): Additional condition(s), if any, that must be met for this event to trigger an automation. - -**Returns:** - An `OnAddArtifactAlias` object. +Define a new Automation in which this event triggers the given action. diff --git a/content/en/ref/python/automations/oncreateartifact.md b/content/en/ref/python/automations/oncreateartifact.md index 7a2e82ca19..ea4c7c4df8 100644 --- a/content/en/ref/python/automations/oncreateartifact.md +++ b/content/en/ref/python/automations/oncreateartifact.md @@ -1,32 +1,26 @@ --- title: OnCreateArtifact -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/events.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L194-L200 >}} +A new artifact is created. +| Attributes | | +| :--- | :--- | +| `scope` | The scope of the event: only artifact collections are valid scopes for this event. | +| `filter` | Additional condition(s), if any, that must be met for this event to trigger an automation. | -## class `OnCreateArtifact` -A new artifact is created. +## Methods +### `then` -### method `OnCreateArtifact.__init__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L151-L158) ```python -__init__( - event_type: 'Literal[CREATE_ARTIFACT]' = CREATE_ARTIFACT, - scope: '_ArtifactSequenceScope | _ArtifactPortfolioScope', - filter: 'And | Or | Nor | Not | Lt | Gt | Lte | Gte | Eq | Ne | In | NotIn | Exists | Regex | Contains | dict[str, Any] | FilterExpr' = And([]) -) → None +then( + action: InputAction +) -> NewAutomation ``` -**Args:** - - - `event_type` (Literal[CREATE_ARTIFACT]): - - `scope` (Union[_ArtifactSequenceScope, _ArtifactPortfolioScope]): The scope of the event: only artifact collections are valid scopes for this event. - - `filter` (Union[And, Or, Nor, Not, Lt, Gt, Lte, Gte, Eq, Ne, In, NotIn, Exists, Regex, Contains, Dict[str, Any], FilterExpr]): Additional condition(s), if any, that must be met for this event to trigger an automation. - -**Returns:** - An `OnCreateArtifact` object. +Define a new Automation in which this event triggers the given action. diff --git a/content/en/ref/python/automations/onlinkartifact.md b/content/en/ref/python/automations/onlinkartifact.md index 19f82b57a0..28d0f48bf7 100644 --- a/content/en/ref/python/automations/onlinkartifact.md +++ b/content/en/ref/python/automations/onlinkartifact.md @@ -1,32 +1,26 @@ --- title: OnLinkArtifact -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/events.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L182-L185 >}} +A new artifact is linked to a collection. +| Attributes | | +| :--- | :--- | +| `scope` | The scope of the event. | +| `filter` | Additional condition(s), if any, that must be met for this event to trigger an automation. | -## class `OnLinkArtifact` -A new artifact is linked to a collection. +## Methods +### `then` -### method `OnLinkArtifact.__init__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L151-L158) ```python -__init__( - event_type: 'Literal[LINK_ARTIFACT]' = LINK_ARTIFACT, - scope: '_ArtifactSequenceScope | _ArtifactPortfolioScope | ProjectScope', - filter: 'And | Or | Nor | Not | Lt | Gt | Lte | Gte | Eq | Ne | In | NotIn | Exists | Regex | Contains | dict[str, Any] | FilterExpr' = And([]) -) → None +then( + action: InputAction +) -> NewAutomation ``` -**Args:** - - - `event_type` (Literal[LINK_ARTIFACT]): - - `scope` (Union[_ArtifactSequenceScope, _ArtifactPortfolioScope, ProjectScope]): The scope of the event. - - `filter` (Union[And, Or, Nor, Not, Lt, Gt, Lte, Gte, Eq, Ne, In, NotIn, Exists, Regex, Contains, Dict[str, Any], FilterExpr]): Additional condition(s), if any, that must be met for this event to trigger an automation. - -**Returns:** - An `OnLinkArtifact` object. +Define a new Automation in which this event triggers the given action. diff --git a/content/en/ref/python/automations/onrunmetric.md b/content/en/ref/python/automations/onrunmetric.md index 7ac4d1a2d6..f6ee3aaf32 100644 --- a/content/en/ref/python/automations/onrunmetric.md +++ b/content/en/ref/python/automations/onrunmetric.md @@ -1,32 +1,26 @@ --- title: OnRunMetric -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/events.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L210-L232 >}} +A run metric satisfies a user-defined condition. +| Attributes | | +| :--- | :--- | +| `scope` | The scope of the event: only projects are valid scopes for this event. | +| `filter` | Run and/or metric condition(s) that must be satisfied for this event to trigger an automation. | -## class `OnRunMetric` -A run metric satisfies a user-defined condition. +## Methods +### `then` -### method `OnRunMetric.__init__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/events.py#L151-L158) ```python -__init__( - event_type: 'Literal[RUN_METRIC_THRESHOLD, RUN_METRIC_CHANGE]', - scope: 'ProjectScope', - filter: 'RunMetricFilter' -) → None +then( + action: InputAction +) -> NewAutomation ``` -**Args:** - - - `event_type` (Literal[RUN_METRIC_THRESHOLD, RUN_METRIC_CHANGE]): - - `scope` (ProjectScope): The scope of the event: only projects are valid scopes for this event. - - `filter` (RunMetricFilter): Run and/or metric condition(s) that must be satisfied for this event to trigger an automation. - -**Returns:** - An `OnRunMetric` object. +Define a new Automation in which this event triggers the given action. diff --git a/content/en/ref/python/automations/sendnotification.md b/content/en/ref/python/automations/sendnotification.md index 3bb281fb43..a462fb48fe 100644 --- a/content/en/ref/python/automations/sendnotification.md +++ b/content/en/ref/python/automations/sendnotification.md @@ -1,49 +1,33 @@ --- title: SendNotification -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/actions.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/actions.py#L127-L164 >}} - - -## class `SendNotification` Defines an automation action that sends a (Slack) notification. +| Attributes | | +| :--- | :--- | +| `title` | The title of the sent notification. | +| `message` | The message body of the sent notification. | +| `severity` | The severity (`INFO`, `WARN`, `ERROR`) of the sent notification. | +| `action_type` | The kind of action to be triggered. | -### method `SendNotification.__init__` - -```python -__init__( - integration_id: 'str', - title: 'str' = '', - message: 'str' = '', - severity: 'AlertSeverity' = , - action_type: 'Literal[NOTIFICATION]' = NOTIFICATION -) → None -``` - -**Args:** - - - `integration_id` (str): The ID of the Slack integration that will be used to send the notification. - - `title` (str): The title of the sent notification. - - `message` (str): The message body of the sent notification. - - `severity` (AlertSeverity): The severity (`INFO`, `WARN`, `ERROR`) of the sent notification. - - `action_type` (Literal[NOTIFICATION]): +## Methods -**Returns:** - An `SendNotification` object. +### `from_integration` -### classmethod `SendNotification.from_integration` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/actions.py#L149-L164) ```python +@classmethod from_integration( - integration: 'SlackIntegration', - title: 'str' = '', - text: 'str' = '', - level: 'AlertSeverity' = -) → Self + integration: SlackIntegration, + *, + title: str = "", + text: str = "", + level: AlertSeverity = AlertSeverity.INFO +) -> Self ``` Define a notification action that sends to the given (Slack) integration. diff --git a/content/en/ref/python/automations/sendwebhook.md b/content/en/ref/python/automations/sendwebhook.md index a34f5c7593..938e9761b9 100644 --- a/content/en/ref/python/automations/sendwebhook.md +++ b/content/en/ref/python/automations/sendwebhook.md @@ -1,43 +1,29 @@ --- title: SendWebhook -namespace: automations_namespace -python_object_type: class --- -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/automations/actions.py >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/actions.py#L167-L189 >}} - - -## class `SendWebhook` Defines an automation action that sends a webhook request. +| Attributes | | +| :--- | :--- | +| `request_payload` | The payload, possibly with template variables, to send in the webhook request. | +| `action_type` | The kind of action to be triggered. | -### method `SendWebhook.__init__` - -```python -__init__( - integration_id: 'str', - request_payload: 'Annotated | None' = None, - action_type: 'Literal[GENERIC_WEBHOOK]' = GENERIC_WEBHOOK -) → None -``` - -**Args:** - - - `integration_id` (str): The ID of the webhook integration that will be used to send the request. - - `request_payload` (Optional[Annotated]): The payload, possibly with template variables, to send in the webhook request. - - `action_type` (Literal[GENERIC_WEBHOOK]): +## Methods -**Returns:** - An `SendWebhook` object. +### `from_integration` -### classmethod `SendWebhook.from_integration` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/automations/actions.py#L181-L189) ```python +@classmethod from_integration( - integration: 'WebhookIntegration', - payload: 'Optional[SerializedToJson[dict[str, Any]]]' = None -) → Self + integration: WebhookIntegration, + *, + payload: Optional[SerializedToJson[dict[str, Any]]] = None +) -> Self ``` Define a webhook action that sends to the given (webhook) integration. diff --git a/content/en/ref/python/controller.md b/content/en/ref/python/controller.md new file mode 100644 index 0000000000..9f423ff83e --- /dev/null +++ b/content/en/ref/python/controller.md @@ -0,0 +1,27 @@ +--- +title: controller +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_sweep.py#L96-L120 >}} + +Public sweep controller constructor. + +```python +controller( + sweep_id_or_config: Optional[Union[str, Dict]] = None, + entity: Optional[str] = None, + project: Optional[str] = None +) -> "_WandbController" +``` + +#### Examples: + +```python +import wandb + +tuner = wandb.controller(...) +print(tuner.sweep_config) +print(tuner.sweep_id) +tuner.configure_search(...) +tuner.configure_stopping(...) +``` diff --git a/content/en/ref/python/data-types/_index.md b/content/en/ref/python/data-types/_index.md index b973d670f4..bfdf86e358 100644 --- a/content/en/ref/python/data-types/_index.md +++ b/content/en/ref/python/data-types/_index.md @@ -1,59 +1,49 @@ --- title: Data Types -module: wandb.sdk.data_types -weight: 2 -no_list: true --- -Data Types in W&B are classes that wrap media and structured data for logging to runs. They include visualization components in the W&B UI and handle data serialization, storage, and retrieval. + -## Available Data Types -| Data Type | Description | -|-----------|-------------| -| [`Image`](./Image/) | Log images with support for masks, bounding boxes, and segmentation. | -| [`Video`](./Video/) | Track video data for model outputs or dataset samples. | -| [`Audio`](./Audio/) | Log audio samples for audio processing tasks. | -| [`Table`](./Table/) | Create tables that can contain mixed media types. | -| [`Plotly`](./Plotly/) | Log Plotly charts for data visualization. | -| [`Html`](./Html/) | Embed custom HTML content. | -| [`Object3D`](./Object3D/) | Visualize 3D point clouds and meshes. | -| [`Molecule`](./Molecule/) | Log molecular structures for computational chemistry. | -## Examples +This module defines data types for logging rich, interactive visualizations to W&B. -This example uses an `Image`: +Data types include common media types, like images, audio, and videos, +flexible containers for information, like tables and HTML, and more. -```python -import wandb -import matplotlib.pyplot as plt +For more on logging media, see [our guide](https://docs.wandb.com/guides/track/log/media) -# Generate an image for demonstration purposes -path_to_img = "/path/to/cafe.png" -im = plt.imread(path_to_img) +For more on logging structured data for interactive dataset and model analysis, +see [our guide to W&B Tables](https://docs.wandb.com/guides/models/tables/). -# Initialize a new run -with wandb.init(project="awesome-project") as run: +All of these special data types are subclasses of WBValue. All the data types +serialize to JSON, since that is what wandb uses to save the objects locally +and upload them to the W&B server. - # Log the image - run.log({"img": [wandb.Image(im, caption="Cafe")]}) -``` +## Classes -This example uses a `Table` to log a table with mixed text and labels: +[`class Audio`](./audio.md): W&B class for audio clips. -```python -import wandb +[`class BoundingBoxes2D`](./boundingboxes2d.md): Format images with 2D bounding box overlays for logging to W&B. -# Initialize a new run -with wandb.init(project="visualize-predictions", name="tables") as run: +[`class Graph`](./graph.md): W&B class for graphs. - # Create tabular data, using a list of lists - data = [["Cat", "1", "1"],["Dog", "0", "-1"]] - run.log({"Table 1": wandb.Table(data=data, columns=["Text", "Predicted Label", "True Label"])}) +[`class Histogram`](./histogram.md): W&B class for histograms. - # Create tabular data, using `wandb.Table.add_data()` method - table = wandb.Table(columns=["Text", "Predicted Label", "True Label"]) - table.add_data("Cat", "1", "1") - table.add_data("Dog", "0", "-1") - run.log({"Table 2": table}) -``` \ No newline at end of file +[`class Html`](./html.md): W&B class for logging HTML content to W&B. + +[`class Image`](./image.md): A class for logging images to W&B. + +[`class ImageMask`](./imagemask.md): Format image masks or overlays for logging to W&B. + +[`class Molecule`](./molecule.md): W&B class for 3D Molecular data. + +[`class Object3D`](./object3d.md): W&B class for 3D point clouds. + +[`class Plotly`](./plotly.md): W&B class for Plotly plots. + +[`class Table`](./table.md): The Table class used to display and analyze tabular data. + +[`class Video`](./video.md): A class for logging videos to W&B. + +[`class WBTraceTree`](./wbtracetree.md): Media object for trace tree data. diff --git a/content/en/ref/python/data-types/audio.md b/content/en/ref/python/data-types/audio.md new file mode 100644 index 0000000000..1e9571b651 --- /dev/null +++ b/content/en/ref/python/data-types/audio.md @@ -0,0 +1,48 @@ +--- +title: Audio +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/audio.py#L17-L200 >}} + +W&B class for audio clips. + +## Methods + +### `durations` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/audio.py#L148-L151) + +```python +@classmethod +durations( + audio_list +) +``` + +Calculate the duration of the audio files. + +### `resolve_ref` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/audio.py#L170-L186) + +```python +resolve_ref() +``` + +Resolve the reference to the actual file path. + + + + +### `sample_rates` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/audio.py#L153-L156) + +```python +@classmethod +sample_rates( + audio_list +) +``` + +Get sample rates of the audio files. diff --git a/content/en/ref/python/data-types/boundingboxes2d.md b/content/en/ref/python/data-types/boundingboxes2d.md new file mode 100644 index 0000000000..fafdd08231 --- /dev/null +++ b/content/en/ref/python/data-types/boundingboxes2d.md @@ -0,0 +1,147 @@ +--- +title: BoundingBoxes2D +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/bounding_boxes_2d.py#L28-L327 >}} + +Format images with 2D bounding box overlays for logging to W&B. + +| Args | | +| :--- | :--- | +| `val` | (dictionary) A dictionary of the following form: box_data: (list of dictionaries) One dictionary for each bounding box, containing: position: (dictionary) the position and size of the bounding box, in one of two formats Note that boxes need not all use the same format. {"minX", "minY", "maxX", "maxY"}: (dictionary) A set of coordinates defining the upper and lower bounds of the box (the bottom left and top right corners) {"middle", "width", "height"}: (dictionary) A set of coordinates defining the center and dimensions of the box, with "middle" as a list [x, y] for the center point and "width" and "height" as numbers domain: (string) One of two options for the bounding box coordinate domain null: By default, or if no argument is passed, the coordinate domain is assumed to be relative to the original image, expressing this box as a fraction or percentage of the original image. This means all coordinates and dimensions passed into the "position" argument are floating point numbers between 0 and 1. "pixel": (string literal) The coordinate domain is set to the pixel space. This means all coordinates and dimensions passed into "position" are integers within the bounds of the image dimensions. class_id: (integer) The class label id for this box scores: (dictionary of string to number, optional) A mapping of named fields to numerical values (float or int), can be used for filtering boxes in the UI based on a range of values for the corresponding field box_caption: (string, optional) A string to be displayed as the label text above this box in the UI, often composed of the class label, class name, and/or scores class_labels: (dictionary, optional) A map of integer class labels to their readable class names | +| `key` | (string) The readable name or id for this set of bounding boxes (e.g. predictions, ground_truth) | + +#### Examples: + +### Log bounding boxes for a single image + +```python +import numpy as np +import wandb + +run = wandb.init() +image = np.random.randint(low=0, high=256, size=(200, 300, 3)) + +class_labels = {0: "person", 1: "car", 2: "road", 3: "building"} + +img = wandb.Image( + image, + boxes={ + "predictions": { + "box_data": [ + { + # one box expressed in the default relative/fractional domain + "position": { + "minX": 0.1, + "maxX": 0.2, + "minY": 0.3, + "maxY": 0.4, + }, + "class_id": 1, + "box_caption": class_labels[1], + "scores": {"acc": 0.2, "loss": 1.2}, + }, + { + # another box expressed in the pixel domain + "position": { + "middle": [150, 20], + "width": 68, + "height": 112, + }, + "domain": "pixel", + "class_id": 3, + "box_caption": "a building", + "scores": {"acc": 0.5, "loss": 0.7}, + }, + # Log as many boxes an as needed + ], + "class_labels": class_labels, + } + }, +) + +run.log({"driving_scene": img}) +``` + +### Log a bounding box overlay to a Table + +```python +import numpy as np +import wandb + +run = wandb.init() +image = np.random.randint(low=0, high=256, size=(200, 300, 3)) + +class_labels = {0: "person", 1: "car", 2: "road", 3: "building"} + +class_set = wandb.Classes( + [ + {"name": "person", "id": 0}, + {"name": "car", "id": 1}, + {"name": "road", "id": 2}, + {"name": "building", "id": 3}, + ] +) + +img = wandb.Image( + image, + boxes={ + "predictions": { + "box_data": [ + { + # one box expressed in the default relative/fractional domain + "position": { + "minX": 0.1, + "maxX": 0.2, + "minY": 0.3, + "maxY": 0.4, + }, + "class_id": 1, + "box_caption": class_labels[1], + "scores": {"acc": 0.2, "loss": 1.2}, + }, + { + # another box expressed in the pixel domain + "position": { + "middle": [150, 20], + "width": 68, + "height": 112, + }, + "domain": "pixel", + "class_id": 3, + "box_caption": "a building", + "scores": {"acc": 0.5, "loss": 0.7}, + }, + # Log as many boxes an as needed + ], + "class_labels": class_labels, + } + }, + classes=class_set, +) + +table = wandb.Table(columns=["image"]) +table.add_data(img) +run.log({"driving_scene": table}) +``` + +## Methods + +### `type_name` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/bounding_boxes_2d.py#L249-L251) + +```python +@classmethod +type_name() -> str +``` + +### `validate` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/bounding_boxes_2d.py#L253-L310) + +```python +validate( + val: dict +) -> bool +``` diff --git a/content/en/ref/python/data-types/graph.md b/content/en/ref/python/data-types/graph.md new file mode 100644 index 0000000000..a0764d0c14 --- /dev/null +++ b/content/en/ref/python/data-types/graph.md @@ -0,0 +1,94 @@ +--- +title: Graph +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L245-L439 >}} + +W&B class for graphs. + +This class is typically used for saving and displaying neural net models. +It represents the graph as an array of nodes and edges. The nodes can have +labels that can be visualized by wandb. + +#### Examples: + +Import a keras model. + +```python +import wandb + +wandb.Graph.from_keras(keras_model) +``` + +## Methods + +### `add_edge` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L354-L362) + +```python +add_edge( + from_node, to_node +) +``` + +Add an edge to the graph. + + + + +### `add_node` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L338-L352) + +```python +add_node( + node=None, **node_kwargs +) +``` + +Add a node to the graph. + + + + +### `from_keras` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L364-L400) + +```python +@classmethod +from_keras( + model +) +``` + +Create a graph from a Keras model. + +This method is not supported for Keras 3.0.0 and above. +Requires a refactor. + +" + +### `pprint` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L328-L336) + +```python +pprint() +``` + +Pretty print the graph. + + + + +### `__getitem__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/graph.py#L325-L326) + +```python +__getitem__( + nid +) +``` diff --git a/content/en/ref/python/data-types/histogram.md b/content/en/ref/python/data-types/histogram.md new file mode 100644 index 0000000000..82224efe29 --- /dev/null +++ b/content/en/ref/python/data-types/histogram.md @@ -0,0 +1,14 @@ +--- +title: Histogram +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/histogram.py#L18-L107 >}} + +W&B class for histograms. + +This object works just like numpy's histogram function +https://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html + +| Class Variables | | +| :--- | :--- | +| `MAX_LENGTH` | `512` | diff --git a/content/en/ref/python/data-types/html.md b/content/en/ref/python/data-types/html.md new file mode 100644 index 0000000000..7c3ffbf48f --- /dev/null +++ b/content/en/ref/python/data-types/html.md @@ -0,0 +1,21 @@ +--- +title: Html +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/html.py#L19-L157 >}} + +W&B class for logging HTML content to W&B. + +## Methods + +### `inject_head` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/html.py#L89-L108) + +```python +inject_head() -> None +``` + +Inject a tag into the HTML. + + diff --git a/content/en/ref/python/data-types/image.md b/content/en/ref/python/data-types/image.md new file mode 100644 index 0000000000..ce18b92244 --- /dev/null +++ b/content/en/ref/python/data-types/image.md @@ -0,0 +1,84 @@ +--- +title: Image +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/image.py#L129-L830 >}} + +A class for logging images to W&B. + +| Attributes | | +| :--- | :--- | + +## Methods + +### `all_boxes` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/image.py#L739-L764) + +```python +@classmethod +all_boxes( + images: Sequence['Image'], + run: "wandb.Run", + run_key: str, + step: Union[int, str] +) -> Union[List[Optional[dict]], bool] +``` + +Collect all boxes from a list of images. + +" + +### `all_captions` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/image.py#L766-L774) + +```python +@classmethod +all_captions( + images: Sequence['Media'] +) -> Union[bool, Sequence[Optional[str]]] +``` + +Get captions from a list of images. + +" + +### `all_masks` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/image.py#L712-L737) + +```python +@classmethod +all_masks( + images: Sequence['Image'], + run: "wandb.Run", + run_key: str, + step: Union[int, str] +) -> Union[List[Optional[dict]], bool] +``` + +Collect all masks from a list of images. + +" + +### `guess_mode` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/image.py#L599-L633) + +```python +guess_mode( + data: Union['np.ndarray', 'torch.Tensor'], + file_type: Optional[str] = None +) -> str +``` + +Guess what type of image the np.array is representing. + + + + +| Class Variables | | +| :--- | :--- | +| `MAX_DIMENSION` | `65500` | +| `MAX_ITEMS` | `108` | diff --git a/content/en/ref/python/data-types/imagemask.md b/content/en/ref/python/data-types/imagemask.md new file mode 100644 index 0000000000..c371bbdd48 --- /dev/null +++ b/content/en/ref/python/data-types/imagemask.md @@ -0,0 +1,126 @@ +--- +title: ImageMask +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/image_mask.py#L18-L251 >}} + +Format image masks or overlays for logging to W&B. + +| Args | | +| :--- | :--- | +| `val` | (dictionary) One of these two keys to represent the image: mask_data : (2D numpy array) The mask containing an integer class label for each pixel in the image path : (string) The path to a saved image file of the mask class_labels : (dictionary of integers to strings, optional) A mapping of the integer class labels in the mask to readable class names. These will default to class_0, class_1, class_2, etc. | +| `key` | (string) The readable name or id for this mask type (e.g. predictions, ground_truth) | + +#### Examples: + +### Logging a single masked image + +```python +import numpy as np +import wandb + +run = wandb.init() +image = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8) +predicted_mask = np.empty((100, 100), dtype=np.uint8) +ground_truth_mask = np.empty((100, 100), dtype=np.uint8) + +predicted_mask[:50, :50] = 0 +predicted_mask[50:, :50] = 1 +predicted_mask[:50, 50:] = 2 +predicted_mask[50:, 50:] = 3 + +ground_truth_mask[:25, :25] = 0 +ground_truth_mask[25:, :25] = 1 +ground_truth_mask[:25, 25:] = 2 +ground_truth_mask[25:, 25:] = 3 + +class_labels = {0: "person", 1: "tree", 2: "car", 3: "road"} + +masked_image = wandb.Image( + image, + masks={ + "predictions": { + "mask_data": predicted_mask, + "class_labels": class_labels, + }, + "ground_truth": { + "mask_data": ground_truth_mask, + "class_labels": class_labels, + }, + }, +) +run.log({"img_with_masks": masked_image}) +``` + +### Log a masked image inside a Table + +```python +import numpy as np +import wandb + +run = wandb.init() +image = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8) +predicted_mask = np.empty((100, 100), dtype=np.uint8) +ground_truth_mask = np.empty((100, 100), dtype=np.uint8) + +predicted_mask[:50, :50] = 0 +predicted_mask[50:, :50] = 1 +predicted_mask[:50, 50:] = 2 +predicted_mask[50:, 50:] = 3 + +ground_truth_mask[:25, :25] = 0 +ground_truth_mask[25:, :25] = 1 +ground_truth_mask[:25, 25:] = 2 +ground_truth_mask[25:, 25:] = 3 + +class_labels = {0: "person", 1: "tree", 2: "car", 3: "road"} + +class_set = wandb.Classes( + [ + {"name": "person", "id": 0}, + {"name": "tree", "id": 1}, + {"name": "car", "id": 2}, + {"name": "road", "id": 3}, + ] +) + +masked_image = wandb.Image( + image, + masks={ + "predictions": { + "mask_data": predicted_mask, + "class_labels": class_labels, + }, + "ground_truth": { + "mask_data": ground_truth_mask, + "class_labels": class_labels, + }, + }, + classes=class_set, +) + +table = wandb.Table(columns=["image"]) +table.add_data(masked_image) +run.log({"random_field": table}) +``` + +## Methods + +### `type_name` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/image_mask.py#L223-L225) + +```python +@classmethod +type_name() -> str +``` + +### `validate` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/helper_types/image_mask.py#L227-L251) + +```python +validate( + val: dict +) -> bool +``` diff --git a/content/en/ref/python/data-types/molecule.md b/content/en/ref/python/data-types/molecule.md new file mode 100644 index 0000000000..0f917d5e8d --- /dev/null +++ b/content/en/ref/python/data-types/molecule.md @@ -0,0 +1,68 @@ +--- +title: Molecule +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/molecule.py#L25-L250 >}} + +W&B class for 3D Molecular data. + +## Methods + +### `from_rdkit` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/molecule.py#L98-L162) + +```python +@classmethod +from_rdkit( + data_or_path: "RDKitDataType", + caption: Optional[str] = None, + convert_to_3d_and_optimize: bool = (True), + mmff_optimize_molecule_max_iterations: int = 200 +) -> "Molecule" +``` + +Convert RDKit-supported file/object types to wandb.Molecule. + +| Args | | +| :--- | :--- | +| `data_or_path` | (string, rdkit.Chem.rdchem.Mol) Molecule can be initialized from a file name or an rdkit.Chem.rdchem.Mol object. | +| `caption` | (string) Caption associated with the molecule for display. | +| `convert_to_3d_and_optimize` | (bool) Convert to rdkit.Chem.rdchem.Mol with 3D coordinates. This is an expensive operation that may take a long time for complicated molecules. | +| `mmff_optimize_molecule_max_iterations` | (int) Number of iterations to use in rdkit.Chem.AllChem.MMFFOptimizeMolecule | + + + + +### `from_smiles` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/molecule.py#L164-L201) + +```python +@classmethod +from_smiles( + data: str, + caption: Optional[str] = None, + sanitize: bool = (True), + convert_to_3d_and_optimize: bool = (True), + mmff_optimize_molecule_max_iterations: int = 200 +) -> "Molecule" +``` + +Convert SMILES string to wandb.Molecule. + +| Args | | +| :--- | :--- | +| `data` | SMILES string. | +| `caption` | Caption associated with the molecule for display. | +| `sanitize` | Check if the molecule is chemically reasonable by the RDKit's definition. | +| `convert_to_3d_and_optimize` | Convert to rdkit.Chem.rdchem.Mol with 3D coordinates. This is a computationally intensive operation that may take a long time for complicated molecules. | +| `mmff_optimize_molecule_max_iterations` | Number of iterations to use in rdkit.Chem.AllChem.MMFFOptimizeMolecule. | + + + + +| Class Variables | | +| :--- | :--- | +| `SUPPORTED_RDKIT_TYPES` | | +| `SUPPORTED_TYPES` | | diff --git a/content/en/ref/python/data-types/object3d.md b/content/en/ref/python/data-types/object3d.md new file mode 100644 index 0000000000..8dc8de2933 --- /dev/null +++ b/content/en/ref/python/data-types/object3d.md @@ -0,0 +1,86 @@ +--- +title: Object3D +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/object_3d.py#L252-L552 >}} + +W&B class for 3D point clouds. + +## Methods + +### `from_file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/object_3d.py#L403-L422) + +```python +@classmethod +from_file( + data_or_path: Union['TextIO', str], + file_type: Optional['FileFormat3D'] = None +) -> "Object3D" +``` + +Initializes Object3D from a file or stream. + +| Args | | +| :--- | :--- | +| data_or_path (Union["TextIO", str]): A path to a file or a `TextIO` stream. file_type (str): Specifies the data format passed to `data_or_path`. Required when `data_or_path` is a `TextIO` stream. This parameter is ignored if a file path is provided. The type is taken from the file extension. | + + + + +### `from_numpy` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/object_3d.py#L424-L456) + +```python +@classmethod +from_numpy( + data: "np.ndarray" +) -> "Object3D" +``` + +Initializes Object3D from a numpy array. + +| Args | | +| :--- | :--- | +| data (numpy array): Each entry in the array will represent one point in the point cloud. | + +The shape of the numpy array must be one of either: + +```text +[[x y z], ...] # nx3. +[[x y z c], ...] # nx4 where c is a category with supported range [1, 14]. +[[x y z r g b], ...] # nx6 where is rgb is color. +``` + + + + +### `from_point_cloud` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/object_3d.py#L458-L494) + +```python +@classmethod +from_point_cloud( + points: Sequence['Point'], + boxes: Sequence['Box3D'], + vectors: Optional[Sequence['Vector3D']] = None, + point_cloud_type: "PointCloudType" = "lidar/beta" +) -> "Object3D" +``` + +Initializes Object3D from a python object. + +| Args | | +| :--- | :--- | +| points (Sequence["Point"]): The points in the point cloud. boxes (Sequence["Box3D"]): 3D bounding boxes for labeling the point cloud. Boxes are displayed in point cloud visualizations. vectors (Optional[Sequence["Vector3D"]]): Each vector is displayed in the point cloud visualization. Can be used to indicate directionality of bounding boxes. Defaults to None. point_cloud_type ("lidar/beta"): At this time, only the "lidar/beta" type is supported. Defaults to "lidar/beta". | + + + + +| Class Variables | | +| :--- | :--- | +| `SUPPORTED_POINT_CLOUD_TYPES` | | +| `SUPPORTED_TYPES` | | diff --git a/content/en/ref/python/data-types/plotly.md b/content/en/ref/python/data-types/plotly.md new file mode 100644 index 0000000000..d64a088974 --- /dev/null +++ b/content/en/ref/python/data-types/plotly.md @@ -0,0 +1,24 @@ +--- +title: Plotly +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/plotly.py#L33-L95 >}} + +W&B class for Plotly plots. + +## Methods + +### `make_plot_media` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/plotly.py#L38-L50) + +```python +@classmethod +make_plot_media( + val: Union['plotly.Figure', 'matplotlib.artist.Artist'] +) -> Union[Image, 'Plotly'] +``` + +Create a Plotly object from a Plotly figure or a matplotlib artist. + + diff --git a/content/en/ref/python/data-types/table.md b/content/en/ref/python/data-types/table.md new file mode 100644 index 0000000000..ed0a6261dd --- /dev/null +++ b/content/en/ref/python/data-types/table.md @@ -0,0 +1,209 @@ +--- +title: Table +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L198-L1067 >}} + +The Table class used to display and analyze tabular data. + +Unlike traditional spreadsheets, Tables support numerous types of data: +scalar values, strings, numpy arrays, and most subclasses of `wandb.data_types.Media`. +This means you can embed `Images`, `Video`, `Audio`, and other sorts of rich, annotated media +directly in Tables, alongside other traditional scalar values. + +This class is the primary class used to generate W&B Tables +https://docs.wandb.ai/guides/models/tables/. + +## Methods + +### `add_column` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L950-L991) + +```python +add_column( + name, data, optional=(False) +) +``` + +Adds a column of data to the table. + +| Args | | +| :--- | :--- | +| `name` | (str) - the unique name of the column | +| `data` | (list | np.array) - a column of homogeneous data | +| `optional` | (bool) - if null-like values are permitted | + +### `add_computed_columns` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L1045-L1067) + +```python +add_computed_columns( + fn +) +``` + +Adds one or more computed columns based on existing data. + +| Args | | +| :--- | :--- | +| `fn` | A function which accepts one or two parameters, ndx (int) and row (dict), which is expected to return a dict representing new columns for that row, keyed by the new column names. - `ndx` is an integer representing the index of the row. Only included if `include_ndx` is set to `True`. - `row` is a dictionary keyed by existing columns | + +### `add_data` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L509-L545) + +```python +add_data( + *data +) +``` + +Adds a new row of data to the table. + +The maximum amount ofrows in a table is determined by +`wandb.Table.MAX_ARTIFACT_ROWS`. + +The length of the data should match the length of the table column. + +### `add_row` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L503-L507) + +```python +add_row( + *row +) +``` + +Deprecated. Use `Table.add_data` method instead. + +### `cast` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L410-L463) + +```python +cast( + col_name, dtype, optional=(False) +) +``` + +Casts a column to a specific data type. + +This can be one of the normal python classes, an internal W&B type, +or an example object, like an instance of wandb.Image or +wandb.Classes. + +| Args | | +| :--- | :--- | +| col_name (str): The name of the column to cast. dtype (class, wandb.wandb_sdk.interface._dtypes.Type, any): The target dtype. optional (bool): If the column should allow Nones. | + +### `get_column` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L993-L1016) + +```python +get_column( + name, convert_to=None +) +``` + +Retrieves a column from the table and optionally converts it to a NumPy object. + +| Args | | +| :--- | :--- | +| `name` | (str) - the name of the column | +| `convert_to` | (str, optional) - "numpy": will convert the underlying data to numpy object | + +### `get_dataframe` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L1027-L1033) + +```python +get_dataframe() +``` + +Returns a `pandas.DataFrame` of the table. + +### `get_index` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L1018-L1025) + +```python +get_index() +``` + +Returns an array of row indexes for use in other tables to create links. + +### `index_ref` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L1035-L1043) + +```python +index_ref( + index +) +``` + +Gets a reference of the index of a row in the table. + + + + +### `iterrows` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L819-L833) + +```python +iterrows() +``` + +Returns the table data by row, showing the index of the row and the relevant data. + +| Yields | | +| :--- | :--- | + +*** + +index: The index of the row. Using this value in other W&B tables +will automatically build a relationship between the tables +row: The data of the row. + + + + +### `set_fk` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L845-L854) + +```python +set_fk( + col_name, table, table_col +) +``` + +Set foreign key type for Table object. + + + + +### `set_pk` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/table.py#L835-L843) + +```python +set_pk( + col_name +) +``` + +Set primary key type for Table object. + + + + +| Class Variables | | +| :--- | :--- | +| `MAX_ARTIFACT_ROWS` | `200000` | +| `MAX_ROWS` | `10000` | diff --git a/content/en/ref/python/data-types/video.md b/content/en/ref/python/data-types/video.md new file mode 100644 index 0000000000..c924419dbb --- /dev/null +++ b/content/en/ref/python/data-types/video.md @@ -0,0 +1,28 @@ +--- +title: Video +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/video.py#L74-L295 >}} + +A class for logging videos to W&B. + +## Methods + +### `encode` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/video.py#L187-L213) + +```python +encode( + fps: int = 4 +) -> None +``` + +Encode the video data to a file. + + + + +| Class Variables | | +| :--- | :--- | +| `EXTS` | | diff --git a/content/en/ref/python/data-types/wbtracetree.md b/content/en/ref/python/data-types/wbtracetree.md new file mode 100644 index 0000000000..e49079a1ad --- /dev/null +++ b/content/en/ref/python/data-types/wbtracetree.md @@ -0,0 +1,11 @@ +--- +title: WBTraceTree +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/data_types/trace_tree.py#L80-L119 >}} + +Media object for trace tree data. + +| Args | | +| :--- | :--- | +| root_span (Span): The root span of the trace tree. model_dict (dict, optional): A dictionary containing the model dump. NOTE: model_dict is a completely-user-defined dict. The UI will render a JSON viewer for this dict, giving special treatment to dictionaries with a `_kind` key. This is because model vendors have such different serialization formats that we need to be flexible here. | diff --git a/content/en/ref/python/finish.md b/content/en/ref/python/finish.md new file mode 100644 index 0000000000..fea501852c --- /dev/null +++ b/content/en/ref/python/finish.md @@ -0,0 +1,29 @@ +--- +title: finish +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L4084-L4105 >}} + +Finish a run and upload any remaining data. + +```python +finish( + exit_code: (int | None) = None, + quiet: (bool | None) = None +) -> None +``` + +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`). + +| Args | | +| :--- | :--- | +| `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 using `wandb.Settings(quiet=...)`. | diff --git a/content/en/ref/python/init.md b/content/en/ref/python/init.md new file mode 100644 index 0000000000..c68139a4e9 --- /dev/null +++ b/content/en/ref/python/init.md @@ -0,0 +1,105 @@ +--- +title: init +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_init.py#L1247-L1601 >}} + +Start a new run to track and log to W&B. + +```python +init( + entity: (str | None) = None, + project: (str | None) = None, + dir: (StrPath | None) = None, + id: (str | None) = None, + name: (str | None) = None, + notes: (str | None) = None, + tags: (Sequence[str] | None) = None, + config: (dict[str, Any] | str | None) = None, + config_exclude_keys: (list[str] | None) = None, + config_include_keys: (list[str] | None) = None, + allow_val_change: (bool | None) = None, + group: (str | None) = None, + job_type: (str | None) = None, + mode: (Literal['online', 'offline', 'disabled', 'shared'] | None) = None, + force: (bool | None) = None, + anonymous: (Literal['never', 'allow', 'must'] | None) = None, + reinit: (bool | Literal[None, 'default', 'return_previous', 'finish_previous', + 'create_new']) = None, + resume: (bool | Literal['allow', 'never', 'must', 'auto'] | None) = None, + resume_from: (str | None) = None, + fork_from: (str | None) = None, + save_code: (bool | None) = None, + tensorboard: (bool | None) = None, + sync_tensorboard: (bool | None) = None, + monitor_gym: (bool | None) = None, + settings: (Settings | dict[str, Any] | None) = None +) -> Run +``` + +In an ML training pipeline, you could add `wandb.init()` to the beginning of +your training script as well as your evaluation script, and each piece would +be tracked as a run in W&B. + +`wandb.init()` spawns a new background process to log data to a run, and it +also syncs data to https://wandb.ai by default, so you can see your results +in real-time. When you're done logging data, call `wandb.Run.finish()` to end the run. +If you don't call `run.finish()`, the run will end when your script exits. + +Run IDs must not contain any of the following special characters `/ \ # ? % :` + +| Args | | +| :--- | :--- | +| `entity` | The username or team name the runs are logged to. The entity must already exist, so ensure you create your account or team in the UI before starting to log runs. If not specified, the run will default your default entity. To change the default entity, go to your settings and update the "Default location to create new projects" under "Default team". | +| `project` | The name of the project under which this run will be logged. If not specified, we use a heuristic to infer the project name based on the system, such as checking the git root or the current program file. If we can't infer the project name, the project will default to `"uncategorized"`. | +| `dir` | The absolute path to the directory where experiment logs and metadata files are stored. If not specified, this defaults to the `./wandb` directory. Note that this does not affect the location where artifacts are stored when calling `download()`. | +| `id` | A unique identifier for this run, used for resuming. It must be unique within the project and cannot be reused once a run is deleted. For a short descriptive name, use the `name` field, or for saving hyperparameters to compare across runs, use `config`. | +| `name` | A short display name for this run, which appears in the UI to help you identify it. By default, we generate a random two-word name allowing easy cross-reference runs from table to charts. Keeping these run names brief enhances readability in chart legends and tables. For saving hyperparameters, we recommend using the `config` field. | +| `notes` | A detailed description of the run, similar to a commit message in Git. Use this argument to capture any context or details that may help you recall the purpose or setup of this run in the future. | +| `tags` | A list of tags to label this run in the UI. Tags are helpful for organizing runs or adding temporary identifiers like "baseline" or "production." You can easily add, remove tags, or filter by tags in the UI. If resuming a run, the tags provided here will replace any existing tags. To add tags to a resumed run without overwriting the current tags, use `run.tags += ("new_tag",)` after calling `run = wandb.init()`. | +| `config` | Sets `wandb.config`, a dictionary-like object for storing input parameters to your run, such as model hyperparameters or data preprocessing settings. The config appears in the UI in an overview page, allowing you to group, filter, and sort runs based on these parameters. Keys should not contain periods (`.`), and values should be smaller than 10 MB. If a dictionary, `argparse.Namespace`, or `absl.flags.FLAGS` is provided, the key-value pairs will be loaded directly into `wandb.config`. If a string is provided, it is interpreted as a path to a YAML file, from which configuration values will be loaded into `wandb.config`. | +| `config_exclude_keys` | A list of specific keys to exclude from `wandb.config`. | +| `config_include_keys` | A list of specific keys to include in `wandb.config`. | +| `allow_val_change` | Controls whether config values can be modified after their initial set. By default, an exception is raised if a config value is overwritten. For tracking variables that change during training, such as a learning rate, consider using `wandb.log()` instead. By default, this is `False` in scripts and `True` in Notebook environments. | +| `group` | Specify a group name to organize individual runs as part of a larger experiment. This is useful for cases like cross-validation or running multiple jobs that train and evaluate a model on different test sets. Grouping allows you to manage related runs collectively in the UI, making it easy to toggle and review results as a unified experiment. | +| `job_type` | Specify the type of run, especially helpful when organizing runs within a group as part of a larger experiment. For example, in a group, you might label runs with job types such as "train" and "eval". Defining job types enables you to easily filter and group similar runs in the UI, facilitating direct comparisons. | +| `mode` | Specifies how run data is managed, with the following options: - `"online"` (default): Enables live syncing with W&B when a network connection is available, with real-time updates to visualizations. - `"offline"`: Suitable for air-gapped or offline environments; data is saved locally and can be synced later. Ensure the run folder is preserved to enable future syncing. - `"disabled"`: Disables all W&B functionality, making the run’s methods no-ops. Typically used in testing to bypass W&B operations. - `"shared"`: (This is an experimental feature). Allows multiple processes, possibly on different machines, to simultaneously log to the same run. In this approach you use a primary node and one or more worker nodes to log data to the same run. Within the primary node you initialize a run. For each worker node, initialize a run using the run ID used by the primary node. | +| `force` | Determines if a W&B login is required to run the script. If `True`, the user must be logged in to W&B; otherwise, the script will not proceed. If `False` (default), the script can proceed without a login, switching to offline mode if the user is not logged in. | +| `anonymous` | Specifies the level of control over anonymous data logging. Available options are: - `"never"` (default): Requires you to link your W&B account before tracking the run. This prevents unintentional creation of anonymous runs by ensuring each run is associated with an account. - `"allow"`: Enables a logged-in user to track runs with their account, but also allows someone running the script without a W&B account to view the charts and data in the UI. - `"must"`: Forces the run to be logged to an anonymous account, even if the user is logged in. | +| `reinit` | Shorthand for the "reinit" setting. Determines the behavior of `wandb.init()` when a run is active. | +| `resume` | Controls the behavior when resuming a run with the specified `id`. Available options are: - `"allow"`: If a run with the specified `id` exists, it will resume from the last step; otherwise, a new run will be created. - `"never"`: If a run with the specified `id` exists, an error will be raised. If no such run is found, a new run will be created. - `"must"`: If a run with the specified `id` exists, it will resume from the last step. If no run is found, an error will be raised. - `"auto"`: Automatically resumes the previous run if it crashed on this machine; otherwise, starts a new run. - `True`: Deprecated. Use `"auto"` instead. - `False`: Deprecated. Use the default behavior (leaving `resume` unset) to always start a new run. If `resume` is set, `fork_from` and `resume_from` cannot be used. When `resume` is unset, the system will always start a new run. | +| `resume_from` | Specifies a moment in a previous run to resume a run from, using the format `{run_id}?_step={step}`. This allows users to truncate the history logged to a run at an intermediate step and resume logging from that step. The target run must be in the same project. If an `id` argument is also provided, the `resume_from` argument will take precedence. `resume`, `resume_from` and `fork_from` cannot be used together, only one of them can be used at a time. Note that this feature is in beta and may change in the future. | +| `fork_from` | Specifies a point in a previous run from which to fork a new run, using the format `{id}?_step={step}`. This creates a new run that resumes logging from the specified step in the target run’s history. The target run must be part of the current project. If an `id` argument is also provided, it must be different from the `fork_from` argument, an error will be raised if they are the same. `resume`, `resume_from` and `fork_from` cannot be used together, only one of them can be used at a time. Note that this feature is in beta and may change in the future. | +| `save_code` | Enables saving the main script or notebook to W&B, aiding in experiment reproducibility and allowing code comparisons across runs in the UI. By default, this is disabled, but you can change the default to enable on your settings page. | +| `tensorboard` | Deprecated. Use `sync_tensorboard` instead. | +| `sync_tensorboard` | Enables automatic syncing of W&B logs from TensorBoard or TensorBoardX, saving relevant event files for viewing in the W&B UI. | +| `monitor_gym` | Enables automatic logging of videos of the environment when using OpenAI Gym. | +| `settings` | Specifies a dictionary or `wandb.Settings` object with advanced settings for the run. | + +| Returns | | +| :--- | :--- | +| A `Run` object. | + +| Raises | | +| :--- | :--- | +| `Error` | If some unknown or internal error happened during the run initialization. | +| `AuthenticationError` | If the user failed to provide valid credentials. | +| `CommError` | If there was a problem communicating with the WandB server. | +| `UsageError` | If the user provided invalid arguments. | +| `KeyboardInterrupt` | If user interrupts the run. | + +#### Examples: + +`wandb.init()` returns a `Run` object. Use the run object to log data, +save artifacts, and manage the run lifecycle. + +```python +import wandb + +config = {"lr": 0.01, "batch_size": 32} +with wandb.init(config=config) as run: + # Log accuracy and loss to the run + acc = 0.95 # Example accuracy + loss = 0.05 # Example loss + run.log({"accuracy": acc, "loss": loss}) +``` diff --git a/content/en/ref/python/launch-library/_index.md b/content/en/ref/python/launch-library/_index.md new file mode 100644 index 0000000000..cbe1e9b771 --- /dev/null +++ b/content/en/ref/python/launch-library/_index.md @@ -0,0 +1,17 @@ +--- +title: launch-library +--- + + + + + +## Classes + +[`class LaunchAgent`](./launchagent.md): Launch agent class which polls run given run queues and launches runs for wandb launch. + +## Functions + +[`launch(...)`](./launch.md): Launch a W&B launch experiment. + +[`launch_add(...)`](./launch_add.md): Enqueue a W&B launch experiment. With either a source uri, job or docker_image. diff --git a/content/en/ref/python/launch-library/launch.md b/content/en/ref/python/launch-library/launch.md new file mode 100644 index 0000000000..0ff7f27f0e --- /dev/null +++ b/content/en/ref/python/launch-library/launch.md @@ -0,0 +1,63 @@ +--- +title: launch +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/_launch.py#L249-L331 >}} + +Launch a W&B launch experiment. + +```python +launch( + api: Api, + job: Optional[str] = None, + entry_point: Optional[List[str]] = None, + version: Optional[str] = None, + name: Optional[str] = None, + resource: Optional[str] = None, + resource_args: Optional[Dict[str, Any]] = None, + project: Optional[str] = None, + entity: Optional[str] = None, + docker_image: Optional[str] = None, + config: Optional[Dict[str, Any]] = None, + synchronous: Optional[bool] = (True), + run_id: Optional[str] = None, + repository: Optional[str] = None +) -> AbstractRun +``` + +| Arguments | | +| :--- | :--- | +| `job` | string reference to a wandb.Job eg: wandb/test/my-job:latest | +| `api` | An instance of a wandb Api from wandb.apis.internal. | +| `entry_point` | Entry point to run within the project. Defaults to using the entry point used in the original run for wandb URIs, or main.py for git repository URIs. | +| `version` | For Git-based projects, either a commit hash or a branch name. | +| `name` | Name run under which to launch the run. | +| `resource` | Execution backend for the run. | +| `resource_args` | Resource related arguments for launching runs onto a remote backend. Will be stored on the constructed launch config under `resource_args`. | +| `project` | Target project to send launched run to | +| `entity` | Target entity to send launched run to | +| `config` | A dictionary containing the configuration for the run. May also contain resource specific arguments under the key "resource_args". | +| `synchronous` | Whether to block while waiting for a run to complete. Defaults to True. Note that if `synchronous` is False and `backend` is "local-container", this method will return, but the current process will block when exiting until the local run completes. If the current process is interrupted, any asynchronous runs launched via this method will be terminated. If `synchronous` is True and the run fails, the current process will error out as well. | +| `run_id` | ID for the run (To ultimately replace the :name: field) | +| `repository` | string name of repository path for remote registry | + +#### Example: + +```python +from wandb.sdk.launch import launch + +job = "wandb/jobs/Hello World:latest" +params = {"epochs": 5} +# Run W&B project and create a reproducible docker environment +# on a local host +api = wandb.apis.internal.Api() +launch(api, job, parameters=params) +``` + +| Returns | | +| :--- | :--- | +| an instance of`wandb.launch.SubmittedRun` exposing information (e.g. run ID) about the launched run. | + +| Raises | | +| :--- | :--- | +| `wandb.exceptions.ExecutionError` If a run launched in blocking mode is unsuccessful. | diff --git a/content/en/ref/python/launch-library/launch_add.md b/content/en/ref/python/launch-library/launch_add.md new file mode 100644 index 0000000000..a6ee8f92d6 --- /dev/null +++ b/content/en/ref/python/launch-library/launch_add.md @@ -0,0 +1,74 @@ +--- +title: launch_add +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/_launch_add.py#L34-L131 >}} + +Enqueue a W&B launch experiment. With either a source uri, job or docker_image. + +```python +launch_add( + uri: Optional[str] = None, + job: Optional[str] = None, + config: Optional[Dict[str, Any]] = None, + template_variables: Optional[Dict[str, Union[float, int, str]]] = None, + project: Optional[str] = None, + entity: Optional[str] = None, + queue_name: Optional[str] = None, + resource: Optional[str] = None, + entry_point: Optional[List[str]] = None, + name: Optional[str] = None, + version: Optional[str] = None, + docker_image: Optional[str] = None, + project_queue: Optional[str] = None, + resource_args: Optional[Dict[str, Any]] = None, + run_id: Optional[str] = None, + build: Optional[bool] = (False), + repository: Optional[str] = None, + sweep_id: Optional[str] = None, + author: Optional[str] = None, + priority: Optional[int] = None +) -> "public.QueuedRun" +``` + +| Arguments | | +| :--- | :--- | +| `uri` | URI of experiment to run. A wandb run uri or a Git repository URI. | +| `job` | string reference to a wandb.Job eg: wandb/test/my-job:latest | +| `config` | A dictionary containing the configuration for the run. May also contain resource specific arguments under the key "resource_args" | +| `template_variables` | A dictionary containing values of template variables for a run queue. Expected format of `{"VAR_NAME": VAR_VALUE}` | +| `project` | Target project to send launched run to | +| `entity` | Target entity to send launched run to | +| `queue` | the name of the queue to enqueue the run to | +| `priority` | the priority level of the job, where 1 is the highest priority | +| `resource` | Execution backend for the run: W&B provides built-in support for "local-container" backend | +| `entry_point` | Entry point to run within the project. Defaults to using the entry point used in the original run for wandb URIs, or main.py for git repository URIs. | +| `name` | Name run under which to launch the run. | +| `version` | For Git-based projects, either a commit hash or a branch name. | +| `docker_image` | The name of the docker image to use for the run. | +| `resource_args` | Resource related arguments for launching runs onto a remote backend. Will be stored on the constructed launch config under `resource_args`. | +| `run_id` | optional string indicating the id of the launched run | +| `build` | optional flag defaulting to false, requires queue to be set if build, an image is created, creates a job artifact, pushes a reference to that job artifact to queue | +| `repository` | optional string to control the name of the remote repository, used when pushing images to a registry | +| `project_queue` | optional string to control the name of the project for the queue. Primarily used for back compatibility with project scoped queues | + +#### Example: + +```python +from wandb.sdk.launch import launch_add + +project_uri = "https://github.com/wandb/examples" +params = {"alpha": 0.5, "l1_ratio": 0.01} +# Run W&B project and create a reproducible docker environment +# on a local host +api = wandb.apis.internal.Api() +launch_add(uri=project_uri, parameters=params) +``` + +| Returns | | +| :--- | :--- | +| an instance of`wandb.api.public.QueuedRun` which gives information about the queued run, or if `wait_until_started` or `wait_until_finished` are called, gives access to the underlying Run information. | + +| Raises | | +| :--- | :--- | +| `wandb.exceptions.LaunchError` if unsuccessful | diff --git a/content/en/ref/python/launch-library/launchagent.md b/content/en/ref/python/launch-library/launchagent.md new file mode 100644 index 0000000000..0fcf2e9e74 --- /dev/null +++ b/content/en/ref/python/launch-library/launchagent.md @@ -0,0 +1,169 @@ +--- +title: LaunchAgent +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L165-L931 >}} + +Launch agent class which polls run given run queues and launches runs for wandb launch. + +| Attributes | | +| :--- | :--- | +| `num_running_jobs` | Return the number of jobs not including schedulers. | +| `num_running_schedulers` | Return just the number of schedulers. | +| `thread_ids` | Returns a list of keys running thread ids for the agent. | + +## Methods + +### `check_sweep_state` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L793-L810) + +```python +check_sweep_state( + launch_spec, api +) +``` + +Check the state of a sweep before launching a run for the sweep. + +### `fail_run_queue_item` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L296-L305) + +```python +fail_run_queue_item( + run_queue_item_id, message, phase, files=None +) +``` + +### `finish_thread_id` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L417-L511) + +```python +finish_thread_id( + thread_id, exception=None +) +``` + +Removes the job from our list for now. + +### `get_job_and_queue` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L915-L922) + +```python +get_job_and_queue() +``` + +### `initialized` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L191-L194) + +```python +@classmethod +initialized() -> bool +``` + +Return whether the agent is initialized. + +### `loop` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L578-L659) + +```python +loop() +``` + +Loop infinitely to poll for jobs and run them. + +| Raises | | +| :--- | :--- | +| `KeyboardInterrupt` | if the agent is requested to stop. | + +### `name` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L181-L189) + +```python +@classmethod +name() -> str +``` + +Return the name of the agent. + +### `pop_from_queue` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L341-L364) + +```python +pop_from_queue( + queue +) +``` + +Pops an item off the runqueue to run as a job. + +| Arguments | | +| :--- | :--- | +| `queue` | Queue to pop from. | + +| Returns | | +| :--- | :--- | +| Item popped off the queue. | + +| Raises | | +| :--- | :--- | +| `Exception` | if there is an error popping from the queue. | + +### `print_status` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L366-L382) + +```python +print_status() -> None +``` + +Prints the current status of the agent. + +### `run_job` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L513-L547) + +```python +run_job( + job, queue, file_saver +) +``` + +Set up project and run the job. + +| Arguments | | +| :--- | :--- | +| `job` | Job to run. | + +### `task_run_job` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L662-L694) + +```python +task_run_job( + launch_spec, job, default_config, api, job_tracker +) +``` + +### `update_status` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/launch/agent/agent.py#L384-L395) + +```python +update_status( + status +) +``` + +Update the status of the agent. + +| Arguments | | +| :--- | :--- | +| `status` | Status to update the agent to. | diff --git a/content/en/ref/python/log.md b/content/en/ref/python/log.md new file mode 100644 index 0000000000..2304c1e558 --- /dev/null +++ b/content/en/ref/python/log.md @@ -0,0 +1,249 @@ +--- +title: log +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1765-L2028 >}} + +Upload run data. + +```python +log( + data: dict[str, Any], + step: (int | None) = None, + commit: (bool | None) = None +) -> None +``` + +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/guides/track/log) for +code snippets, best practices, and more. + +#### Basic usage: + +```python +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/guides/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/guides/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/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/guides/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 +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/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](https://docs.wandb.ai/guides/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 +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 +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) +``` + +| Args | | +| :--- | :--- | +| `data` | 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. | +| `step` | The step number to log. If `None`, 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. If `step` is `None`, then the default is `commit=True`; otherwise, the default is `commit=False`. | + +#### Examples: + +For more and more detailed examples, see +[our guides to logging](https://docs.wandb.com/guides/track/log). + +Basic usage + +```python +import wandb + +with wandb.init() as run: + run.log({"train-loss": 0.5, "accuracy": 0.9 +``` + +Incremental logging + +```python +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 +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 +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 +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 +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 +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 +import wandb + +with wandb.init() as run: + run.log({"pr": wandb.plot.pr_curve(y_test, y_probas, labels)}) +``` + +3D Object + +```python +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")), + ] + } + ) +``` + +| Raises | | +| :--- | :--- | +| `wandb.Error` | If called before `wandb.init()`. | +| `ValueError` | If invalid data is passed. | diff --git a/content/en/ref/python/login.md b/content/en/ref/python/login.md new file mode 100644 index 0000000000..0768a21c9d --- /dev/null +++ b/content/en/ref/python/login.md @@ -0,0 +1,44 @@ +--- +title: login +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_login.py#L41-L90 >}} + +Set up W&B login credentials. + +```python +login( + anonymous: Optional[Literal['must', 'allow', 'never']] = None, + key: Optional[str] = None, + relogin: Optional[bool] = None, + host: Optional[str] = None, + force: Optional[bool] = None, + timeout: Optional[int] = None, + verify: bool = (False), + referrer: Optional[str] = None +) -> bool +``` + +By default, this will only store credentials locally without +verifying them with the W&B server. To verify credentials, pass +`verify=True`. + +| Args | | +| :--- | :--- | +| `anonymous` | Set to "must", "allow", or "never". If set to "must", always log a user in anonymously. If set to "allow", only create an anonymous user if the user isn't already logged in. If set to "never", never log a user anonymously. Default set to "never". Defaults to `None`. | +| `key` | The API key to use. | +| `relogin` | If true, will re-prompt for API key. | +| `host` | The host to connect to. | +| `force` | If true, will force a relogin. | +| `timeout` | Number of seconds to wait for user input. | +| `verify` | Verify the credentials with the W&B server. | +| `referrer` | The referrer to use in the URL login request. | + +| Returns | | +| :--- | :--- | +| `bool` | If `key` is configured. | + +| Raises | | +| :--- | :--- | +| `AuthenticationError` | If `api_key` fails verification with the server. | +| `UsageError` | If `api_key` cannot be configured and no tty. | diff --git a/content/en/ref/python/public-api/_index.md b/content/en/ref/python/public-api/_index.md index a7084d8f44..38d2700f42 100644 --- a/content/en/ref/python/public-api/_index.md +++ b/content/en/ref/python/public-api/_index.md @@ -1,132 +1,31 @@ --- -title: Public API -module: wandb.apis.public -weight: 6 -no_list: true +title: Import & Export API --- -The W&B Public API provides programmatic access to query, export, and update data stored in W&B. Use this API for post-hoc analysis, data export, and programmatic management of runs, artifacts, and sweeps. While the main SDK handles real-time logging during training, the Public API enables you to retrieve historical data, update metadata, manage artifacts, and perform analysis on completed experiments. The main `Api` class serves as the entry point to most functionality. + -{{< readfile file="/_includes/public-api-use.md" >}} -## Available Components -| Component | Description | -|-----------|-------------| -| [`Api`](./api/) | Main entry point for the Public API. Query runs, projects, and artifacts across your organization. | -| [`Runs`](./runs/) | Access and manage individual training runs, including history, logs, and metrics. | -| [`Artifacts`](./artifacts/) | Query and download model artifacts, datasets, and other versioned files. | -| [`Sweeps`](./sweeps/) | Access hyperparameter sweep data and analyze optimization results. | -| [`Projects`](./projects/) | Manage projects and access project-level metadata and settings. | -| [`Reports`](./reports/) | Programmatically access and manage W&B Reports. | -| [`Teams`](./teams/) | Query team information and manage team-level resources. | -| [`Users`](./users/) | Access user profiles and user-specific data. | -| [`Files`](./files/) | Download and manage files associated with runs. | -| [`History`](./history/) | Access detailed time-series metrics logged during training. | -| [`Automations`](./automations/) | Manage automated workflows and actions. | -| [`Integrations`](./integrations/) | Configure and manage third-party integrations. | +## Classes -## Common Use Cases +[`class Api`](./api.md): Used for querying the W&B server. -### Data Export and Analysis -- Export run history as DataFrames for analysis in Jupyter notebooks -- Download metrics for custom visualization or reporting -- Aggregate results across multiple experiments +[`class BetaReport`](./betareport.md): BetaReport is a class associated with reports created in W&B. -### Post-Hoc Updates -- Update run metadata after completion -- Add tags or notes to completed experiments -- Modify run configurations or summaries +[`class File`](./file.md): File saved to W&B. -### Artifact Management -- Query artifacts by version or alias -- Download model checkpoints programmatically -- Track artifact lineage and dependencies +[`class Files`](./files.md): A lazy iterator over a collection of `File` objects. -### Sweep Analysis -- Access sweep results and best performing runs -- Export hyperparameter search results -- Analyze parameter importance +[`class Project`](./project.md): A project is a namespace for runs. -## Authentication +[`class Projects`](./projects.md): An lazy iterator of `Project` objects. -The Public API uses the same authentication mechanism as the Python SDK. You can authenticate in several ways: +[`class Registry`](./registry.md): A single registry in the Registry. -Use the `WANDB_API_KEY` environment variable to set your API key: +[`class Reports`](./reports.md): Reports is a lazy iterator of `BetaReport` objects. -```bash -export WANDB_API_KEY=your_api_key -``` +[`class Run`](./run.md): A single run associated with an entity and project. -Pass the API key directly when initializing the `Api` class: +[`class Runs`](./runs.md): A lazy iterator of `Run` objects associated with a project and optional filter. -```python -api = Api(api_key="your_api_key") -``` - -Or use `wandb.login()` to authenticate the current session: -```python -import wandb - -wandb.login() -api = Api() -``` - - -## Example Usage - - -### Download an Artifact by name and alias - -The following example shows how to retrieve an artifact logged to W&B by its name and alias, and then download its contents. - -```python -import wandb - -api = wandb.Api() -artifact = api.artifact("entity/project/artifact:alias") -artifact.download() -``` - -### Download an Artifact from a registry - -The following example shows how to retrieve a linked artifact from a W&B Registry - -```python -import wandb - -REGISTRY = "" -COLLECTION = "" -VERSION = "" - -api = wandb.Api() -artifact_name = f"wandb-registry-{REGISTRY}/{COLLECTION}:{VERSION}" - -# Fetch the artifact -fetched_artifact = api.artifact(name = artifact_name) - -# Download artifact. Returns path to downloaded contents -downloaded_path = fetched_artifact.download() -``` - -### Query W&B Registry - -Use Mongo-like filters to query W&B Registries, Collections, and Artifacts. The following example demonstrates how to filter collections by name using a regular expression. - -```python -import wandb - -# Initialize wandb API -api = wandb.Api() - -# Filter all collections, independent of registry, that -# contains the string `yolo` in the collection name -collection_filters = { - "name": {"$regex": "yolo"} -} - -# Returns an iterable of all collections that match the filters -collections = api.registries().collections(filter=collection_filters) -``` - -For more information on how to query a registry, collection, or artifact, see the [Find registry items](/guides/registry/search-registry). \ No newline at end of file +[`class Sweep`](./sweep.md): The set of runs associated with the sweep. diff --git a/content/en/ref/python/public-api/api.md b/content/en/ref/python/public-api/api.md index 3d1c1111f7..5c5d9d6e06 100644 --- a/content/en/ref/python/public-api/api.md +++ b/content/en/ref/python/public-api/api.md @@ -1,142 +1,61 @@ --- title: Api -namespace: public_apis_namespace -python_object_type: class --- -{{< readfile file="/_includes/public-api-use.md" >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L151-L2513 >}} -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/apis/public/api.py >}} +Used for querying the W&B server. +#### Examples: - - -## class `Api` -Used for querying the W&B server. - - - -**Examples:** - ```python +```python import wandb wandb.Api() -``` - -### method `Api.__init__` - -```python -__init__( - overrides: Optional[Dict[str, Any]] = None, - timeout: Optional[int] = None, - api_key: Optional[str] = None -) → None ``` -Initialize the API. - - - -**Args:** - - - `overrides`: You can set `base_url` if you are - - `using a W&B server other than `https`: //api.wandb.ai`. You can also set defaults for `entity`, `project`, and `run`. - - `timeout`: HTTP timeout in seconds for API requests. If not specified, the default timeout will be used. - - `api_key`: API key to use for authentication. If not provided, the API key from the current environment or configuration will be used. - - ---- - -### property Api.api_key - -Returns W&B API key. - - - -**Returns:** - - `str | None`: The api_key property value. ---- - -### property Api.client - -Returns the client object. - - - -**Returns:** - - `RetryingClient`: The client property value. ---- - -### property Api.default_entity - -Returns the default W&B entity. - - - -**Returns:** - - `str | None`: The default_entity property value. ---- - -### property Api.user_agent - -Returns W&B public user agent. - - - -**Returns:** - - `str`: The user_agent property value. ---- - -### property Api.viewer - -Returns the viewer object. - +| Attributes | | +| :--- | :--- | +| `client` | Returns the client object. | +| `default_entity` | Returns the default W&B entity. | +| `user_agent` | Returns W&B public user agent. | +| `viewer` | Returns the viewer object. | +## Methods -**Raises:** - - - `ValueError`: If viewer data is not able to be fetched from W&B. - - `requests.RequestException`: If an error occurs while making the graphql request. +### `artifact` - - - - -**Returns:** - - `public.User`: The viewer property value. ---- - -### method `Api.artifact` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1568-L1615) ```python -artifact(name: str, type: Optional[str] = None) +artifact( + name: str, + type: (str | None) = None +) ``` -Returns a single artifact. - - - -**Args:** - - - `name`: The artifact's name. The name of an artifact resembles a filepath that consists, at a minimum, the name of the project the artifact was logged to, the name of the artifact, and the artifact's version or alias. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. If no entity is specified in the name, the Run or API setting's entity is used. - - `type`: The type of artifact to fetch. +Returns a single artifact. +| Args | | +| :--- | :--- | +| `name` | The artifact's name. The name of an artifact resembles a filepath that consists, at a minimum, the name of the project the artifact was logged to, the name of the artifact, and the artifact's version or alias. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. If no entity is specified in the name, the Run or API setting's entity is used. | +| `type` | The type of artifact to fetch. | +| Returns | | +| :--- | :--- | +| An `Artifact` object. | -**Returns:** - An `Artifact` object. +| Raises | | +| :--- | :--- | +| `ValueError` | If the artifact name is not specified. | +| `ValueError` | If the artifact type is specified but does not match the type of the fetched artifact. | +#### Examples: - -**Raises:** - - - `ValueError`: If the artifact name is not specified. - - `ValueError`: If the artifact type is specified but does not match the type of the fetched artifact. - - - -**Examples:** - In the proceeding code snippets "entity", "project", "artifact", "version", and "alias" are placeholders for your W&B entity, name of the project the artifact is in, the name of the artifact, and artifact's version, respectively. +In the proceeding code snippets "entity", "project", "artifact", +"version", and "alias" are placeholders for your W&B entity, name +of the project the artifact is in, the name of the artifact, +and artifact's version, respectively. ```python import wandb @@ -152,42 +71,43 @@ wandb.Api().artifact(name="entity/project/artifact:alias") # Specify the entity, project, artifact's name, and a specific artifact version wandb.Api().artifact(name="entity/project/artifact:version") -``` - - +``` -**Note:** +#### Note: -> This method is intended for external use only. Do not call `api.artifact()` within the wandb repository code. +This method is intended for external use only. Do not call `api.artifact()` within the wandb repository code. ---- +### `artifact_collection` -### method `Api.artifact_collection` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1403-L1457) ```python -artifact_collection(type_name: str, name: str) → public.ArtifactCollection +artifact_collection( + type_name: str, + name: str +) -> ArtifactCollection ``` -Returns a single artifact collection by type. - -You can use the returned `ArtifactCollection` object to retrieve information about specific artifacts in that collection, and more. +Returns a single artifact collection by type. +You can use the returned `ArtifactCollection` object to retrieve +information about specific artifacts in that collection, and more. +| Args | | +| :--- | :--- | +| `type_name` | The type of artifact collection to fetch. | +| `name` | An artifact collection name. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. | -**Args:** - - - `type_name`: The type of artifact collection to fetch. - - `name`: An artifact collection name. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. +| Returns | | +| :--- | :--- | +| An `ArtifactCollection` object. | +#### Examples: - -**Returns:** - An `ArtifactCollection` object. - - - -**Examples:** - In the proceeding code snippet "type", "entity", "project", and "artifact_name" are placeholders for the collection type, your W&B entity, name of the project the artifact is in, and the name of the artifact, respectively. +In the proceeding code snippet "type", "entity", "project", and +"artifact_name" are placeholders for the collection type, your W&B +entity, name of the project the artifact is in, and the name of +the artifact, respectively. ```python import wandb @@ -201,310 +121,307 @@ artifact_example = collections.artifacts()[0] # Download the contents of the artifact to the specified root directory. artifact_example.download() -``` +``` ---- +### `artifact_collection_exists` -### method `Api.artifact_collection_exists` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1752-L1784) ```python -artifact_collection_exists(name: str, type: str) → bool +artifact_collection_exists( + name: str, + type: str +) -> bool ``` -Whether an artifact collection exists within a specified project and entity. - - - -**Args:** - - - `name`: An artifact collection name. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. If entity or project is not specified, infer the collection from the override params if they exist. Otherwise, entity is pulled from the user settings and project will default to "uncategorized". - - `type`: The type of artifact collection. - +Whether an artifact collection exists within a specified project and entity. +| Args | | +| :--- | :--- | +| `name` | An artifact collection name. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. If entity or project is not specified, infer the collection from the override params if they exist. Otherwise, entity is pulled from the user settings and project will default to "uncategorized". | +| `type` | The type of artifact collection. | -**Returns:** - True if the artifact collection exists, False otherwise. +| Returns | | +| :--- | :--- | +| True if the artifact collection exists, False otherwise. | +#### Examples: - -**Examples:** - In the proceeding code snippet "type", and "collection_name" refer to the type of the artifact collection and the name of the collection, respectively. +In the proceeding code snippet "type", and "collection_name" refer to the type +of the artifact collection and the name of the collection, respectively. ```python import wandb wandb.Api.artifact_collection_exists(type="type", name="collection_name") -``` +``` ---- +### `artifact_collections` -### method `Api.artifact_collections` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1374-L1401) ```python artifact_collections( project_name: str, type_name: str, per_page: int = 50 -) → public.ArtifactCollections +) -> ArtifactCollections ``` -Returns a collection of matching artifact collections. - - +Returns a collection of matching artifact collections. -**Args:** - - - `project_name`: The name of the project to filter on. - - `type_name`: The name of the artifact type to filter on. - - `per_page`: Sets the page size for query pagination. None will use the default size. Usually there is no reason to change this. +| Args | | +| :--- | :--- | +| `project_name` | The name of the project to filter on. | +| `type_name` | The name of the artifact type to filter on. | +| `per_page` | Sets the page size for query pagination. None will use the default size. Usually there is no reason to change this. | +| Returns | | +| :--- | :--- | +| An iterable `ArtifactCollections` object. | +### `artifact_exists` -**Returns:** - An iterable `ArtifactCollections` object. - ---- - -### method `Api.artifact_exists` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1714-L1750) ```python -artifact_exists(name: str, type: Optional[str] = None) → bool +artifact_exists( + name: str, + type: (str | None) = None +) -> bool ``` -Whether an artifact version exists within the specified project and entity. - +Whether an artifact version exists within the specified project and entity. +| Args | | +| :--- | :--- | +| `name` | The name of artifact. Add the artifact's entity and project as a prefix. Append the version or the alias of the artifact with a colon. If the entity or project is not specified, W&B uses override parameters if populated. Otherwise, the entity is pulled from the user settings and the project is set to "Uncategorized". | +| `type` | The type of artifact. | -**Args:** - - - `name`: The name of artifact. Add the artifact's entity and project as a prefix. Append the version or the alias of the artifact with a colon. If the entity or project is not specified, W&B uses override parameters if populated. Otherwise, the entity is pulled from the user settings and the project is set to "Uncategorized". - - `type`: The type of artifact. +| Returns | | +| :--- | :--- | +| True if the artifact version exists, False otherwise. | +#### Examples: - -**Returns:** - True if the artifact version exists, False otherwise. - - - -**Examples:** - In the proceeding code snippets "entity", "project", "artifact", "version", and "alias" are placeholders for your W&B entity, name of the project the artifact is in, the name of the artifact, and artifact's version, respectively. +In the proceeding code snippets "entity", "project", "artifact", +"version", and "alias" are placeholders for your W&B entity, name of +the project the artifact is in, the name of the artifact, and +artifact's version, respectively. ```python import wandb wandb.Api().artifact_exists("entity/project/artifact:version") wandb.Api().artifact_exists("entity/project/artifact:alias") -``` +``` ---- +### `artifact_type` -### method `Api.artifact_type` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1350-L1372) ```python artifact_type( type_name: str, - project: Optional[str] = None -) → public.ArtifactType + project: (str | None) = None +) -> ArtifactType ``` -Returns the matching `ArtifactType`. +Returns the matching `ArtifactType`. +| Args | | +| :--- | :--- | +| `type_name` | The name of the artifact type to retrieve. | +| `project` | If given, a project name or path to filter on. | +| Returns | | +| :--- | :--- | +| An `ArtifactType` object. | -**Args:** - - - `type_name`: The name of the artifact type to retrieve. - - `project`: If given, a project name or path to filter on. - - - -**Returns:** - An `ArtifactType` object. - ---- +### `artifact_types` -### method `Api.artifact_types` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1327-L1348) ```python -artifact_types(project: Optional[str] = None) → public.ArtifactTypes +artifact_types( + project: (str | None) = None +) -> ArtifactTypes ``` -Returns a collection of matching artifact types. +Returns a collection of matching artifact types. +| Args | | +| :--- | :--- | +| `project` | The project name or path to filter on. | +| Returns | | +| :--- | :--- | +| An iterable `ArtifactTypes` object. | -**Args:** - - - `project`: The project name or path to filter on. +### `artifact_versions` - - -**Returns:** - An iterable `ArtifactTypes` object. - ---- - -### method `Api.artifact_versions` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1459-L1469) ```python -artifact_versions(type_name, name, per_page=50) +artifact_versions( + type_name, name, per_page=50 +) ``` -Deprecated. Use `Api.artifacts(type_name, name)` method instead. +Deprecated. Use `Api.artifacts(type_name, name)` method instead. ---- +### `artifacts` -### method `Api.artifacts` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1471-L1524) ```python artifacts( type_name: str, name: str, per_page: int = 50, - tags: Optional[List[str]] = None -) → public.Artifacts + tags: (list[str] | None) = None +) -> Artifacts ``` -Return an `Artifacts` collection. - - - -**Args:** - type_name: The type of artifacts to fetch. name: The artifact's collection name. Optionally append the entity that logged the artifact as a prefix followed by a forward slash. per_page: Sets the page size for query pagination. If set to `None`, use the default size. Usually there is no reason to change this. tags: Only return artifacts with all of these tags. +Return an `Artifacts` collection. +| Args | | +| :--- | :--- | +type_name: The type of artifacts to fetch. +name: The artifact's collection name. Optionally append the +entity that logged the artifact as a prefix followed by +a forward slash. +per_page: Sets the page size for query pagination. If set to +`None`, use the default size. Usually there is no reason +to change this. +tags: Only return artifacts with all of these tags. -**Returns:** - An iterable `Artifacts` object. +| Returns | | +| :--- | :--- | +| An iterable `Artifacts` object. | +#### Examples: - -**Examples:** - In the proceeding code snippet, "type", "entity", "project", and "artifact_name" are placeholders for the artifact type, W&B entity, name of the project the artifact was logged to, and the name of the artifact, respectively. +In the proceeding code snippet, "type", "entity", "project", and +"artifact_name" are placeholders for the artifact type, W&B entity, +name of the project the artifact was logged to, +and the name of the artifact, respectively. ```python import wandb wandb.Api().artifacts(type_name="type", name="entity/project/artifact_name") -``` +``` ---- +### `automation` -### method `Api.automation` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2154-L2190) ```python -automation(name: str, entity: Optional[str] = None) → Automation +automation( + name: str, + *, + entity: (str | None) = None +) -> Automation ``` -Returns the only Automation matching the parameters. - - +Returns the only Automation matching the parameters. -**Args:** - - - `name`: The name of the automation to fetch. - - `entity`: The entity to fetch the automation for. +| Args | | +| :--- | :--- | +| `name` | The name of the automation to fetch. | +| `entity` | The entity to fetch the automation for. | +| Raises | | +| :--- | :--- | +| `ValueError` | If zero or multiple Automations match the search criteria. | +#### Examples: -**Raises:** - - - `ValueError`: If zero or multiple Automations match the search criteria. - - - -**Examples:** - Get an existing automation named "my-automation": +Get an existing automation named "my-automation": ```python import wandb api = wandb.Api() automation = api.automation(name="my-automation") -``` +``` -Get an existing automation named "other-automation", from the entity "my-team": +Get an existing automation named "other-automation", from the entity "my-team": ```python automation = api.automation(name="other-automation", entity="my-team") -``` +``` ---- +### `automations` -### method `Api.automations` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2192-L2247) ```python automations( - entity: Optional[str] = None, - name: Optional[str] = None, + entity: (str | None) = None, + *, + name: (str | None) = None, per_page: int = 50 -) → Iterator[ForwardRef('Automation')] +) -> Iterator[Automation] ``` -Returns an iterator over all Automations that match the given parameters. - -If no parameters are provided, the returned iterator will contain all Automations that the user has access to. - - - -**Args:** - - - `entity`: The entity to fetch the automations for. - - `name`: The name of the automation to fetch. - - `per_page`: The number of automations to fetch per page. Defaults to 50. Usually there is no reason to change this. +Returns an iterator over all Automations that match the given parameters. +If no parameters are provided, the returned iterator will contain all +Automations that the user has access to. +| Args | | +| :--- | :--- | +| `entity` | The entity to fetch the automations for. | +| `name` | The name of the automation to fetch. | +| `per_page` | The number of automations to fetch per page. Defaults to 50. Usually there is no reason to change this. | -**Returns:** - A list of automations. +| Returns | | +| :--- | :--- | +| A list of automations. | +#### Examples: - -**Examples:** - Fetch all existing automations for the entity "my-team": +Fetch all existing automations for the entity "my-team": ```python import wandb api = wandb.Api() automations = api.automations(entity="my-team") -``` +``` ---- +### `create_automation` -### method `Api.create_automation` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2249-L2355) ```python create_automation( - obj: 'NewAutomation', - fetch_existing: bool = False, - **kwargs: typing_extensions.Unpack[ForwardRef('WriteAutomationsKwargs')] -) → Automation + obj: NewAutomation, + *, + fetch_existing: bool = (False), + **kwargs +) -> Automation ``` -Create a new Automation. - - +Create a new Automation. -**Args:** - obj: The automation to create. fetch_existing: If True, and a conflicting automation already exists, attempt to fetch the existing automation instead of raising an error. **kwargs: Any additional values to assign to the automation before creating it. If given, these will override any values that may already be set on the automation: - - `name`: The name of the automation. - - `description`: The description of the automation. - - `enabled`: Whether the automation is enabled. - - `scope`: The scope of the automation. - - `event`: The event that triggers the automation. - - `action`: The action that is triggered by the automation. +| Args | | +| :--- | :--- | +| `obj` | The automation to create. | +| `fetch_existing` | If True, and a conflicting automation already exists, attempt to fetch the existing automation instead of raising an error. | +| `**kwargs` | Any additional values to assign to the automation before creating it. If given, these will override any values that may already be set on the automation: - `name`: The name of the automation. - `description`: The description of the automation. - `enabled`: Whether the automation is enabled. - `scope`: The scope of the automation. - `event`: The event that triggers the automation. - `action`: The action that is triggered by the automation. | +| Returns | | +| :--- | :--- | +| The saved Automation. | +#### Examples: -**Returns:** - The saved Automation. - - - -**Examples:** - Create a new automation named "my-automation" that sends a Slack notification when a run within a specific project logs a metric exceeding a custom threshold: +Create a new automation named "my-automation" that sends a Slack notification +when a run within a specific project logs a metric exceeding a custom threshold: ```python import wandb @@ -518,21 +435,21 @@ project = api.project("my-project", entity="my-team") slack_hook = next(api.slack_integrations(entity="my-team")) event = OnRunMetric( - scope=project, - filter=RunEvent.metric("custom-metric") > 10, + scope=project, + filter=RunEvent.metric("custom-metric") > 10, ) action = SendNotification.from_integration(slack_hook) automation = api.create_automation( - event >> action, - name="my-automation", - description="Send a Slack message whenever 'custom-metric' exceeds 10.", + event >> action, + name="my-automation", + description="Send a Slack message whenever 'custom-metric' exceeds 10.", ) -``` +``` ---- +### `create_custom_chart` -### method `Api.create_custom_chart` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L556-L633) ```python create_custom_chart( @@ -541,129 +458,115 @@ create_custom_chart( display_name: str, spec_type: Literal['vega2'], access: Literal['private', 'public'], - spec: Union[str, dict] -) → str + spec: (str | dict) +) -> str ``` -Create a custom chart preset and return its id. - - - -**Args:** - - - `entity`: The entity (user or team) that owns the chart - - `name`: Unique identifier for the chart preset - - `display_name`: Human-readable name shown in the UI - - `spec_type`: Type of specification. Must be "vega2" for Vega-Lite v2 specifications. - - `access`: Access level for the chart: - - "private": Chart is only accessible to the entity that created it - - "public": Chart is publicly accessible - - `spec`: The Vega/Vega-Lite specification as a dictionary or JSON string - - - -**Returns:** - The ID of the created chart preset in the format "entity/name" +Create a custom chart preset and return its id. +| Args | | +| :--- | :--- | +| `entity` | The entity (user or team) that owns the chart | +| `name` | Unique identifier for the chart preset | +| `display_name` | Human-readable name shown in the UI | +| `spec_type` | Type of specification. Must be "vega2" for Vega-Lite v2 specifications. | +| `access` | Access level for the chart: - "private": Chart is only accessible to the entity that created it - "public": Chart is publicly accessible | +| `spec` | The Vega/Vega-Lite specification as a dictionary or JSON string | +| Returns | | +| :--- | :--- | +| The ID of the created chart preset in the format "entity/name" | -**Raises:** - - - `wandb.Error`: If chart creation fails - - `UnsupportedError`: If the server doesn't support custom charts +| Raises | | +| :--- | :--- | +| `wandb.Error` | If chart creation fails | +| `UnsupportedError` | If the server doesn't support custom charts | +#### Example: +```python +import wandb -**Example:** - ```python - import wandb - - api = wandb.Api() - - # Define a simple bar chart specification - vega_spec = { - "$schema": "https://vega.github.io/schema/vega-lite/v6.json", - "mark": "bar", - "data": {"name": "wandb"}, - "encoding": { - "x": {"field": "${field:x}", "type": "ordinal"}, - "y": {"field": "${field:y}", "type": "quantitative"}, - }, - } +api = wandb.Api() - # Create the custom chart - chart_id = api.create_custom_chart( - entity="my-team", - name="my-bar-chart", - display_name="My Custom Bar Chart", - spec_type="vega2", - access="private", - spec=vega_spec, - ) +# Define a simple bar chart specification +vega_spec = { + "$schema": "https://vega.github.io/schema/vega-lite/v6.json", + "mark": "bar", + "data": {"name": "wandb"}, + "encoding": { + "x": {"field": "${field:x}", "type": "ordinal"}, + "y": {"field": "${field:y}", "type": "quantitative"}, + }, +} + +# Create the custom chart +chart_id = api.create_custom_chart( + entity="my-team", + name="my-bar-chart", + display_name="My Custom Bar Chart", + spec_type="vega2", + access="private", + spec=vega_spec, +) - # Use with wandb.plot_table() - chart = wandb.plot_table( - vega_spec_name=chart_id, - data_table=my_table, - fields={"x": "category", "y": "value"}, - ) - ``` +# Use with wandb.plot_table() +chart = wandb.plot_table( + vega_spec_name=chart_id, + data_table=my_table, + fields={"x": "category", "y": "value"}, +) +``` ---- +### `create_project` -### method `Api.create_project` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L416-L423) ```python -create_project(name: str, entity: str) → None +create_project( + name: str, + entity: str +) -> None ``` -Create a new project. - - +Create a new project. -**Args:** - - - `name`: The name of the new project. - - `entity`: The entity of the new project. +| Args | | +| :--- | :--- | +| `name` | The name of the new project. | +| `entity` | The entity of the new project. | ---- +### `create_registry` -### method `Api.create_registry` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1894-L1967) ```python create_registry( name: str, visibility: Literal['organization', 'restricted'], - organization: Optional[str] = None, - description: Optional[str] = None, - artifact_types: Optional[List[str]] = None -) → Registry + organization: (str | None) = None, + description: (str | None) = None, + artifact_types: (list[str] | None) = None +) -> Registry ``` -Create a new registry. - - +Create a new registry. -**Args:** - - - `name`: The name of the registry. Name must be unique within the organization. - - `visibility`: The visibility of the registry. - - `organization`: Anyone in the organization can view this registry. You can edit their roles later from the settings in the UI. - - `restricted`: Only invited members via the UI can access this registry. Public sharing is disabled. - - `organization`: The organization of the registry. If no organization is set in the settings, the organization will be fetched from the entity if the entity only belongs to one organization. - - `description`: The description of the registry. - - `artifact_types`: The accepted artifact types of the registry. A type is no - - `more than 128 characters and do not include characters `/` or ``: `. If not specified, all types are accepted. Allowed types added to the registry cannot be removed later. +| Args | | +| :--- | :--- | +| `name` | The name of the registry. Name must be unique within the organization. | +| `visibility` | The visibility of the registry. organization: Anyone in the organization can view this registry. You can edit their roles later from the settings in the UI. restricted: Only invited members via the UI can access this registry. Public sharing is disabled. | +| `organization` | The organization of the registry. If no organization is set in the settings, the organization will be fetched from the entity if the entity only belongs to one organization. | +| `description` | The description of the registry. | +| `artifact_types` | The accepted artifact types of the registry. A type is no more than 128 characters and do not include characters `/` or `:`. If not specified, all types are accepted. Allowed types added to the registry cannot be removed later. | +| Returns | | +| :--- | :--- | +| A registry object. | +#### Examples: -**Returns:** - A registry object. - - - -**Examples:** - ```python +```python import wandb api = wandb.Api() @@ -674,180 +577,174 @@ registry = api.create_registry( description="This is a test registry", artifact_types=["model"], ) -``` +``` ---- +### `create_run` -### method `Api.create_run` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L425-L447) ```python create_run( - run_id: Optional[str] = None, - project: Optional[str] = None, - entity: Optional[str] = None -) → public.Run + *, + run_id: (str | None) = None, + project: (str | None) = None, + entity: (str | None) = None +) -> public.Run ``` -Create a new run. - - - -**Args:** - - - `run_id`: The ID to assign to the run. If not specified, W&B creates a random ID. - - `project`: The project where to log the run to. If no project is specified, log the run to a project called "Uncategorized". - - `entity`: The entity that owns the project. If no entity is specified, log the run to the default entity. - +Create a new run. +| Args | | +| :--- | :--- | +| `run_id` | The ID to assign to the run. If not specified, W&B creates a random ID. | +| `project` | The project where to log the run to. If no project is specified, log the run to a project called "Uncategorized". | +| `entity` | The entity that owns the project. If no entity is specified, log the run to the default entity. | -**Returns:** - The newly created `Run`. +| Returns | | +| :--- | :--- | +| The newly created `Run`. | ---- +### `create_run_queue` -### method `Api.create_run_queue` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L449-L554) ```python create_run_queue( name: str, - type: 'public.RunQueueResourceType', - entity: Optional[str] = None, - prioritization_mode: Optional[ForwardRef('public.RunQueuePrioritizationMode')] = None, - config: Optional[dict] = None, - template_variables: Optional[dict] = None -) → public.RunQueue + type: public.RunQueueResourceType, + entity: (str | None) = None, + prioritization_mode: (public.RunQueuePrioritizationMode | None) = None, + config: (dict | None) = None, + template_variables: (dict | None) = None +) -> public.RunQueue ``` -Create a new run queue in W&B Launch. - - - -**Args:** - - - `name`: Name of the queue to create - - `type`: Type of resource to be used for the queue. One of "local-container", "local-process", "kubernetes","sagemaker", or "gcp-vertex". - - `entity`: Name of the entity to create the queue. If `None`, use the configured or default entity. - - `prioritization_mode`: Version of prioritization to use. Either "V0" or `None`. - - `config`: Default resource configuration to be used for the queue. Use handlebars (eg. `{{var}}`) to specify template variables. - - `template_variables`: A dictionary of template variable schemas to use with the config. - +Create a new run queue in W&B Launch. +| Args | | +| :--- | :--- | +| `name` | Name of the queue to create | +| `type` | Type of resource to be used for the queue. One of "local-container", "local-process", "kubernetes","sagemaker", or "gcp-vertex". | +| `entity` | Name of the entity to create the queue. If `None`, use the configured or default entity. | +| `prioritization_mode` | Version of prioritization to use. Either "V0" or `None`. | +| `config` | Default resource configuration to be used for the queue. Use handlebars (eg. `{{var}}`) to specify template variables. | +| `template_variables` | A dictionary of template variable schemas to use with the config. | -**Returns:** - The newly created `RunQueue`. +| Returns | | +| :--- | :--- | +| The newly created `RunQueue`. | +| Raises | | +| :--- | :--- | +| `ValueError` if any of the parameters are invalid `wandb.Error` on wandb API errors | +### `create_team` -**Raises:** - `ValueError` if any of the parameters are invalid `wandb.Error` on wandb API errors - ---- - -### method `Api.create_team` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1050-L1063) ```python -create_team(team: str, admin_username: Optional[str] = None) → public.Team +create_team( + team: str, + admin_username: (str | None) = None +) -> Team ``` -Create a new team. +Create a new team. +| Args | | +| :--- | :--- | +| `team` | The name of the team | +| `admin_username` | Username of the admin user of the team. Defaults to the current user. | +| Returns | | +| :--- | :--- | +| A `Team` object. | -**Args:** - - - `team`: The name of the team - - `admin_username`: Username of the admin user of the team. Defaults to the current user. +### `create_user` - - -**Returns:** - A `Team` object. - ---- - -### method `Api.create_user` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L744-L756) ```python -create_user(email: str, admin: Optional[bool] = False) +create_user( + email: str, + admin: (bool | None) = (False) +) -> User ``` -Create a new user. - +Create a new user. +| Args | | +| :--- | :--- | +| `email` | The email address of the user. | +| `admin` | Set user as a global instance administrator. | -**Args:** - - - `email`: The email address of the user. - - `admin`: Set user as a global instance administrator. +| Returns | | +| :--- | :--- | +| A `User` object. | +### `delete_automation` - -**Returns:** - A `User` object. - ---- - -### method `Api.delete_automation` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2480-L2513) ```python -delete_automation(obj: Union[ForwardRef('Automation'), str]) → Literal[True] +delete_automation( + obj: (Automation | str) +) -> Literal[True] ``` -Delete an automation. - - - -**Args:** - - - `obj`: The automation to delete, or its ID. +Delete an automation. +| Args | | +| :--- | :--- | +| `obj` | The automation to delete, or its ID. | +| Returns | | +| :--- | :--- | +| True if the automation was deleted successfully. | -**Returns:** - True if the automation was deleted successfully. +### `flush` ---- - -### method `Api.flush` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L823-L830) ```python flush() ``` -Flush the local cache. +Flush the local cache. -The api object keeps a local cache of runs, so if the state of the run may change while executing your script you must clear the local cache with `api.flush()` to get the latest values associated with the run. +The api object keeps a local cache of runs, so if the state of the run +may change while executing your script you must clear the local cache +with `api.flush()` to get the latest values associated with the run. ---- +### `from_path` -### method `Api.from_path` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L832-L894) ```python -from_path(path: str) +from_path( + path: str +) ``` -Return a run, sweep, project or report from a path. - +Return a run, sweep, project or report from a path. +| Args | | +| :--- | :--- | +| `path` | The path to the project, run, sweep or report | -**Args:** - - - `path`: The path to the project, run, sweep or report +| Returns | | +| :--- | :--- | +| A `Project`, `Run`, `Sweep`, or `BetaReport` instance. | +| Raises | | +| :--- | :--- | +| `wandb.Error` if path is invalid or the object doesn't exist. | +#### Examples: -**Returns:** - A `Project`, `Run`, `Sweep`, or `BetaReport` instance. - - - -**Raises:** - `wandb.Error` if path is invalid or the object doesn't exist. - - - -**Examples:** - In the proceeding code snippets "project", "team", "run_id", "sweep_id", and "report_name" are placeholders for the project, team, run ID, sweep ID, and the name of a specific report, respectively. +In the proceeding code snippets "project", "team", "run_id", "sweep_id", +and "report_name" are placeholders for the project, team, run ID, +sweep ID, and the name of a specific report, respectively. ```python import wandb @@ -859,125 +756,122 @@ team_project = api.from_path("team/project") run = api.from_path("team/project/runs/run_id") sweep = api.from_path("team/project/sweeps/sweep_id") report = api.from_path("team/project/reports/report_name") -``` +``` ---- +### `integrations` -### method `Api.integrations` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1969-L1991) ```python integrations( - entity: Optional[str] = None, + entity: (str | None) = None, + *, per_page: int = 50 -) → Iterator[ForwardRef('Integration')] +) -> Iterator[Integration] ``` -Return an iterator of all integrations for an entity. - +Return an iterator of all integrations for an entity. +| Args | | +| :--- | :--- | +| `entity` | The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. | +| `per_page` | Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. | -**Args:** - - - `entity`: The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. - - `per_page`: Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. +| Yields | | +| :--- | :--- | +| Iterator[SlackIntegration | WebhookIntegration]: An iterator of any supported integrations. | +### `job` - -**Yields:** - - - `Iterator[SlackIntegration | WebhookIntegration]`: An iterator of any supported integrations. - ---- - -### method `Api.job` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1617-L1634) ```python -job(name: Optional[str], path: Optional[str] = None) → public.Job +job( + name: (str | None), + path: (str | None) = None +) -> public.Job ``` -Return a `Job` object. - - - -**Args:** - - - `name`: The name of the job. - - `path`: The root path to download the job artifact. +Return a `Job` object. +| Args | | +| :--- | :--- | +| `name` | The name of the job. | +| `path` | The root path to download the job artifact. | +| Returns | | +| :--- | :--- | +| A `Job` object. | -**Returns:** - A `Job` object. +### `list_jobs` ---- - -### method `Api.list_jobs` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1636-L1712) ```python -list_jobs(entity: str, project: str) → List[Dict[str, Any]] +list_jobs( + entity: str, + project: str +) -> list[dict[str, Any]] ``` -Return a list of jobs, if any, for the given entity and project. - - +Return a list of jobs, if any, for the given entity and project. -**Args:** - - - `entity`: The entity for the listed jobs. - - `project`: The project for the listed jobs. +| Args | | +| :--- | :--- | +| `entity` | The entity for the listed jobs. | +| `project` | The project for the listed jobs. | +| Returns | | +| :--- | :--- | +| A list of matching jobs. | +### `project` -**Returns:** - A list of matching jobs. - ---- - -### method `Api.project` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L979-L1003) ```python -project(name: str, entity: Optional[str] = None) → public.Project +project( + name: str, + entity: (str | None) = None +) -> public.Project ``` -Return the `Project` with the given name (and entity, if given). - - +Return the `Project` with the given name (and entity, if given). -**Args:** - - - `name`: The project name. - - `entity`: Name of the entity requested. If None, will fall back to the default entity passed to `Api`. If no default entity, will raise a `ValueError`. +| Args | | +| :--- | :--- | +| `name` | The project name. | +| `entity` | Name of the entity requested. If None, will fall back to the default entity passed to `Api`. If no default entity, will raise a `ValueError`. | +| Returns | | +| :--- | :--- | +| A `Project` object. | +### `projects` -**Returns:** - A `Project` object. - ---- - -### method `Api.projects` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L952-L977) ```python -projects(entity: Optional[str] = None, per_page: int = 200) → public.Projects +projects( + entity: (str | None) = None, + per_page: int = 200 +) -> public.Projects ``` -Get projects for a given entity. - - +Get projects for a given entity. -**Args:** - - - `entity`: Name of the entity requested. If None, will fall back to the default entity passed to `Api`. If no default entity, will raise a `ValueError`. - - `per_page`: Sets the page size for query pagination. If set to `None`, use the default size. Usually there is no reason to change this. +| Args | | +| :--- | :--- | +| `entity` | Name of the entity requested. If None, will fall back to the default entity passed to `Api`. If no default entity, will raise a `ValueError`. | +| `per_page` | Sets the page size for query pagination. If set to `None`, use the default size. Usually there is no reason to change this. | +| Returns | | +| :--- | :--- | +| A `Projects` object which is an iterable collection of `Project`objects. | +### `queued_run` -**Returns:** - A `Projects` object which is an iterable collection of `Project`objects. - ---- - -### method `Api.queued_run` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1271-L1292) ```python queued_run( @@ -990,97 +884,93 @@ queued_run( ) ``` -Return a single queued run based on the path. +Return a single queued run based on the path. -Parses paths of the form `entity/project/queue_id/run_queue_item_id`. +Parses paths of the form `entity/project/queue_id/run_queue_item_id`. ---- +### `registries` -### method `Api.registries` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1786-L1852) ```python registries( - organization: Optional[str] = None, - filter: Optional[Dict[str, Any]] = None -) → Registries + organization: (str | None) = None, + filter: (dict[str, Any] | None) = None +) -> Registries ``` -Returns a lazy iterator of `Registry` objects. - -Use the iterator to search and filter registries, collections, or artifact versions across your organization's registry. +Returns a lazy iterator of `Registry` objects. +Use the iterator to search and filter registries, collections, +or artifact versions across your organization's registry. +| Args | | +| :--- | :--- | +| `organization` | (str, optional) The organization of the registry to fetch. If not specified, use the organization specified in the user's settings. | +| `filter` | (dict, optional) MongoDB-style filter to apply to each object in the lazy registry iterator. Fields available to filter for registries are `name`, `description`, `created_at`, `updated_at`. Fields available to filter for collections are `name`, `tag`, `description`, `created_at`, `updated_at` Fields available to filter for versions are `tag`, `alias`, `created_at`, `updated_at`, `metadata` | -**Args:** - - - `organization`: (str, optional) The organization of the registry to fetch. If not specified, use the organization specified in the user's settings. - - `filter`: (dict, optional) MongoDB-style filter to apply to each object in the lazy registry iterator. Fields available to filter for registries are `name`, `description`, `created_at`, `updated_at`. Fields available to filter for collections are `name`, `tag`, `description`, `created_at`, `updated_at` Fields available to filter for versions are `tag`, `alias`, `created_at`, `updated_at`, `metadata` +| Returns | | +| :--- | :--- | +| A lazy iterator of `Registry` objects. | +#### Examples: - -**Returns:** - A lazy iterator of `Registry` objects. - - - -**Examples:** - Find all registries with the names that contain "model" +Find all registries with the names that contain "model" ```python import wandb api = wandb.Api() # specify an org if your entity belongs to multiple orgs api.registries(filter={"name": {"$regex": "model"}}) -``` +``` -Find all collections in the registries with the name "my_collection" and the tag "my_tag" +Find all collections in the registries with the name "my_collection" and the tag "my_tag" ```python api.registries().collections(filter={"name": "my_collection", "tag": "my_tag"}) -``` +``` -Find all artifact versions in the registries with a collection name that contains "my_collection" and a version that has the alias "best" +Find all artifact versions in the registries with a collection name that contains "my_collection" and a version that has the alias "best" ```python api.registries().collections( filter={"name": {"$regex": "my_collection"}} ).versions(filter={"alias": "best"}) -``` +``` -Find all artifact versions in the registries that contain "model" and have the tag "prod" or alias "best" +Find all artifact versions in the registries that contain "model" and have the tag "prod" or alias "best" ```python api.registries(filter={"name": {"$regex": "model"}}).versions( filter={"$or": [{"tag": "prod"}, {"alias": "best"}]} ) -``` +``` ---- +### `registry` -### method `Api.registry` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1854-L1892) ```python -registry(name: str, organization: Optional[str] = None) → Registry +registry( + name: str, + organization: (str | None) = None +) -> Registry ``` -Return a registry given a registry name. - +Return a registry given a registry name. +| Args | | +| :--- | :--- | +| `name` | The name of the registry. This is without the `wandb-registry-` prefix. | +| `organization` | The organization of the registry. If no organization is set in the settings, the organization will be fetched from the entity if the entity only belongs to one organization. | -**Args:** - - - `name`: The name of the registry. This is without the `wandb-registry-` prefix. - - `organization`: The organization of the registry. If no organization is set in the settings, the organization will be fetched from the entity if the entity only belongs to one organization. +| Returns | | +| :--- | :--- | +| A registry object. | +#### Examples: - -**Returns:** - A registry object. - - - -**Examples:** - Fetch and update a registry +Fetch and update a registry ```python import wandb @@ -1089,164 +979,161 @@ api = wandb.Api() registry = api.registry(name="my-registry", organization="my-org") registry.description = "This is an updated description" registry.save() -``` +``` ---- +### `reports` -### method `Api.reports` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1005-L1048) ```python reports( - path: str = '', - name: Optional[str] = None, + path: str = "", + name: (str | None) = None, per_page: int = 50 -) → public.Reports +) -> public.Reports ``` -Get reports for a given project path. - -Note: `wandb.Api.reports()` API is in beta and will likely change in future releases. - - - -**Args:** - - - `path`: The path to the project the report resides in. Specify the entity that created the project as a prefix followed by a forward slash. - - `name`: Name of the report requested. - - `per_page`: Sets the page size for query pagination. If set to `None`, use the default size. Usually there is no reason to change this. +Get reports for a given project path. +Note: `wandb.Api.reports()` API is in beta and will likely change in +future releases. +| Args | | +| :--- | :--- | +| `path` | The path to the project the report resides in. Specify the entity that created the project as a prefix followed by a forward slash. | +| `name` | Name of the report requested. | +| `per_page` | Sets the page size for query pagination. If set to `None`, use the default size. Usually there is no reason to change this. | -**Returns:** - A `Reports` object which is an iterable collection of `BetaReport` objects. +| Returns | | +| :--- | :--- | +| A `Reports` object which is an iterable collection of `BetaReport` objects. | +#### Examples: - -**Examples:** - ```python +```python import wandb wandb.Api.reports("entity/project") -``` +``` ---- +### `run` -### method `Api.run` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1251-L1269) ```python -run(path='') +run( + path="" +) ``` -Return a single run by parsing path in the form `entity/project/run_id`. +Return a single run by parsing path in the form `entity/project/run_id`. +| Args | | +| :--- | :--- | +| `path` | Path to run in the form `entity/project/run_id`. If `api.entity` is set, this can be in the form `project/run_id` and if `api.project` is set this can just be the run_id. | +| Returns | | +| :--- | :--- | +| A `Run` object. | -**Args:** - - - `path`: Path to run in the form `entity/project/run_id`. If `api.entity` is set, this can be in the form `project/run_id` and if `api.project` is set this can just be the run_id. +### `run_queue` - - -**Returns:** - A `Run` object. - ---- - -### method `Api.run_queue` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1294-L1307) ```python -run_queue(entity: str, name: str) +run_queue( + entity: str, + name: str +) ``` -Return the named `RunQueue` for entity. +Return the named `RunQueue` for entity. -See `Api.create_run_queue` for more information on how to create a run queue. +See `Api.create_run_queue` for more information on how to create a run queue. ---- +### `runs` -### method `Api.runs` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1120-L1249) ```python runs( - path: Optional[str] = None, - filters: Optional[Dict[str, Any]] = None, - order: str = '+created_at', + path: (str | None) = None, + filters: (dict[str, Any] | None) = None, + order: str = "+created_at", per_page: int = 50, - include_sweeps: bool = True + include_sweeps: bool = (True), + lazy: bool = (True) ) ``` -Returns a `Runs` object, which lazily iterates over `Run` objects. - -Fields you can filter by include: -- `createdAt`: The timestamp when the run was created. (in ISO 8601 format, e.g. "2023-01-01T12:00:00Z") -- `displayName`: The human-readable display name of the run. (e.g. "eager-fox-1") -- `duration`: The total runtime of the run in seconds. -- `group`: The group name used to organize related runs together. -- `host`: The hostname where the run was executed. -- `jobType`: The type of job or purpose of the run. -- `name`: The unique identifier of the run. (e.g. "a1b2cdef") -- `state`: The current state of the run. -- `tags`: The tags associated with the run. -- `username`: The username of the user who initiated the run - -Additionally, you can filter by items in the run config or summary metrics. Such as `config.experiment_name`, `summary_metrics.loss`, etc. - -For more complex filtering, you can use MongoDB query operators. For details, see: https://docs.mongodb.com/manual/reference/operator/query The following operations are supported: -- `$and` -- `$or` -- `$nor` -- `$eq` -- `$ne` -- `$gt` -- `$gte` -- `$lt` -- `$lte` -- `$in` -- `$nin` -- `$exists` -- `$regex` - - - - - - - -**Args:** - - - `path`: (str) path to project, should be in the form: "entity/project" - - `filters`: (dict) queries for specific runs using the MongoDB query language. You can filter by run properties such as config.key, summary_metrics.key, state, entity, createdAt, etc. - - `For example`: `{"config.experiment_name": "foo"}` would find runs with a config entry of experiment name set to "foo" - - `order`: (str) Order can be `created_at`, `heartbeat_at`, `config.*.value`, or `summary_metrics.*`. If you prepend order with a + order is ascending (default). If you prepend order with a - order is descending. The default order is run.created_at from oldest to newest. - - `per_page`: (int) Sets the page size for query pagination. - - `include_sweeps`: (bool) Whether to include the sweep runs in the results. - - - -**Returns:** - A `Runs` object, which is an iterable collection of `Run` objects. +Returns a `Runs` object, which lazily iterates over `Run` objects. + +Fields you can filter by include: + +- `createdAt`: The timestamp when the run was created. (in ISO 8601 format, e.g. "2023-01-01T12:00:00Z") +- `displayName`: The human-readable display name of the run. (e.g. "eager-fox-1") +- `duration`: The total runtime of the run in seconds. +- `group`: The group name used to organize related runs together. +- `host`: The hostname where the run was executed. +- `jobType`: The type of job or purpose of the run. +- `name`: The unique identifier of the run. (e.g. "a1b2cdef") +- `state`: The current state of the run. +- `tags`: The tags associated with the run. +- `username`: The username of the user who initiated the run + +Additionally, you can filter by items in the run config or summary metrics. +Such as `config.experiment_name`, `summary_metrics.loss`, etc. + +For more complex filtering, you can use MongoDB query operators. +For details, see: https://docs.mongodb.com/manual/reference/operator/query +The following operations are supported: + +- `$and` +- `$or` +- `$nor` +- `$eq` +- `$ne` +- `$gt` +- `$gte` +- `$lt` +- `$lte` +- `$in` +- `$nin` +- `$exists` +- `$regex` + +| Args | | +| :--- | :--- | +| `path` | (str) path to project, should be in the form: "entity/project" | +| `filters` | (dict) queries for specific runs using the MongoDB query language. You can filter by run properties such as config.key, summary_metrics.key, state, entity, createdAt, etc. For example: `{"config.experiment_name": "foo"}` would find runs with a config entry of experiment name set to "foo" | +| `order` | (str) Order can be `created_at`, `heartbeat_at`, `config.*.value`, or `summary_metrics.*`. If you prepend order with a + order is ascending (default). If you prepend order with a - order is descending. The default order is run.created_at from oldest to newest. | +| `per_page` | (int) Sets the page size for query pagination. | +| `include_sweeps` | (bool) Whether to include the sweep runs in the results. | +| `lazy` | (bool) Whether to use lazy loading for faster performance. When True (default), only essential run metadata is loaded initially. Heavy fields like config, summaryMetrics, and systemMetrics are loaded on-demand when accessed. Set to False for full data upfront. | + +| Returns | | +| :--- | :--- | +| A `Runs` object, which is an iterable collection of `Run` objects. | + +#### Examples: - - -**Examples:** - ```python +```python # Find runs in project where config.experiment_name has been set to "foo" api.runs(path="my_entity/project", filters={"config.experiment_name": "foo"}) -``` +``` ```python # Find runs in project where config.experiment_name has been set to "foo" or "bar" api.runs( path="my_entity/project", filters={ - "$or": [ - {"config.experiment_name": "foo"}, - {"config.experiment_name": "bar"}, - ] + "$or": [ + {"config.experiment_name": "foo"}, + {"config.experiment_name": "bar"}, + ] }, ) -``` +``` ```python # Find runs in project where config.experiment_name matches a regex @@ -1255,7 +1142,7 @@ api.runs( path="my_entity/project", filters={"config.experiment_name": {"$regex": "b.*"}}, ) -``` +``` ```python # Find runs in project where the run name matches a regex @@ -1263,52 +1150,48 @@ api.runs( api.runs( path="my_entity/project", filters={"display_name": {"$regex": "^foo.*"}} ) -``` +``` ```python # Find runs in project sorted by ascending loss api.runs(path="my_entity/project", order="+summary_metrics.loss") -``` +``` ---- +### `slack_integrations` -### method `Api.slack_integrations` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2037-L2079) ```python slack_integrations( - entity: Optional[str] = None, + *, + entity: (str | None) = None, per_page: int = 50 -) → Iterator[ForwardRef('SlackIntegration')] +) -> Iterator[SlackIntegration] ``` -Returns an iterator of Slack integrations for an entity. - - +Returns an iterator of Slack integrations for an entity. -**Args:** - - - `entity`: The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. - - `per_page`: Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. +| Args | | +| :--- | :--- | +| `entity` | The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. | +| `per_page` | Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. | +| Yields | | +| :--- | :--- | +| Iterator[SlackIntegration]: An iterator of Slack integrations. | +#### Examples: -**Yields:** - - - `Iterator[SlackIntegration]`: An iterator of Slack integrations. - - - -**Examples:** - Get all registered Slack integrations for the team "my-team": +Get all registered Slack integrations for the team "my-team": ```python import wandb api = wandb.Api() slack_integrations = api.slack_integrations(entity="my-team") -``` +``` -Find only Slack integrations that post to channel names starting with "team-alerts-": +Find only Slack integrations that post to channel names starting with "team-alerts-": ```python slack_integrations = api.slack_integrations(entity="my-team") @@ -1317,95 +1200,87 @@ team_alert_integrations = [ for ig in slack_integrations if ig.channel_name.startswith("team-alerts-") ] -``` +``` ---- +### `sweep` -### method `Api.sweep` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1309-L1325) ```python -sweep(path='') +sweep( + path="" +) ``` -Return a sweep by parsing path in the form `entity/project/sweep_id`. - +Return a sweep by parsing path in the form `entity/project/sweep_id`. +| Args | | +| :--- | :--- | +| `path` | Path to sweep in the form entity/project/sweep_id. If `api.entity` is set, this can be in the form project/sweep_id and if `api.project` is set this can just be the sweep_id. | -**Args:** - - - `path`: Path to sweep in the form entity/project/sweep_id. If `api.entity` is set, this can be in the form project/sweep_id and if `api.project` is set this can just be the sweep_id. +| Returns | | +| :--- | :--- | +| A `Sweep` object. | +### `sync_tensorboard` - -**Returns:** - A `Sweep` object. - ---- - -### method `Api.sync_tensorboard` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L758-L780) ```python -sync_tensorboard(root_dir, run_id=None, project=None, entity=None) +sync_tensorboard( + root_dir, run_id=None, project=None, entity=None +) ``` -Sync a local directory containing tfevent files to wandb. +Sync a local directory containing tfevent files to wandb. ---- +### `team` -### method `Api.team` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1065-L1076) ```python -team(team: str) → public.Team +team( + team: str +) -> Team ``` -Return the matching `Team` with the given name. - - +Return the matching `Team` with the given name. -**Args:** - - - `team`: The name of the team. +| Args | | +| :--- | :--- | +| `team` | The name of the team. | +| Returns | | +| :--- | :--- | +| A `Team` object. | +### `update_automation` -**Returns:** - A `Team` object. - ---- - -### method `Api.update_automation` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L2357-L2478) ```python update_automation( - obj: 'Automation', - create_missing: bool = False, - **kwargs: typing_extensions.Unpack[ForwardRef('WriteAutomationsKwargs')] -) → Automation + obj: Automation, + *, + create_missing: bool = (False), + **kwargs +) -> Automation ``` -Update an existing automation. - - +Update an existing automation. -**Args:** - - - `obj`: The automation to update. Must be an existing automation. create_missing (bool): If True, and the automation does not exist, create it. **kwargs: Any additional values to assign to the automation before updating it. If given, these will override any values that may already be set on the automation: - - `name`: The name of the automation. - - `description`: The description of the automation. - - `enabled`: Whether the automation is enabled. - - `scope`: The scope of the automation. - - `event`: The event that triggers the automation. - - `action`: The action that is triggered by the automation. +| Args | | +| :--- | :--- | +| `obj` | The automation to update. Must be an existing automation. create_missing (bool): If True, and the automation does not exist, create it. | +| `**kwargs` | Any additional values to assign to the automation before updating it. If given, these will override any values that may already be set on the automation: - `name`: The name of the automation. - `description`: The description of the automation. - `enabled`: Whether the automation is enabled. - `scope`: The scope of the automation. - `event`: The event that triggers the automation. - `action`: The action that is triggered by the automation. | +| Returns | | +| :--- | :--- | +| The updated automation. | +#### Examples: -**Returns:** - The updated automation. - - - -**Examples:** - Disable and edit the description of an existing automation ("my-automation"): +Disable and edit the description of an existing automation ("my-automation"): ```python import wandb @@ -1417,9 +1292,9 @@ automation.enabled = False automation.description = "Kept for reference, but no longer used." updated_automation = api.update_automation(automation) -``` +``` -OR +OR ```python import wandb @@ -1433,133 +1308,125 @@ updated_automation = api.update_automation( enabled=False, description="Kept for reference, but no longer used.", ) -``` +``` ---- +### `upsert_run_queue` -### method `Api.upsert_run_queue` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L635-L742) ```python upsert_run_queue( name: str, resource_config: dict, - resource_type: 'public.RunQueueResourceType', - entity: Optional[str] = None, - template_variables: Optional[dict] = None, - external_links: Optional[dict] = None, - prioritization_mode: Optional[ForwardRef('public.RunQueuePrioritizationMode')] = None + resource_type: public.RunQueueResourceType, + entity: (str | None) = None, + template_variables: (dict | None) = None, + external_links: (dict | None) = None, + prioritization_mode: (public.RunQueuePrioritizationMode | None) = None ) ``` -Upsert a run queue in W&B Launch. - - - -**Args:** - - - `name`: Name of the queue to create - - `entity`: Optional name of the entity to create the queue. If `None`, use the configured or default entity. - - `resource_config`: Optional default resource configuration to be used for the queue. Use handlebars (eg. `{{var}}`) to specify template variables. - - `resource_type`: Type of resource to be used for the queue. One of "local-container", "local-process", "kubernetes", "sagemaker", or "gcp-vertex". - - `template_variables`: A dictionary of template variable schemas to be used with the config. - - `external_links`: Optional dictionary of external links to be used with the queue. - - `prioritization_mode`: Optional version of prioritization to use. Either "V0" or None - +Upsert a run queue in W&B Launch. +| Args | | +| :--- | :--- | +| `name` | Name of the queue to create | +| `entity` | Optional name of the entity to create the queue. If `None`, use the configured or default entity. | +| `resource_config` | Optional default resource configuration to be used for the queue. Use handlebars (eg. `{{var}}`) to specify template variables. | +| `resource_type` | Type of resource to be used for the queue. One of "local-container", "local-process", "kubernetes", "sagemaker", or "gcp-vertex". | +| `template_variables` | A dictionary of template variable schemas to be used with the config. | +| `external_links` | Optional dictionary of external links to be used with the queue. | +| `prioritization_mode` | Optional version of prioritization to use. Either "V0" or None | -**Returns:** - The upserted `RunQueue`. +| Returns | | +| :--- | :--- | +| The upserted `RunQueue`. | +| Raises | | +| :--- | :--- | +| ValueError if any of the parameters are invalid wandb.Error on wandb API errors | +### `user` -**Raises:** - ValueError if any of the parameters are invalid wandb.Error on wandb API errors - ---- - -### method `Api.user` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1078-L1101) ```python -user(username_or_email: str) → Optional[ForwardRef('public.User')] +user( + username_or_email: str +) -> (User | None) ``` -Return a user from a username or email address. - -This function only works for local administrators. Use `api.viewer` to get your own user object. - +Return a user from a username or email address. +This function only works for local administrators. Use `api.viewer` +to get your own user object. -**Args:** - - - `username_or_email`: The username or email address of the user. +| Args | | +| :--- | :--- | +| `username_or_email` | The username or email address of the user. | +| Returns | | +| :--- | :--- | +| A `User` object or None if a user is not found. | +### `users` -**Returns:** - A `User` object or None if a user is not found. - ---- - -### method `Api.users` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1103-L1118) ```python -users(username_or_email: str) → List[ForwardRef('public.User')] +users( + username_or_email: str +) -> list[User] ``` -Return all users from a partial username or email address query. - -This function only works for local administrators. Use `api.viewer` to get your own user object. - +Return all users from a partial username or email address query. +This function only works for local administrators. Use `api.viewer` +to get your own user object. -**Args:** - - - `username_or_email`: The prefix or suffix of the user you want to find. +| Args | | +| :--- | :--- | +| `username_or_email` | The prefix or suffix of the user you want to find. | +| Returns | | +| :--- | :--- | +| An array of `User` objects. | +### `webhook_integrations` -**Returns:** - An array of `User` objects. - ---- - -### method `Api.webhook_integrations` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/api.py#L1993-L2035) ```python webhook_integrations( - entity: Optional[str] = None, + entity: (str | None) = None, + *, per_page: int = 50 -) → Iterator[ForwardRef('WebhookIntegration')] +) -> Iterator[WebhookIntegration] ``` -Returns an iterator of webhook integrations for an entity. - - +Returns an iterator of webhook integrations for an entity. -**Args:** - - - `entity`: The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. - - `per_page`: Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. +| Args | | +| :--- | :--- | +| `entity` | The entity (e.g. team name) for which to fetch integrations. If not provided, the user's default entity will be used. | +| `per_page` | Number of integrations to fetch per page. Defaults to 50. Usually there is no reason to change this. | +| Yields | | +| :--- | :--- | +| Iterator[WebhookIntegration]: An iterator of webhook integrations. | +#### Examples: -**Yields:** - - - `Iterator[WebhookIntegration]`: An iterator of webhook integrations. - - - -**Examples:** - Get all registered webhook integrations for the team "my-team": +Get all registered webhook integrations for the team "my-team": ```python import wandb api = wandb.Api() webhook_integrations = api.webhook_integrations(entity="my-team") -``` +``` -Find only webhook integrations that post requests to "https://my-fake-url.com": +Find only webhook integrations that post requests to "https://my-fake-url.com": ```python webhook_integrations = api.webhook_integrations(entity="my-team") @@ -1568,5 +1435,11 @@ my_webhooks = [ for ig in webhook_integrations if ig.url_endpoint.startswith("https://my-fake-url.com") ] -``` +``` +| Class Variables | | +| :--- | :--- | +| `CREATE_PROJECT` | | +| `DEFAULT_ENTITY_QUERY` | | +| `USERS_QUERY` | | +| `VIEWER_QUERY` | | diff --git a/content/en/ref/python/public-api/betareport.md b/content/en/ref/python/public-api/betareport.md new file mode 100644 index 0000000000..1150f918d4 --- /dev/null +++ b/content/en/ref/python/public-api/betareport.md @@ -0,0 +1,63 @@ +--- +title: BetaReport +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L143-L280 >}} + +BetaReport is a class associated with reports created in W&B. + +Provides access to report attributes (name, description, user, spec, +timestamps) and methods for retrieving associated runs, +sections, and for rendering the report as HTML. + +| Attributes | | +| :--- | :--- | +| `sections` | Get the panel sections (groups) from the report. | + +## Methods + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L18-L38) + +```python +display( + height=420, hidden=(False) +) -> bool +``` + +Display this object in jupyter. + +### `runs` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L185-L207) + +```python +runs( + section, per_page=50, only_selected=(True) +) +``` + +Get runs associated with a section of the report. + +### `snake_to_camel` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L14-L16) + +```python +snake_to_camel( + string +) +``` + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L266-L277) + +```python +to_html( + height=1024, hidden=(False) +) +``` + +Generate HTML containing an iframe displaying this report. diff --git a/content/en/ref/python/public-api/file.md b/content/en/ref/python/public-api/file.md new file mode 100644 index 0000000000..95bcd31898 --- /dev/null +++ b/content/en/ref/python/public-api/file.md @@ -0,0 +1,109 @@ +--- +title: File +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L229-L411 >}} + +File saved to W&B. + +Represents a single file stored in W&B. Includes access to file metadata. +Files are associated with a specific run and +can include text files, model weights, datasets, visualizations, and other +artifacts. You can download the file, delete the file, and access file +properties. + +Specify one or more attributes in a dictionary to fine a specific +file logged to a specific run. You can search using the following keys: + +- id (str): The ID of the run that contains the file +- name (str): Name of the file +- url (str): path to file +- direct_url (str): path to file in the bucket +- sizeBytes (int): size of file in bytes +- md5 (str): md5 of file +- mimetype (str): mimetype of file +- updated_at (str): timestamp of last update +- path_uri (str): path to file in the bucket, currently only available for S3 objects and reference files + +| Args | | +| :--- | :--- | +| `client` | The run object that contains the file attrs (dict): A dictionary of attributes that define the file | +| `run` | The run object that contains the file | + + + + +| Attributes | | +| :--- | :--- | +| `path_uri` | Returns the URI path to the file in the storage bucket. | +| `size` | Returns the size of the file in bytes. | + +## Methods + +### `delete` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L340-L371) + +```python +delete() +``` + +Delete the file from the W&B server. + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L18-L38) + +```python +display( + height=420, hidden=(False) +) -> bool +``` + +Display this object in jupyter. + +### `download` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L296-L338) + +```python +download( + root: str = ".", + replace: bool = (False), + exist_ok: bool = (False), + api: (Api | None) = None +) -> io.TextIOWrapper +``` + +Downloads a file previously saved by a run from the wandb server. + +| Args | | +| :--- | :--- | +| `root` | Local directory to save the file. Defaults to the current working directory ("."). | +| `replace` | If `True`, download will overwrite a local file if it exists. Defaults to `False`. | +| `exist_ok` | If `True`, will not raise ValueError if file already exists and will not re-download unless replace=True. Defaults to `False`. | +| `api` | If specified, the `Api` instance used to download the file. | + +| Raises | | +| :--- | :--- | +| `ValueError` if file already exists, `replace=False` and `exist_ok=False`. | + +### `snake_to_camel` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L14-L16) + +```python +snake_to_camel( + string +) +``` + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L40-L41) + +```python +to_html( + *args, **kwargs +) +``` diff --git a/content/en/ref/python/public-api/files.md b/content/en/ref/python/public-api/files.md index e5f2a5e787..08d56c81b2 100644 --- a/content/en/ref/python/public-api/files.md +++ b/content/en/ref/python/public-api/files.md @@ -1,25 +1,17 @@ --- title: Files -namespace: public_apis_namespace -python_object_type: class --- -{{< readfile file="/_includes/public-api-use.md" >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L78-L226 >}} -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/apis/public/files.py >}} +A lazy iterator over a collection of `File` objects. +Access and manage files uploaded to W&B during a run. Handles pagination +automatically when iterating through large collections of files. +#### Example: - -## class `Files` -A lazy iterator over a collection of `File` objects. - -Access and manage files uploaded to W&B during a run. Handles pagination automatically when iterating through large collections of files. - - - -**Example:** - ```python +```python from wandb.apis.public.files import Files from wandb.apis.public.api import Api @@ -31,53 +23,83 @@ files = Files(api.client, run) # Iterate over files for file in files: - print(file.name) - print(file.url) - print(file.size) + print(file.name) + print(file.url) + print(file.size) + + # Download the file + file.download(root="download_directory", replace=True) +``` + +| Attributes | | +| :--- | :--- | +| `cursor` | Returns the cursor position for pagination of file results. | +| `more` | Returns whether there are more files to fetch. | - # Download the file - file.download(root="download_directory", replace=True) -``` +## Methods -### method `Files.__init__` +### `convert_objects` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L215-L223) ```python -__init__( - client: 'RetryingClient', - run: 'Run', - names: 'list[str] | None' = None, - per_page: 'int' = 50, - upload: 'bool' = False, - pattern: 'str | None' = None -) +convert_objects() ``` -Initialize a lazy iterator over a collection of `File` objects. +Converts GraphQL edges to File objects. -Files are retrieved in pages from the W&B server as needed. + +### `next` -**Args:** - - - `client`: The run object that contains the files - - `run`: The run object that contains the files - - `names` (list, optional): A list of file names to filter the files - - `per_page` (int, optional): The number of files to fetch per page - - `upload` (bool, optional): If `True`, fetch the upload URL for each file - - `pattern` (str, optional): Pattern to match when returning files from W&B This pattern uses mySQL's LIKE syntax, so matching all files that end with .json would be "%.json". If both names and pattern are provided, a ValueError will be raised. +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L102-L109) +```python +next() -> T +``` ---- +Return the next item from the iterator. When exhausted, raise StopIteration + +### `update_variables` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/files.py#L208-L213) -### property Files.length +```python +update_variables() +``` +Updates the GraphQL query variables for pagination. + +### `__getitem__` ---- +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L95-L100) + +```python +__getitem__( + index: (int | slice) +) -> (T | list[T]) +``` + +### `__iter__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L50-L52) +```python +__iter__() -> Iterator[T] +``` + +### `__len__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L128-L133) + +```python +__len__() -> int +``` +| Class Variables | | +| :--- | :--- | +| `QUERY` | `None` | diff --git a/content/en/ref/python/public-api/project.md b/content/en/ref/python/public-api/project.md new file mode 100644 index 0000000000..41ab345df4 --- /dev/null +++ b/content/en/ref/python/public-api/project.md @@ -0,0 +1,91 @@ +--- +title: Project +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L168-L278 >}} + +A project is a namespace for runs. + +| Args | | +| :--- | :--- | +| `client` | W&B API client instance. name (str): The name of the project. entity (str): The entity name that owns the project. | + +| Attributes | | +| :--- | :--- | +| `path` | Returns the path of the project. The path is a list containing the entity and project name. | +| `url` | Returns the URL of the project. | + +## Methods + +### `artifacts_types` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L247-L250) + +```python +artifacts_types( + per_page=50 +) +``` + +Returns all artifact types associated with this project. + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L18-L38) + +```python +display( + height=420, hidden=(False) +) -> bool +``` + +Display this object in jupyter. + +### `snake_to_camel` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L14-L16) + +```python +snake_to_camel( + string +) +``` + +### `sweeps` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L252-L262) + +```python +sweeps( + per_page=50 +) +``` + +Return a paginated collection of sweeps in this project. + +| Args | | +| :--- | :--- | +| `per_page` | The number of sweeps to fetch per request to the API. | + +| Returns | | +| :--- | :--- | +| A `Sweeps` object, which is an iterable collection of `Sweep` objects. | + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L228-L239) + +```python +to_html( + height=420, hidden=(False) +) +``` + +Generate HTML containing an iframe displaying this project. + + + + +| Class Variables | | +| :--- | :--- | +| `QUERY` | | diff --git a/content/en/ref/python/public-api/projects.md b/content/en/ref/python/public-api/projects.md index d20f8b7a8e..048401bc39 100644 --- a/content/en/ref/python/public-api/projects.md +++ b/content/en/ref/python/public-api/projects.md @@ -1,41 +1,20 @@ --- title: Projects -namespace: public_apis_namespace -python_object_type: class --- -{{< readfile file="/_includes/public-api-use.md" >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L56-L165 >}} -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/apis/public/projects.py >}} - - - - -## class `Projects` -An lazy iterator of `Project` objects. +An lazy iterator of `Project` objects. An iterable interface to access projects created and saved by the entity. -### method `Projects.__init__` - -```python -__init__( - client: wandb.apis.public.api.RetryingClient, - entity: str, - per_page: int = 50 -) → Projects -``` - -**Args:** - - - `client` (`wandb.apis.internal.Api`): The API client instance to use. - - `entity` (str): The entity name (username or team) to fetch projects for. - - `per_page` (int): Number of projects to fetch per request (default is 50). - +| Args | | +| :--- | :--- | +| client (`wandb.apis.internal.Api`): The API client instance to use. entity (str): The entity name (username or team) to fetch projects for. per_page (int): Number of projects to fetch per request (default is 50). | +#### Example: -**Example:** - ```python +```python from wandb.apis.public.api import Api # Find projects that belong to this entity @@ -47,22 +26,67 @@ for project in projects: print(f"- URL: {project.url}") print(f"- Created at: {project.created_at}") print(f"- Is benchmark: {project.is_benchmark}") -``` +``` + +| Attributes | | +| :--- | :--- | +| `cursor` | Returns the cursor position for pagination of project results. | +| `length` | Returns the total number of projects. Note: This property is not available for projects. | +| `more` | Returns `True` if there are more projects to fetch. Returns `False` if there are no more projects to fetch. | + +## Methods +### `convert_objects` -An iterable collection of `Project` objects. +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/projects.py#L154-L162) +```python +convert_objects() +``` +Converts GraphQL edges to File objects. -**Args:** - - - `client`: The API client used to query W&B. - - `entity`: The entity which owns the projects. - - `per_page`: The number of projects to fetch per request to the API. + ---- +### `next` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L102-L109) +```python +next() -> T +``` + +Return the next item from the iterator. When exhausted, raise StopIteration + +### `update_variables` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L71-L73) + +```python +update_variables() -> None +``` + +Update the query variables for the next page fetch. +### `__getitem__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L95-L100) + +```python +__getitem__( + index: (int | slice) +) -> (T | list[T]) +``` + +### `__iter__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L50-L52) + +```python +__iter__() -> Iterator[T] +``` +| Class Variables | | +| :--- | :--- | +| `QUERY` | | diff --git a/content/en/ref/python/public-api/registry.md b/content/en/ref/python/public-api/registry.md new file mode 100644 index 0000000000..15ba5a794c --- /dev/null +++ b/content/en/ref/python/public-api/registry.md @@ -0,0 +1,114 @@ +--- +title: Registry +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L35-L370 >}} + +A single registry in the Registry. + +| Attributes | | +| :--- | :--- | +| `allow_all_artifact_types` | Returns whether all artifact types are allowed in the registry. If `True` then artifacts of any type can be added to this registry. If `False` then artifacts are restricted to the types in `artifact_types` for this registry. | +| `artifact_types` | Returns the artifact types allowed in the registry. If `allow_all_artifact_types` is `True` then `artifact_types` reflects the types previously saved or currently used in the registry. If `allow_all_artifact_types` is `False` then artifacts are restricted to the types in `artifact_types`. `python import wandb registry = wandb.Api().create_registry() registry.artifact_types.append("model") registry.save() # once saved, the artifact type `model` cannot be removed registry.artifact_types.append("accidentally_added") registry.artifact_types.remove( "accidentally_added" ) # Types can only be removed if it has not been saved yet ` | +| `created_at` | Timestamp of when the registry was created. | +| `description` | Description of the registry. | +| `entity` | Organization entity of the registry. | +| `full_name` | Full name of the registry including the `wandb-registry-` prefix. | +| `name` | Name of the registry without the `wandb-registry-` prefix. | +| `organization` | Organization name of the registry. | +| `updated_at` | Timestamp of when the registry was last updated. | +| `visibility` | Visibility of the registry. | + +## Methods + +### `collections` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L186-L192) + +```python +collections( + filter: (dict[str, Any] | None) = None +) -> Collections +``` + +Returns the collections belonging to the registry. + +### `create` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L202-L266) + +```python +@classmethod +create( + client: Client, + organization: str, + name: str, + visibility: Literal['organization', 'restricted'], + description: (str | None) = None, + artifact_types: (list[str] | None) = None +) +``` + +Create a new registry. + +The registry name must be unique within the organization. +This function should be called using `api.create_registry()` + +| Args | | +| :--- | :--- | +| `client` | The GraphQL client. | +| `organization` | The name of the organization. | +| `name` | The name of the registry (without the `wandb-registry-` prefix). | +| `visibility` | The visibility level ('organization' or 'restricted'). | +| `description` | An optional description for the registry. | +| `artifact_types` | An optional list of allowed artifact types. | + +| Returns | | +| :--- | :--- | +| `Registry` | The newly created Registry object. | + +| Raises | | +| :--- | :--- | +| `ValueError` | If a registry with the same name already exists in the organization or if the creation fails. | + +### `delete` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L268-L283) + +```python +delete() -> None +``` + +Delete the registry. This is irreversible. + +### `load` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L285-L307) + +```python +load() -> None +``` + +Load the registry attributes from the backend to reflect the latest saved state. + +### `save` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L309-L366) + +```python +save() -> None +``` + +Save registry attributes to the backend. + +### `versions` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/registries/registry.py#L194-L200) + +```python +versions( + filter: (dict[str, Any] | None) = None +) -> Versions +``` + +Returns the versions belonging to the registry. diff --git a/content/en/ref/python/public-api/reports.md b/content/en/ref/python/public-api/reports.md index 741a90f7a5..825dfc99fc 100644 --- a/content/en/ref/python/public-api/reports.md +++ b/content/en/ref/python/public-api/reports.md @@ -1,66 +1,78 @@ --- title: Reports -namespace: public_apis_namespace -python_object_type: class --- -{{< readfile file="/_includes/public-api-use.md" >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L23-L140 >}} -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/apis/public/reports.py >}} +Reports is a lazy iterator of `BetaReport` objects. +| Args | | +| :--- | :--- | +| client (`wandb.apis.internal.Api`): The API client instance to use. project (`wandb.sdk.internal.Project`): The project to fetch reports from. name (str, optional): The name of the report to filter by. If `None`, fetches all reports. entity (str, optional): The entity name for the project. Defaults to the project entity. per_page (int): Number of reports to fetch per page (default is 50). | +| Attributes | | +| :--- | :--- | +| `cursor` | Returns the cursor position for pagination of file results. | +| `more` | Returns whether there are more files to fetch. | +## Methods -## class `Reports` -Reports is a lazy iterator of `BetaReport` objects. +### `convert_objects` -### method `Reports.__init__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L123-L137) ```python -__init__(client, project, name=None, entity=None, per_page=50) +convert_objects() ``` -**Args:** - - - `client` (`wandb.apis.internal.Api`): The API client instance to use. - - `project` (`wandb.sdk.internal.Project`): The project to fetch reports from. - - `name` (str, optional): The name of the report to filter by. If `None`, fetches all reports. - - `entity` (str, optional): The entity name for the project. Defaults to the project entity. - - `per_page` (int): Number of reports to fetch per page (default is 50). - - +Converts GraphQL edges to File objects. +### `next` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L102-L109) +```python +next() -> T +``` +Return the next item from the iterator. When exhausted, raise StopIteration ---- +### `update_variables` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/reports.py#L117-L121) -### property Reports.length - +```python +update_variables() +``` +Updates the GraphQL query variables for pagination. +### `__getitem__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L95-L100) ---- +```python +__getitem__( + index: (int | slice) +) -> (T | list[T]) +``` +### `__iter__` -### method `Reports.convert_objects` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L50-L52) ```python -convert_objects() +__iter__() -> Iterator[T] ``` -Converts GraphQL edges to File objects. - ---- +### `__len__` -### method `Reports.update_variables` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L128-L133) ```python -update_variables() +__len__() -> int ``` -Updates the GraphQL query variables for pagination. - +| Class Variables | | +| :--- | :--- | +| `QUERY` | | diff --git a/content/en/ref/python/public-api/run.md b/content/en/ref/python/public-api/run.md new file mode 100644 index 0000000000..a41812cafb --- /dev/null +++ b/content/en/ref/python/public-api/run.md @@ -0,0 +1,420 @@ +--- +title: Run +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L521-L1438 >}} + +A single run associated with an entity and project. + +| Args | | +| :--- | :--- | +| `client` | The W&B API client. | +| `entity` | The entity associated with the run. | +| `project` | The project associated with the run. | +| `run_id` | The unique identifier for the run. | +| `attrs` | The attributes of the run. | +| `include_sweeps` | Whether to include sweeps in the run. | + +| Attributes | | +| :--- | :--- | +| `config` | Get run config. Auto-loads full data if in lazy mode. | +| `entity` | The entity associated with the run. | +| `id` | The unique identifier for the run. | +| `json_config` | Return the run config as a JSON string. | +| `lastHistoryStep` | Returns the last step logged in the run's history. | +| `metadata` | Metadata about the run from wandb-metadata.json. Metadata includes the run's description, tags, start time, memory usage and more. | +| `name` | The name of the run. | +| `path` | The path of the run. The path is a list containing the entity, project, and run_id. | +| `rawconfig` | Get raw run config including internal keys. Auto-loads full data if in lazy mode. | +| `state` | The state of the run. Can be one of: Finished, Failed, Crashed, or Running. | +| `storage_id` | The unique storage identifier for the run. | +| `summary` | Get run summary metrics. Auto-loads full data if in lazy mode. | +| `summary_metrics` | Get run summary metrics. Auto-loads full data if in lazy mode. | +| `sweep_name` | Get sweep name. Always available since sweepName is in lightweight fragment. | +| `system_metrics` | Get run system metrics. Auto-loads full data if in lazy mode. | +| `url` | The URL of the run. The run URL is generated from the entity, project, and run_id. For SaaS users, it takes the form of `https://wandb.ai/entity/project/run_id`. | +| `username` | This API is deprecated. Use `entity` instead. | + +## Methods + +### `create` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L643-L697) + +```python +@classmethod +create( + api: public.Api, + run_id: (str | None) = None, + project: (str | None) = None, + entity: (str | None) = None, + state: Literal['running', 'pending'] = "running" +) +``` + +Create a run for the given project. + +### `delete` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L872-L905) + +```python +delete( + delete_artifacts=(False) +) +``` + +Delete the given run from the wandb backend. + +| Args | | +| :--- | :--- | +| delete_artifacts (bool, optional): Whether to delete the artifacts associated with the run. | + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L18-L38) + +```python +display( + height=420, hidden=(False) +) -> bool +``` + +Display this object in jupyter. + +### `file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L992-L1002) + +```python +file( + name +) +``` + +Return the path of a file with a given name in the artifact. + +| Args | | +| :--- | :--- | +| name (str): name of requested file. | + +| Returns | | +| :--- | :--- | +| A `File` matching the name argument. | + +### `files` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L961-L990) + +```python +files( + names: (list[str] | None) = None, + pattern: (str | None) = None, + per_page: int = 50 +) +``` + +Returns a `Files` object for all files in the run which match the given criteria. + +You can specify a list of exact file names to match, or a pattern to match against. +If both are provided, the pattern will be ignored. + +| Args | | +| :--- | :--- | +| names (list): names of the requested files, if empty returns all files pattern (str, optional): Pattern to match when returning files from W&B. This pattern uses mySQL's LIKE syntax, so matching all files that end with .json would be "%.json". If both names and pattern are provided, a ValueError will be raised. per_page (int): number of results per page. | + +| Returns | | +| :--- | :--- | +| A `Files` object, which is an iterator over `File` objects. | + +### `history` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1030-L1070) + +```python +history( + samples=500, keys=None, x_axis="_step", pandas=(True), stream="default" +) +``` + +Return sampled history metrics for a run. + +This is simpler and faster if you are ok with the history records being sampled. + +| Args | | +| :--- | :--- | +| `samples` | (int, optional) The number of samples to return | +| `pandas` | (bool, optional) Return a pandas dataframe | +| `keys` | (list, optional) Only return metrics for specific keys | +| `x_axis` | (str, optional) Use this metric as the xAxis defaults to _step | +| `stream` | (str, optional) "default" for metrics, "system" for machine metrics | + +| Returns | | +| :--- | :--- | +| `pandas.DataFrame` | If pandas=True returns a `pandas.DataFrame` of history metrics. list of dicts: If pandas=False returns a list of dicts of history metrics. | + +### `load` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L812-L819) + +```python +load( + force=(False) +) +``` + +Load run data using appropriate fragment based on lazy mode. + +### `load_full_data` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1282-L1301) + +```python +load_full_data( + force: bool = (False) +) -> dict[str, Any] +``` + +Load full run data including heavy fields like config, systemMetrics, summaryMetrics. + +This method is useful when you initially used lazy=True for listing runs, +but need access to the full data for specific runs. + +| Args | | +| :--- | :--- | +| `force` | Force reload even if data is already loaded | + +| Returns | | +| :--- | :--- | +| The loaded run attributes | + +### `log_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1235-L1280) + +```python +log_artifact( + artifact: wandb.Artifact, + aliases: (Collection[str] | None) = None, + tags: (Collection[str] | None) = None +) +``` + +Declare an artifact as output of a run. + +| Args | | +| :--- | :--- | +| artifact (`Artifact`): An artifact returned from `wandb.Api().artifact(name)`. aliases (list, optional): Aliases to apply to this artifact. | +| `tags` | (list, optional) Tags to apply to this artifact, if any. | + +| Returns | | +| :--- | :--- | +| A `Artifact` object. | + +### `logged_artifacts` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1128-L1164) + +```python +logged_artifacts( + per_page: int = 100 +) -> public.RunArtifacts +``` + +Fetches all artifacts logged by this run. + +Retrieves all output artifacts that were logged during the run. Returns a +paginated result that can be iterated over or collected into a single list. + +| Args | | +| :--- | :--- | +| `per_page` | Number of artifacts to fetch per API request. | + +| Returns | | +| :--- | :--- | +| An iterable collection of all Artifact objects logged as outputs during this run. | + +#### Example: + +```python +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) +``` + +### `save` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L907-L909) + +```python +save() +``` + +Persist changes to the run object to the W&B backend. + +### `scan_history` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1072-L1126) + +```python +scan_history( + keys=None, page_size=1000, min_step=None, max_step=None +) +``` + +Returns an iterable collection of all history records for a run. + +| Args | | +| :--- | :--- | +| keys ([str], optional): only fetch these keys, and only fetch rows that have all of keys defined. page_size (int, optional): size of pages to fetch from the api. min_step (int, optional): the minimum number of pages to scan at a time. max_step (int, optional): the maximum number of pages to scan at a time. | + +| Returns | | +| :--- | :--- | +| An iterable collection over history records (dict). | + +#### Example: + +Export all the loss values for an example run + +```python +run = api.run("entity/project-name/run-id") +history = run.scan_history(keys=["Loss"]) +losses = [row["Loss"] for row in history] +``` + +### `snake_to_camel` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L14-L16) + +```python +snake_to_camel( + string +) +``` + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1424-L1432) + +```python +to_html( + height=420, hidden=(False) +) +``` + +Generate HTML containing an iframe displaying this run. + +### `update` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L844-L870) + +```python +update() +``` + +Persist changes to the run object to the wandb backend. + +### `upload_file` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1004-L1028) + +```python +upload_file( + path, root="." +) +``` + +Upload a local file to W&B, associating it with this run. + +| Args | | +| :--- | :--- | +| path (str): Path to the file to upload. Can be absolute or relative. root (str): The root path to save the file relative to. For example, if you want to have the file saved in the run as "my_dir/file.txt" and you're currently in "my_dir" you would set root to "../". Defaults to current directory ("."). | + +| Returns | | +| :--- | :--- | +| A `File` object representing the uploaded file. | + +### `use_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1197-L1233) + +```python +use_artifact( + artifact, use_as=None +) +``` + +Declare an artifact as an input to a run. + +| Args | | +| :--- | :--- | +| artifact (`Artifact`): An artifact returned from `wandb.Api().artifact(name)` use_as (string, optional): A string identifying how the artifact is used in the script. Used to easily differentiate artifacts used in a run, when using the beta wandb launch feature's artifact swapping functionality. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +### `used_artifacts` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L1166-L1195) + +```python +used_artifacts( + per_page: int = 100 +) -> public.RunArtifacts +``` + +Fetches artifacts explicitly used by this run. + +Retrieves only the input artifacts that were explicitly declared as used +during the run, typically via `run.use_artifact()`. Returns a paginated +result that can be iterated over or collected into a single list. + +| Args | | +| :--- | :--- | +| `per_page` | Number of artifacts to fetch per API request. | + +| Returns | | +| :--- | :--- | +| An iterable collection of Artifact objects explicitly used as inputs in this run. | + +#### Example: + +```python +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 +``` + +### `wait_until_finished` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L821-L842) + +```python +wait_until_finished() +``` + +Check the state of the run until it is finished. diff --git a/content/en/ref/python/public-api/runs.md b/content/en/ref/python/public-api/runs.md index 0afbb6485a..65d4e6f56a 100644 --- a/content/en/ref/python/public-api/runs.md +++ b/content/en/ref/python/public-api/runs.md @@ -1,51 +1,28 @@ --- title: Runs -namespace: public_apis_namespace -python_object_type: class --- -{{< readfile file="/_includes/public-api-use.md" >}} +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L216-L518 >}} -{{< cta-button githubLink=https://github.com/wandb/wandb/blob/main/wandb/apis/public/runs.py >}} +A lazy iterator of `Run` objects associated with a project and optional filter. - - - -## class `Runs` -A lazy iterator of `Run` objects associated with a project and optional filter. - -Runs are retrieved in pages from the W&B server as needed. +Runs are retrieved in pages from the W&B server as needed. This is generally used indirectly using the `Api.runs` namespace. -### method `Runs.__init__` - -```python -__init__( - client: 'RetryingClient', - entity: 'str', - project: 'str', - filters: 'dict[str, Any] | None' = None, - order: 'str' = '+created_at', - per_page: 'int' = 50, - include_sweeps: 'bool' = True -) -``` - -**Args:** - - - `client`: (`wandb.apis.public.RetryingClient`) The API client to use for requests. - - `entity`: (str) The entity (username or team) that owns the project. - - `project`: (str) The name of the project to fetch runs from. - - `filters`: (Optional[Dict[str, Any]]) A dictionary of filters to apply to the runs query. - - `order`: (str) Order can be `created_at`, `heartbeat_at`, `config.*.value`, or `summary_metrics.*`. If you prepend order with a + order is ascending (default). If you prepend order with a - order is descending. The default order is run.created_at from oldest to newest. - - `per_page`: (int) The number of runs to fetch per request (default is 50). - - `include_sweeps`: (bool) Whether to include sweep information in the runs. Defaults to True. +| Args | | +| :--- | :--- | +| `client` | (`wandb.apis.public.RetryingClient`) The API client to use for requests. | +| `entity` | (str) The entity (username or team) that owns the project. | +| `project` | (str) The name of the project to fetch runs from. | +| `filters` | (Optional[Dict[str, Any]]) A dictionary of filters to apply to the runs query. | +| `order` | (str) Order can be `created_at`, `heartbeat_at`, `config.*.value`, or `summary_metrics.*`. If you prepend order with a + order is ascending (default). If you prepend order with a - order is descending. The default order is run.created_at from oldest to newest. | +| `per_page` | (int) The number of runs to fetch per request (default is 50). | +| `include_sweeps` | (bool) Whether to include sweep information in the runs. Defaults to True. | +#### Examples: - -**Examples:** - ```python +```python from wandb.apis.public.runs import Runs from wandb.apis.public import Api @@ -77,54 +54,117 @@ histories_df = runs.histories( x_axis="_step", # X-axis metric format="pandas", # Return as pandas DataFrame ) -``` +``` +| Attributes | | +| :--- | :--- | +| `cursor` | Returns the cursor position for pagination of runs results. | +| `more` | Returns whether there are more runs to fetch. | +## Methods +### `convert_objects` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L344-L381) +```python +convert_objects() +``` +Converts GraphQL edges to Runs objects. ---- + -### property Runs.length +### `histories` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L383-L482) +```python +histories( + samples: int = 500, + keys: (list[str] | None) = None, + x_axis: str = "_step", + format: Literal['default', 'pandas', 'polars'] = "default", + stream: Literal['default', 'system'] = "default" +) +``` +Return sampled history metrics for all runs that fit the filters conditions. +| Args | | +| :--- | :--- | +| `samples` | The number of samples to return per run | +| `keys` | Only return metrics for specific keys | +| `x_axis` | Use this metric as the xAxis defaults to _step | +| `format` | Format to return data in, options are "default", "pandas", "polars" | +| `stream` | "default" for metrics, "system" for machine metrics | ---- +| Returns | | +| :--- | :--- | +| `pandas.DataFrame` | If `format="pandas"`, returns a `pandas.DataFrame` of history metrics. | +| `polars.DataFrame` | If `format="polars"`, returns a `polars.DataFrame` of history metrics. list of dicts: If `format="default"`, returns a list of dicts containing history metrics with a `run_id` key. | + +### `next` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L102-L109) +```python +next() -> T +``` -### method `Runs.histories` +Return the next item from the iterator. When exhausted, raise StopIteration + +### `update_variables` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L71-L73) ```python -histories( - samples: 'int' = 500, - keys: 'list[str] | None' = None, - x_axis: 'str' = '_step', - format: "Literal['default', 'pandas', 'polars']" = 'default', - stream: "Literal['default', 'system']" = 'default' -) +update_variables() -> None +``` + +Update the query variables for the next page fetch. + +### `upgrade_to_full` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/runs.py#L487-L518) + +```python +upgrade_to_full() +``` + +Upgrade this Runs collection from lazy to full mode. + +This switches to fetching full run data and +upgrades any already-loaded Run objects to have full data. +Uses parallel loading for better performance when upgrading multiple runs. + +### `__getitem__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L95-L100) + +```python +__getitem__( + index: (int | slice) +) -> (T | list[T]) ``` -Return sampled history metrics for all runs that fit the filters conditions. +### `__iter__` +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L50-L52) +```python +__iter__() -> Iterator[T] +``` + +### `__len__` -**Args:** - - - `samples`: The number of samples to return per run - - `keys`: Only return metrics for specific keys - - `x_axis`: Use this metric as the xAxis defaults to _step - - `format`: Format to return data in, options are "default", "pandas", "polars" - - `stream`: "default" for metrics, "system" for machine metrics +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/paginator.py#L128-L133) -**Returns:** - - - `pandas.DataFrame`: If `format="pandas"`, returns a `pandas.DataFrame` of history metrics. - - `polars.DataFrame`: If `format="polars"`, returns a `polars.DataFrame` of history metrics. - - `list of dicts`: If `format="default"`, returns a list of dicts containing history metrics with a `run_id` key. +```python +__len__() -> int +``` +| Class Variables | | +| :--- | :--- | +| `QUERY` | `None` | diff --git a/content/en/ref/python/public-api/sweep.md b/content/en/ref/python/public-api/sweep.md new file mode 100644 index 0000000000..43016cf5ea --- /dev/null +++ b/content/en/ref/python/public-api/sweep.md @@ -0,0 +1,115 @@ +--- +title: Sweep +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/sweeps.py#L197-L441 >}} + +The set of runs associated with the sweep. + +| Attributes | | +| :--- | :--- | +| `config` | The sweep configuration used for the sweep. | +| `entity` | The entity associated with the sweep. | +| `expected_run_count` | Return the number of expected runs in the sweep or None for infinite runs. | +| `name` | The name of the sweep. Returns the first name that exists in the following priority order: 1. User-edited display name 2. Name configured at creation time 3. Sweep ID | +| `order` | Return the order key for the sweep. | +| `path` | Returns the path of the project. The path is a list containing the entity, project name, and sweep ID. | +| `url` | The URL of the sweep. The sweep URL is generated from the entity, project, the term "sweeps", and the sweep ID.run_id. For SaaS users, it takes the form of `https://wandb.ai/entity/project/sweeps/sweeps_ID`. | +| `username` | Deprecated. Use `Sweep.entity` instead. | + +## Methods + +### `best_run` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/sweeps.py#L295-L318) + +```python +best_run( + order=None +) +``` + +Return the best run sorted by the metric defined in config or the order passed in. + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L18-L38) + +```python +display( + height=420, hidden=(False) +) -> bool +``` + +Display this object in jupyter. + +### `get` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/sweeps.py#L361-L423) + +```python +@classmethod +get( + client: RetryingClient, + entity: (str | None) = None, + project: (str | None) = None, + sid: (str | None) = None, + order: (str | None) = None, + query: (str | None) = None, + **kwargs +) +``` + +Execute a query against the cloud backend. + +| Args | | +| :--- | :--- | +| `client` | The client to use to execute the query. | +| `entity` | The entity (username or team) that owns the project. | +| `project` | The name of the project to fetch sweep from. | +| `sid` | The sweep ID to query. | +| `order` | The order in which the sweep's runs are returned. | +| `query` | The query to use to execute the query. | +| `**kwargs` | Additional keyword arguments to pass to the query. | + +### `load` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/sweeps.py#L271-L283) + +```python +load( + force: bool = (False) +) +``` + +Fetch and update sweep data logged to the run from GraphQL database. + + + + +### `snake_to_camel` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/attrs.py#L14-L16) + +```python +snake_to_camel( + string +) +``` + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/apis/public/sweeps.py#L425-L433) + +```python +to_html( + height=420, hidden=(False) +) +``` + +Generate HTML containing an iframe displaying this sweep. + +| Class Variables | | +| :--- | :--- | +| `LEGACY_QUERY` | | +| `QUERY` | | diff --git a/content/en/ref/python/run.md b/content/en/ref/python/run.md new file mode 100644 index 0000000000..ba4af9e79b --- /dev/null +++ b/content/en/ref/python/run.md @@ -0,0 +1,1006 @@ +--- +title: Run +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L477-L4017 >}} + +A unit of computation logged by W&B. Typically, this is an ML experiment. + +Call [`wandb.init()`](https://docs.wandb.ai/ref/python/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](https://docs.wandb.ai/guides/track/log/distributed-training) +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](https://docs.wandb.ai/guides/track/launch) or +[`wandb.init`](https://docs.wandb.ai/ref/python/init/) API reference page +or more information. + +There is a another `Run` object in the +[`wandb.apis.public`](https://docs.wandb.ai/ref/python/public-api/api/) +namespace. Use this object is to interact with runs that have already been +created. + +#### Examples: + +Create a run with `wandb.init()`: + +```python +import wandb + +# Start a new run and log some data +# Use context manager (`with` statement) to automatically finish the run +with wandb.init(entity="entity", project="project") as run: + run.log({"accuracy": acc, "loss": loss}) +``` + + + + +| 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/guides/track/log/log-summary/). | +| `config` | Config object associated with this run. | +| `config_static` | Static config object associated with this run. | +| `dir` | The directory where files associated with the run are saved. | +| `disabled` | True if the run is disabled, False otherwise. | +| `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. | +| `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. | +| `id` | Identifier for this 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](https://docs.wandb.ai/guides/runs/#organize-runs). | +| `name` | Display name of the run. Display names are not guaranteed to be unique and may be descriptive. By default, they are randomly generated. | +| `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$`. | +| `offline` | True if the run is offline, False otherwise. | +| `path` | Path to the run. Run paths include entity, project, and run ID, in the format `entity/project/run_id`. | +| `project` | Name of the W&B project associated with the 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. | +| `resumed` | True if the run was resumed, False otherwise. | +| `settings` | A frozen copy of run's Settings object. | +| `start_time` | Unix timestamp (in seconds) of when the run started. | +| `starting_step` | The first step of the run. | +| `step` | Current value of the step. This counter is incremented by `wandb.Run.log()`. | +| `sweep_id` | Identifier for the sweep associated with the run, if there is one. | +| `sweep_url` | URL of the sweep associated with the run, if there is one. Offline runs do not have a sweep URL. | +| `tags` | Tags associated with the run, if there are any. | +| `url` | The url for the W&B run, if there is one. Offline runs will not have a url. | + +## Methods + +### `alert` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3594-L3628) + +```python +alert( + title: str, + text: str, + level: (str | AlertLevel | None) = None, + wait_duration: (int | float | timedelta | None) = None +) -> None +``` + +Create an alert with the given title and text. + +| Args | | +| :--- | :--- | +| `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`, or `ERROR`. | +| `wait_duration` | The time to wait (in seconds) before sending another alert with this title. | + +### `define_metric` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2785-L2850) + +```python +define_metric( + 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 +) -> wandb_metric.Metric +``` + +Customize metrics logged with `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 into `wandb.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 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. | + +| Returns | | +| :--- | :--- | +| An object that represents this call but can otherwise be discarded. | + +### `display` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1345-L1362) + +```python +display( + height: int = 420, + hidden: bool = (False) +) -> bool +``` + +Display this run in Jupyter. + +### `finish` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2230-L2263) + +```python +finish( + exit_code: (int | None) = None, + quiet: (bool | None) = None +) -> None +``` + +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. + +| Args | | +| :--- | :--- | +| `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 using `wandb.Settings(quiet=...)`. | + +### `finish_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3234-L3287) + +```python +finish_artifact( + artifact_or_path: (Artifact | str), + name: (str | None) = None, + type: (str | None) = None, + aliases: (list[str] | None) = None, + distributed_id: (str | None) = None +) -> Artifact +``` + +Finishes a non-finalized artifact as output of a run. + +Subsequent "upserts" with the same distributed ID will result in a new version. + +| Args | | +| :--- | :--- | +| `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 calling `wandb.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 include `dataset`, `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. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +### `get_project_url` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1055-L1071) + +```python +get_project_url() -> (str | None) +``` + +This method is deprecated and will be removed in a future release. Use `run.project_url` instead. + +URL of the W&B project associated with the run, if there is one. +Offline runs do not have a project URL. + + + + +### `get_sweep_url` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1189-L1205) + +```python +get_sweep_url() -> (str | None) +``` + +This method is deprecated and will be removed in a future release. Use `run.sweep_url` instead. + +The URL of the sweep associated with the run, if there is one. +Offline runs do not have a sweep URL. + + + + +### `get_url` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1219-L1234) + +```python +get_url() -> (str | None) +``` + +This method is deprecated and will be removed in a future release. Use `run.url` instead. + +URL of the W&B run, if there is one. Offline runs do not have a URL. + + + + +### `link_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2973-L3015) + +```python +link_artifact( + artifact: Artifact, + target_path: str, + aliases: (list[str] | None) = None +) -> Artifact +``` + +Link the given artifact to a portfolio (a promoted collection of artifacts). + +Linked artifacts are visible in the UI for the specified portfolio. + +| Args | | +| :--- | :--- | +| `artifact` | the (public or local) artifact which will be linked | +| `target_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. | + +| Returns | | +| :--- | :--- | +| The linked artifact. | + +### `link_model` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3513-L3592) + +```python +link_model( + path: StrPath, + registered_model_name: str, + name: (str | None) = None, + aliases: (list[str] | None) = None +) -> (Artifact | None) +``` + +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. + +| Args | | +| :--- | :--- | +| `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. | + +| Raises | | +| :--- | :--- | +| `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. | + +| Returns | | +| :--- | :--- | +| The linked artifact if linking was successful, otherwise `None`. | + +### `log` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1765-L2028) + +```python +log( + data: dict[str, Any], + step: (int | None) = None, + commit: (bool | None) = None +) -> None +``` + +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/guides/track/log) for +code snippets, best practices, and more. + +#### Basic usage: + +```python +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/guides/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/guides/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/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/guides/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 +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/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](https://docs.wandb.ai/guides/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 +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 +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) +``` + +| Args | | +| :--- | :--- | +| `data` | 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. | +| `step` | The step number to log. If `None`, 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. If `step` is `None`, then the default is `commit=True`; otherwise, the default is `commit=False`. | + +#### Examples: + +For more and more detailed examples, see +[our guides to logging](https://docs.wandb.com/guides/track/log). + +Basic usage + +```python +import wandb + +with wandb.init() as run: + run.log({"train-loss": 0.5, "accuracy": 0.9 +``` + +Incremental logging + +```python +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 +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 +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 +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 +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 +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 +import wandb + +with wandb.init() as run: + run.log({"pr": wandb.plot.pr_curve(y_test, y_probas, labels)}) +``` + +3D Object + +```python +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")), + ] + } + ) +``` + +| Raises | | +| :--- | :--- | +| `wandb.Error` | If called before `wandb.init()`. | +| `ValueError` | If invalid data is passed. | + +### `log_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3140-L3181) + +```python +log_artifact( + artifact_or_path: (Artifact | StrPath), + name: (str | None) = None, + type: (str | None) = None, + aliases: (list[str] | None) = None, + tags: (list[str] | None) = None +) -> Artifact +``` + +Declare an artifact as an output of a run. + +| Args | | +| :--- | :--- | +| `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 calling `wandb.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 include `dataset`, `model` | +| `aliases` | (list, optional) Aliases to apply to this artifact, defaults to `["latest"]` | +| `tags` | (list, optional) Tags to apply to this artifact, if any. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +### `log_code` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1086-L1187) + +```python +log_code( + 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]) = filenames.exclude_wandb_fn +) -> (Artifact | None) +``` + +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`. + +| Args | | +| :--- | :--- | +| `root` | 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-$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. This defaults to `lambda path, root: path.endswith(".py")`. | +| `exclude_fn` | 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 `/.wandb/` and `/wandb/` directories. | + +#### Examples: + +Basic usage + +```python +import wandb + +with wandb.init() as run: + run.log_code() +``` + +Advanced usage + +```python +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/" + ), + ) +``` + +| Returns | | +| :--- | :--- | +| An `Artifact` object if code was logged | + +### `log_model` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3436-L3471) + +```python +log_model( + path: StrPath, + name: (str | None) = None, + aliases: (list[str] | None) = None +) -> None +``` + +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. + +| Args | | +| :--- | :--- | +| `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"]` | + +| Raises | | +| :--- | :--- | +| `ValueError` | If name has invalid special characters. | + +| Returns | | +| :--- | :--- | +| None | + +### `mark_preempting` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3646-L3655) + +```python +mark_preempting() -> None +``` + +Mark this run as preempting. + +Also tells the internal process to immediately report this to server. + +### `project_name` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1031-L1045) + +```python +project_name() -> str +``` + +This method is deprecated and will be removed in a future release. Use `run.project` instead. + +Name of the W&B project associated with the run. + + + + +### `restore` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2214-L2228) + +```python +restore( + name: str, + run_path: (str | None) = None, + replace: bool = (False), + root: (str | None) = None +) -> (None | TextIO) +``` + +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. + +| Args | | +| :--- | :--- | +| `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 locally | +| `root` | 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 | | +| :--- | :--- | +| `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. | + +### `save` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2030-L2133) + +```python +save( + glob_str: (str | os.PathLike), + base_path: (str | os.PathLike | None) = None, + policy: PolicyName = "live" +) -> (bool | list[str]) +``` + +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. + +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. + +| 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 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 | + +| 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/". + +# Explicitly finish the run since a context manager is not used. +run.finish() +``` + +### `status` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2312-L2335) + +```python +status() -> RunStatus +``` + +Get sync info from the internal backend, about the current run's sync status. + +### `to_html` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L1364-L1377) + +```python +to_html( + height: int = 420, + hidden: bool = (False) +) -> str +``` + +Generate HTML containing an iframe displaying the current run. + + + + +### `unwatch` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2961-L2971) + +```python +unwatch( + models: (torch.nn.Module | Sequence[torch.nn.Module] | None) = None +) -> None +``` + +Remove pytorch model topology, gradient and parameter hooks. + +| Args | | +| :--- | :--- | +| `models` | Optional list of pytorch models that have had watch called on them. | + +### `upsert_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3183-L3232) + +```python +upsert_artifact( + artifact_or_path: (Artifact | str), + name: (str | None) = None, + type: (str | None) = None, + aliases: (list[str] | None) = None, + distributed_id: (str | None) = None +) -> 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. + +| Args | | +| :--- | :--- | +| `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 include `dataset`, `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. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +### `use_artifact` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3017-L3138) + +```python +use_artifact( + artifact_or_name: (str | Artifact), + type: (str | None) = None, + aliases: (list[str] | None) = None, + use_as: (str | None) = None +) -> Artifact +``` + +Declare an artifact as an input to a run. + +Call `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 ("" or "/"). 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 artifact | +| `use_as` | This argument is deprecated and does nothing. | + +| Returns | | +| :--- | :--- | +| An `Artifact` object. | + +#### Examples: + +```python +import wandb + +run = wandb.init(project="") + +# Use an artifact by name and alias +artifact_a = run.use_artifact(artifact_or_name=":") + +# Use an artifact by name and version +artifact_b = run.use_artifact(artifact_or_name=":v") + +# Use an artifact by entity/project/name:alias +artifact_c = run.use_artifact( + artifact_or_name="//:" +) + +# Use an artifact by entity/project/name:version +artifact_d = run.use_artifact( + artifact_or_name="//:v" +) + +# Explicitly finish the run since a context manager is not used. +run.finish() +``` + +### `use_model` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3473-L3511) + +```python +use_model( + name: str +) -> FilePathStr +``` + +Download the files logged in a model artifact 'name'. + +| Args | | +| :--- | :--- | +| `name` | 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 | + +| Returns | | +| :--- | :--- | +| path (str): Path to downloaded model artifact file(s). | + +| Raises | | +| :--- | :--- | +| `AssertionError` | If model artifact 'name' is of a type that does not contain the substring 'model'. | + +### `watch` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2930-L2959) + +```python +watch( + 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) +) -> None +``` + +Hook into given PyTorch model to monitor gradients and the model's computational graph. + +This function can track parameters, gradients, or both during training. + +| Args | | +| :--- | :--- | +| `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 with `wandb.watch`. (default=None) | +| `log_graph` | Whether to log the model's computational graph. (default=False) | + +| Raises | | +| :--- | :--- | +| `ValueError` | If `wandb.init()` has not been called or if any of the models are not instances of `torch.nn.Module`. | + +### `__enter__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3630-L3631) + +```python +__enter__() -> Run +``` + +### `__exit__` + +[View source](https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L3633-L3644) + +```python +__exit__( + exc_type: type[BaseException], + exc_val: BaseException, + exc_tb: TracebackType +) -> bool +``` diff --git a/content/en/ref/python/save.md b/content/en/ref/python/save.md new file mode 100644 index 0000000000..e45d6161c1 --- /dev/null +++ b/content/en/ref/python/save.md @@ -0,0 +1,66 @@ +--- +title: save +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2030-L2133 >}} + +Sync one or more files to W&B. + +```python +save( + glob_str: (str | os.PathLike), + base_path: (str | os.PathLike | None) = None, + policy: PolicyName = "live" +) -> (bool | list[str]) +``` + +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. + +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. + +| 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 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 | + +| 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/". + +# Explicitly finish the run since a context manager is not used. +run.finish() +``` diff --git a/content/en/ref/python/sweep.md b/content/en/ref/python/sweep.md new file mode 100644 index 0000000000..fa8c046ce0 --- /dev/null +++ b/content/en/ref/python/sweep.md @@ -0,0 +1,36 @@ +--- +title: sweep +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_sweep.py#L34-L93 >}} + +Initialize a hyperparameter sweep. + +```python +sweep( + sweep: Union[dict, Callable], + entity: Optional[str] = None, + project: Optional[str] = None, + prior_runs: Optional[List[str]] = None +) -> str +``` + +Search for hyperparameters that optimizes a cost function +of a machine learning model by testing various combinations. + +Make note the unique identifier, `sweep_id`, that is returned. +At a later step provide the `sweep_id` to a sweep agent. + +See [Sweep configuration structure](https://docs.wandb.ai/guides/sweeps/define-sweep-configuration) +for information on how to define your sweep. + +| Args | | +| :--- | :--- | +| `sweep` | The configuration of a hyperparameter search. (or configuration generator). If you provide a callable, ensure that the callable does not take arguments and that it returns a dictionary that conforms to the W&B sweep config spec. | +| `entity` | The username or team name where you want to send W&B runs created by the sweep to. Ensure that the entity you specify already exists. If you don't specify an entity, the run will be sent to your default entity, which is usually your username. | +| `project` | The name of the project where W&B runs created from the sweep are sent to. If the project is not specified, the run is sent to a project labeled 'Uncategorized'. | +| `prior_runs` | The run IDs of existing runs to add to this sweep. | + +| Returns | | +| :--- | :--- | +| `str` | A unique identifier for the sweep. | diff --git a/content/en/ref/python/watch.md b/content/en/ref/python/watch.md new file mode 100644 index 0000000000..ae5943cadf --- /dev/null +++ b/content/en/ref/python/watch.md @@ -0,0 +1,33 @@ +--- +title: watch +--- + +{{< cta-button githubLink=https://www.github.com/wandb/wandb/tree/v0.22.2/wandb/sdk/wandb_run.py#L2930-L2959 >}} + +Hook into given PyTorch model to monitor gradients and the model's computational graph. + +```python +watch( + 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) +) -> None +``` + +This function can track parameters, gradients, or both during training. + +| Args | | +| :--- | :--- | +| `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 with `wandb.watch`. (default=None) | +| `log_graph` | Whether to log the model's computational graph. (default=False) | + +| Raises | | +| :--- | :--- | +| `ValueError` | If `wandb.init()` has not been called or if any of the models are not instances of `torch.nn.Module`. |