Artifacts & Model Registry
Version datasets and models, track data lineage from raw data to deployed model, and manage model lifecycle with the W&B Model Registry.
What are Artifacts?
W&B Artifacts are versioned, immutable snapshots of files and directories. They enable:
- Dataset versioning: Track every version of your training data.
- Model versioning: Save model checkpoints with full lineage.
- Lineage tracking: Visualize which data produced which model.
- Deduplication: Files are content-addressed; identical files are stored once.
Logging Artifacts
import wandb
run = wandb.init(project="artifacts-demo")
# Create a dataset artifact
dataset = wandb.Artifact(
name="cifar10-processed",
type="dataset",
description="CIFAR-10 with augmentation applied",
metadata={"num_classes": 10, "split": "train"}
)
# Add files or directories
dataset.add_file("data/train.npz")
dataset.add_dir("data/augmented/")
# Log the artifact (creates version v0, v1, v2, ...)
run.log_artifact(dataset)
# Create a model artifact
model_artifact = wandb.Artifact(
name="resnet50-classifier",
type="model",
description="ResNet-50 trained on CIFAR-10"
)
model_artifact.add_file("checkpoints/best_model.pt")
model_artifact.add_file("checkpoints/config.json")
run.log_artifact(model_artifact)
Using Artifacts
run = wandb.init(project="artifacts-demo")
# Download the latest version
artifact = run.use_artifact("cifar10-processed:latest")
data_dir = artifact.download()
# Or use a specific version
artifact_v2 = run.use_artifact("cifar10-processed:v2")
data_dir = artifact_v2.download()
# Or use an alias
artifact_prod = run.use_artifact("resnet50-classifier:production")
model_dir = artifact_prod.download()
# Load the model
import torch
model = torch.load(f"{model_dir}/best_model.pt")
Model Registry
The W&B Model Registry provides a centralized place to manage model versions, aliases, and stage transitions.
import wandb
run = wandb.init(project="model-registry-demo")
# Log a model artifact
model_artifact = wandb.Artifact("fraud-detector", type="model")
model_artifact.add_file("model.pt")
run.log_artifact(model_artifact)
# Link to the Model Registry
run.link_artifact(
model_artifact,
"model-registry/fraud-detector",
aliases=["latest", "staging"]
)
# Later, promote to production (via UI or API)
api = wandb.Api()
artifact = api.artifact("entity/project/fraud-detector:staging")
artifact.aliases.append("production")
artifact.save()
Lineage Graph
W&B automatically tracks the lineage of artifacts:
Raw Data (v0)
└── Preprocessing Run
└── Processed Dataset (v0)
└── Training Run (config: lr=0.001, epochs=50)
└── Model Checkpoint (v0)
└── Evaluation Run
└── Metrics Report (v0)
# Each arrow is tracked automatically
# Click any artifact in the UI to see its full history
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX