Skip to main content

Artifacts Use Cases

Examples of how artifacts are used


Artifacts provide a flexible, versioned way to store and manage files produced throughout the ML and data lifecycle. They are especially useful for preserving intermediate outputs, enabling reproducibility, and sharing results across teams and environments.

Example Use Cases

Model Training Workflows

You can upload model checkpoints to the Clarifai platform after each training run or epoch. If training is interrupted, you can resume from the most recent checkpoint instead of starting from scratch.

from clarifai.client.artifact import Artifact
from clarifai.client.artifact_version import ArtifactVersion

# 1. Create an artifact to store model files
artifact = Artifact().create(
artifact_id="image-classifier-v1",
user_id="user-id",
app_id="app-id"
)

# 2. Upload the initial trained model
initial_version = ArtifactVersion().upload(
file_path="./trained_model.pt",
artifact_id="image-classifier-v1",
user_id="user-id",
app_id="app-id",
description="Initial training run – 95% accuracy",
visibility="org"
)

print(f"Uploaded version: {initial_version.id}")

# 3. Upload an improved model later
improved_version = ArtifactVersion().upload(
file_path="./improved_model.pt",
artifact_id="image-classifier-v1",
user_id="user-id",
app_id="app-id",
version_id="v20",
description="Improved model – 97.5% accuracy",
visibility="public"
)

Model Deployment

You can retrieve the latest approved model artifact and download it locally for deployment in production environments.

from clarifai.client.artifact import Artifact
from clarifai.client.artifact_version import ArtifactVersion

# 1. List available model artifacts
artifact_client = Artifact()
print("Available models:")

for artifact_pb in artifact_client.list(
user_id="user-id",
app_id="app-id"
):
print(f"- {artifact_pb.id}")

# 2. Access versions of a specific model
version_client = ArtifactVersion(
artifact_id="image-classifier-v1",
user_id="user-id",
app_id="app-id"
)

versions = list(version_client.list())
latest_version = versions[0] # Assumes versions are ordered by recency

# 3. Download the latest version for deployment
downloaded_path = version_client.download(
output_path="./production_model.pt",
version_id=latest_version.id,
force=True
)

print(f"Downloaded model to: {downloaded_path}")

Pipeline Outputs

You can store evaluation metrics, preprocessed embeddings, serialized configurations, or logs produced by pipeline steps. These artifacts can be reused in downstream pipelines, audited later, or shared across teams.

Experiment Tracking

You can use artifacts as a versioned record of experiment outputs. Track how model performance evolves over time, compare results across hyperparameter configurations, and ensure experiments remain reproducible.

Error Handling Examples

You can handle common failure cases gracefully when uploading or downloading artifacts.

from clarifai.client.artifact_version import ArtifactVersion
from clarifai.errors import UserError

try:
# Upload with missing required parameters
ArtifactVersion().upload(
file_path="./model.pt"
# Missing artifact_id, user_id, and app_id
)
except UserError as e:
print(f"Upload failed: {e}")

try:
# Attempt to download a non-existent artifact version
ArtifactVersion().download(
output_path="./model.pt",
artifact_id="non-existent",
version_id="v999",
user_id="user-id",
app_id="app-id"
)
except UserError as e:
print(f"Download failed: {e}")