Skip to main content
Use reference artifacts to track and use files saved outside W&B servers, so you can version and reference large datasets and models without copying them into W&B. Common external storage solutions include: CoreWeave AI Object Storage, an Amazon Simple Storage Service (Amazon S3) bucket, GCS bucket, Azure blob, HTTP file server, or NFS share. Reference artifacts behave like non-reference artifacts. The key difference is that a reference artifact only consists of metadata about the files, such as their sizes and MD5 checksums. The files themselves never leave your system. You can interact with reference artifacts the same way you interact with non-reference artifacts. In the W&B App, you can browse the contents of the reference artifact using the file browser, explore the full dependency graph, and scan through the versioned history of your artifact. However, the UI can’t render rich media such as images and audio, because the artifact doesn’t contain the data itself.
If you log an artifact that doesn’t track external files, W&B saves the artifact’s files to W&B servers. This is the default behavior when you log artifacts with the W&B Python SDK.If you log an artifact that tracks external files, W&B logs metadata about the object, such as the object’s ETag and size. If object versioning is enabled on the bucket, W&B also logs the version ID.
The following sections describe how to track external reference artifacts.

Track an artifact in an external bucket

Use the W&B Python SDK to track references to files stored outside W&B.
  1. Initialize a run with wandb.init().
  2. Create an artifact object with wandb.Artifact().
  3. Specify the reference to the bucket path with the artifact object’s wandb.Artifact.add_reference() method.
  4. Log the artifact’s metadata with run.log_artifact().
import wandb

# Initialize a W&B run
with wandb.init(project="my-project") as run:

  # Create an artifact object
  artifact = wandb.Artifact(name="name", type="type")

  # Add a reference to the bucket path
  artifact.add_reference(uri = "uri/to/your/bucket/path")

  # Log the artifact's metadata
  run.log_artifact(artifact)
As an example, suppose your bucket has the following directory structure:
s3://my-bucket

|datasets/
  |-- mnist/
|models/
  |-- cnn/
