Skip to main content

Model Registry

Publish, deploy, and manage ML models for production serving.

Overview

The Model Registry provides a two-step workflow:

  1. Publish - Register model artifacts to the registry
  2. Deploy - Deploy from registry with hardware configuration

Key features:

  • Model object upload (auto-serialization)
  • Volume path references for large models
  • Hardware configuration (CPU, memory, GPU)
  • Prediction endpoint management

Basic Usage

from sklearn.ensemble import RandomForestClassifier
from strongly_python.mlops import register_model

# Train your model
clf = RandomForestClassifier(n_estimators=100)
clf.fit(X_train, y_train)

# Step 1: Publish model to registry
model = register_model(
name="churn-classifier",
framework="sklearn",
model=clf, # Pass model object directly
description="Predicts customer churn"
)

# Step 2: Deploy with hardware config
model.deploy(cpu=2, memory_gb=4, wait=True)

# Make predictions
result = model.predict({"features": [[1, 2, 3, 4]]})
print(result)

Publishing Models

Three options for publishing model artifacts (choose one):

Pass a Python model object directly - it will be serialized automatically:

from sklearn.ensemble import RandomForestClassifier
from strongly_python.mlops import register_model

clf = RandomForestClassifier().fit(X_train, y_train)

model = register_model(
name="my-classifier",
framework="sklearn",
model=clf,
description="Customer churn prediction"
)

Supported frameworks for auto-serialization:

  • sklearn - scikit-learn models (uses joblib)
  • xgboost - XGBoost models
  • lightgbm - LightGBM models
  • pytorch - PyTorch models (state_dict)
  • tensorflow - TensorFlow/Keras models
  • custom - Custom models (uses pickle)

Option 2: Local File

Upload a model artifact from your local filesystem:

model = register_model(
name="xgb-model",
framework="xgboost",
artifact_path="./models/xgb_model.json"
)

Option 3: Volume Path

Reference a model file stored in your project or shared volume:

model = register_model(
name="production-model",
framework="sklearn",
volume_path="/project/models/trained_model.pkl"
)

Valid volume prefixes:

  • /project/ - Project-specific volume
  • /shared/ - Shared workspace volume
  • /workspace/ - Workspace volume

Deploying Models

Deploy registered models with hardware configuration:

# Deploy with default settings (1 CPU, 2GB memory)
model.deploy()

# Deploy with custom hardware
model.deploy(
cpu=4,
memory_gb=8,
gpu=1,
replicas=2,
wait=True, # Wait for deployment to complete
timeout=600 # Timeout in seconds
)

print(f"Status: {model.status}")
print(f"Endpoint: {model.endpoint}")

Hardware Configuration

ParameterDefaultDescription
cpu1Number of CPU cores
memory_gb2Memory in GB
gpu0Number of GPUs
replicas1Number of replicas

Making Predictions

Once deployed, make predictions through the model endpoint:

# Single prediction
result = model.predict({
"features": [[1.0, 2.0, 3.0, 4.0]]
})
print(result["predictions"])

# Batch prediction
result = model.predict({
"features": [
[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0]
]
})

Model Management

Start/Stop Deployment

# Stop a running model (saves resources)
model.stop()
print(f"Status: {model.status}") # "stopped"

# Restart the model
model.start()
print(f"Status: {model.status}") # "running"

Check Status

status = model.get_status()
print(f"Status: {status['status']}")
print(f"Endpoint: {status['endpoint']}")

View Logs

logs = model.get_logs()
for log in logs:
print(f"{log['timestamp']}: {log['message']}")

Delete Model

model.delete()

Querying Models

from strongly_python.mlops import get_model, list_models

# List all registered models
models = list_models()
for m in models:
print(f"{m.name}: {m.status} ({m.framework})")

# Get specific model by ID
model = get_model("abc123")
print(f"Name: {model.name}")
print(f"Status: {model.status}")
print(f"Endpoint: {model.endpoint}")

Complete Example

from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
from strongly_python.mlops import register_model, list_models

def main():
# Create sample data and train model
print("Training model...")
X, y = make_classification(n_samples=1000, n_features=10)
clf = RandomForestClassifier(n_estimators=50, random_state=42)
clf.fit(X, y)

# Step 1: Publish to registry
print("\n--- Publishing model to registry ---")
model = register_model(
name="demo-classifier",
framework="sklearn",
model=clf,
description="Demo classification model",
tags=["demo", "sklearn"]
)
print(f"Model ID: {model.model_id}")
print(f"Name: {model.name}")

# Step 2: Deploy with hardware config
print("\n--- Deploying model ---")
model.deploy(
cpu=2,
memory_gb=4,
gpu=0,
replicas=1,
wait=True
)
print(f"Status: {model.status}")
print(f"Endpoint: {model.endpoint}")

# Make predictions
print("\n--- Making predictions ---")
test_data = {"features": [X[0].tolist(), X[1].tolist()]}
result = model.predict(test_data)
print(f"Predictions: {result['predictions']}")

# List all models
print("\n--- All registered models ---")
for m in list_models():
print(f" - {m.name}: {m.status}")

# Cleanup
print("\n--- Stopping model ---")
model.stop()
print(f"Final status: {model.status}")

if __name__ == "__main__":
main()

Integration with Experiments

Link model registration to experiment tracking:

import strongly_python as strongly
from strongly_python.mlops import register_model

# Track training experiment
with strongly.start_run(run_name="model-training") as run:
# Train model
clf = RandomForestClassifier(n_estimators=100)
clf.fit(X_train, y_train)

# Log training metrics
strongly.log_params({"n_estimators": 100})
strongly.log_metrics({"accuracy": 0.92})

# Publish trained model to registry
model = register_model(
name="experiment-model",
framework="sklearn",
model=clf,
description=f"Model from run {run.run_id}"
)

# Deploy
model.deploy(cpu=2, memory_gb=4, wait=True)

API Reference

Model Registration

FunctionDescription
register_model(name, framework, ...)Publish model to registry
get_model(model_id)Get model by ID
list_models()List all registered models

register_model() Parameters

ParameterTypeDescription
namestrModel name (required)
frameworkstrML framework (sklearn, pytorch, etc.)
modelAnyPython model object to serialize
artifact_pathstrPath to local model file
volume_pathstrPath in project/shared volume
descriptionstrModel description
tagslistMetadata tags

RegisteredModel Methods

MethodDescription
model.deploy(cpu, memory_gb, gpu, replicas, wait)Deploy model
model.predict(data)Make predictions
model.start()Start stopped model
model.stop()Stop running model
model.get_status()Get deployment status
model.get_logs()Get deployment logs
model.update(description, tags)Update metadata
model.delete()Delete model

RegisteredModel Properties

PropertyDescription
model.model_idUnique model ID
model.nameModel name
model.frameworkML framework
model.statusDeployment status
model.endpointPrediction endpoint URL
model.tagsMetadata tags

Deployment Status Values

StatusDescription
registeredPublished but not deployed
buildingBuilding container image
deployingDeploying to infrastructure
runningDeployed and serving
stoppedDeployment stopped
failedDeployment failed