scaffold.data.artifact_manager.wandb
Attributes
Classes
Artifact manager that uses Weights & Biases (WandB) as the backend. |
Module Contents
- class scaffold.data.artifact_manager.wandb.WandbArtifactManager(entity: str | None = None, project: str | None = None, collection: str = 'default')
Bases:
scaffold.data.artifact_manager.base.ArtifactManagerArtifact manager that uses Weights & Biases (WandB) as the backend.
This manager logs artifacts to WandB. In WandB, collections correspond to artifact types. Each artifact can contain multiple files, and versions are managed implicitly.
Note
It is assumed that wandb.init() has been called before using this manager.
Initialize the WandbArtifactManager.
- Parameters:
entity (Optional[str]) – If not provided, it’s inferred from the active run / API settings.
project (Optional[str]) – If not provided, it’s inferred from the active run / API settings.
collection (str) – The default collection (artifact type) name. Defaults to “default”.
- Raises:
ValueError – If neither a project nor an active project can be identified.
- download_artifact(artifact_name: str, collection: str | None = None, version: str | None = None, to: str | None = None) scaffold.data.artifact_manager.base.Artifact | scaffold.data.artifact_manager.base.TmpArtifact
Download a specific artifact to a local path.
WandB artifacts are downloaded in a nested folder structure.
- Parameters:
artifact_name (str) – The name of the artifact to download.
collection (Optional[str]) – The collection (artifact type) name. Defaults to the active collection.
version (Optional[str]) – The version of the artifact to download. If None, ‘latest’ is used.
to (Optional[str]) – The local destination path where the artifact should be downloaded. If not provided, a TmpArtifact context manager is returned.
- Returns:
- If to is provided, returns an Artifact with metadata.
Otherwise, returns a TmpArtifact context manager that also has an artifact property.
- Return type:
Union[Artifact, TmpArtifact]
- exists_in_collection(artifact_name: str, collection: str | None = None) bool
Check if an artifact exists in the specified collection.
Note
The WandB API does not provide a direct existence check, so this is implemented by listing all artifacts in the collection.
- Parameters:
artifact_name (str) – The artifact name.
collection (Optional[str]) – The collection (artifact type) name. Defaults to the active collection.
- Returns:
True if the artifact exists in the collection, False otherwise.
- Return type:
bool
- list_collection_names() Iterable[str]
List all collections (artifact types) managed by WandB.
- Returns:
A list of collection names corresponding to WandB artifact types.
- Return type:
Iterable[str]
- log_files(artifact_name: str, local_path: str, description: str, collection: str | None = None, artifact_path: str | None = None) scaffold.data.artifact_manager.base.Artifact
Log files or a directory as a WandB artifact.
This method uploads the file or directory located at local_path to WandB. If local_path is a directory, it uses add_dir; otherwise, it uses add_file.
- Parameters:
artifact_name (str) – The artifact name.
local_path (str) – The local path to the file or directory to be logged.
description (str) – The artifact description. Is ignored for this ArtifactManager implementation.
collection (Optional[str]) – The collection (artifact type) name. Defaults to the active collection.
artifact_path (Optional[str]) – An optional subpath within the artifact.
- Returns:
- The logged artifact with its metadata (name, collection, version).
For WandB, the version is typically “latest” as WandB manages versions internally.
- Return type:
- scaffold.data.artifact_manager.wandb.logger