The datasets/mnist/ directory contains a collection of images. To track the image datasets/mnist/ directory as a dataset artifact, specify:
  1. Provide a name for the artifact, such as "mnist".
  2. Set the type parameter to "dataset" when you construct the artifact object (wandb.Artifact(type="dataset")).
  3. When you call wandb.Artifact.add_reference(), provide the path to the datasets/mnist/ directory as an Amazon S3 URI (s3://my-bucket/datasets/mnist/).
  4. Log the artifact with run.log_artifact().
The following code sample creates a reference artifact mnist:latest:
import wandb

with wandb.init(project="my-project") as run:
  artifact = wandb.Artifact(name="mnist", type="dataset")
  artifact.add_reference(uri="s3://my-bucket/datasets/mnist")
  run.log_artifact(artifact)
Within the W&B App, you can browse the contents of the reference artifact using the file browser, explore the full dependency graph, and scan through the versioned history of your artifact. The W&B App doesn’t render rich media such as images or audio because the artifact doesn’t contain the data itself.
W&B Artifacts support any Amazon S3 compatible interface, including CoreWeave AI Object Storage and MinIO. The following scripts work without modification with both providers, when you set the AWS_S3_ENDPOINT_URL environment variable to point at your CoreWeave AI Object Storage or MinIO server.
By default, W&B imposes a 10,000 object limit when adding an object prefix. You can adjust this limit by specifying max_objects= when you call wandb.Artifact.add_reference().

Download an artifact from an external bucket

After you log a reference artifact, you can download it later to retrieve the original files from the bucket. When W&B downloads a reference artifact, it retrieves the files from the underlying bucket using the metadata recorded when you logged the artifact. If your bucket has object versioning enabled, W&B retrieves the object version that corresponds to the state of the file at the time the artifact was logged. As you evolve the contents of your bucket, you can point to the exact version of your data a given model was trained on, because the artifact serves as a snapshot of your bucket during the training run. The following code sample shows how to download a reference artifact. The APIs for downloading artifacts are the same for both reference and non-reference artifacts:
import wandb

with wandb.init(project="my-project") as run:
  artifact = run.use_artifact("mnist:latest", type="dataset")
  artifact_dir = artifact.download()
If you overwrite files as part of your workflow, W&B recommends that you enable ‘Object Versioning’ on your storage buckets.If versioning is enabled, W&B can retrieve the correct version of the file when you download an artifact, even if the file has been overwritten since you logged the artifact.Based on your use case, read the instructions to enable object versioning: AWS, Google Cloud, Azure.

Add and download an external file from a bucket

The following code sample uploads a dataset to an Amazon S3 bucket, tracks it with a reference artifact, then downloads it:
import boto3
import wandb

with wandb.init() as run:
  # Training here...

  s3_client = boto3.client("s3")
  s3_client.upload_file(file_name="my_model.h5", bucket="my-bucket", object_name="models/cnn/my_model.h5")

  # Log the model artifact
  model_artifact = wandb.Artifact("cnn", type="model")
  model_artifact.add_reference("s3://my-bucket/models/cnn/")
  run.log_artifact(model_artifact)
To download the model artifact later, specify the name of the artifact and its type:
import wandb

with wandb.init() as run:
  artifact = run.use_artifact(artifact_or_name = "cnn", type="model")
  datadir = artifact.download()
See the following reports for an end-to-end walkthrough on how to track artifacts by reference for Google Cloud or Azure:

Cloud storage credentials

To read from and write to your external bucket, W&B needs credentials configured in your environment. W&B uses the default mechanism to look for credentials based on the cloud provider you use. To learn more about the credentials used, read the documentation from your cloud provider:
Cloud providerCredentials documentation
CoreWeave AI Object StorageCoreWeave AI Object Storage documentation
AWSBoto3 documentation
Google CloudGoogle Cloud documentation
AzureAzure documentation
For AWS, if the bucket isn’t located in the configured user’s default region, you must set the AWS_REGION environment variable to match the bucket region.
Rich media such as images, audio, video, and point clouds may fail to render in the App UI depending on the CORS configuration of your bucket. To resolve rendering issues, allowlist app.wandb.ai in your bucket’s CORS policy.

Track an artifact in a filesystem

A common pattern for accessing datasets is to expose an NFS mount point to a remote filesystem on all machines running training jobs. This can be an alternative to a cloud storage bucket because, from the perspective of the training script, the files appear local to your filesystem. To track an artifact in a filesystem:
  1. Initialize a run with wandb.init().
  2. Create an artifact object with wandb.Artifact().
  3. Specify the reference to the filesystem path with the artifact object’s wandb.Artifact.add_reference() method.
  4. Log the artifact’s metadata with run.log_artifact().
To track files in a mounted filesystem, copy and paste the following code snippet. Replace the values enclosed in angle brackets (< >) with your own values.
import wandb

# Initialize a run
with wandb.init(entity="<entity>", project="<project>") as run:

  # Create an artifact object
  artifact = wandb.Artifact(name="<name>", type="<type>")

  # Add a reference to the filesystem path
  artifact.add_reference("file:///path/to/dataset/")

  # Log the artifact (metadata only)
  run.log_artifact(artifact)
Note the triple slash in the URL. The first component is the file:// prefix that denotes the use of filesystem references. The second component is the root / of the filesystem. The remaining components are the path to the directory or file you want to track. As an example, suppose you have a filesystem mounted at /mount with the following structure:
mount
|datasets/
  |-- mnist/
|models/
  |-- cnn/
To track the datasets/mnist/ directory as a dataset artifact, use the following code snippet:
import wandb

with wandb.init() as run:
  artifact = wandb.Artifact("mnist", type="dataset")
  artifact.add_reference("file:///mount/datasets/mnist/")
  run.log_artifact(artifact)
This creates a reference artifact mnist:latest that points to the files stored under /mount/datasets/mnist/.
By default, W&B imposes a 10,000 file limit when adding a reference to a directory. You can adjust this limit by specifying max_objects= when you call wandb.Artifact.add_reference().
Similarly, to track a model stored at models/cnn/my_model.h5, use the following code snippet:
import wandb

with wandb.init() as run:

  # Training here...

  # Write model to disk

  # Create an artifact object
  model_artifact = wandb.Artifact("cnn", type="model")

  # Add a reference to the model file path
  model_artifact.add_reference("file:///mount/cnn/my_model.h5")

  # Log the artifact to W&B
  run.log_artifact(model_artifact)

Download an artifact from an external filesystem

After you log a filesystem reference artifact, you can download it later to retrieve the original files from the mounted filesystem. Download files from a referenced filesystem using the same APIs as non-reference artifacts:
  1. Initialize a run with wandb.init().
  2. Use the wandb.Run.use_artifact() method to indicate the artifact you want to download.
  3. Call the artifact’s wandb.Artifact.download() method to download the files from the referenced filesystem.
with wandb.init() as run:
  artifact = run.use_artifact("entity/project/mnist:latest", type="dataset")
  artifact_dir = artifact.download()
W&B copies the contents of /mount/datasets/mnist to the artifacts/mnist:v0/ directory.
Artifact.download() throws an error if it can’t reconstruct the artifact. For example, if an artifact contains a reference to a file that was overwritten, Artifact.download() throws an error because the artifact can no longer be reconstructed.