Model Registry
Publish, deploy, and manage ML models for production serving.
Overview
The Model Registry provides a two-step workflow:
- Publish - Register model artifacts to the registry
- 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):
Option 1: Model Object (Recommended)
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 modelslightgbm- LightGBM modelspytorch- PyTorch models (state_dict)tensorflow- TensorFlow/Keras modelscustom- 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
| Parameter | Default | Description |
|---|---|---|
cpu | 1 | Number of CPU cores |
memory_gb | 2 | Memory in GB |
gpu | 0 | Number of GPUs |
replicas | 1 | Number 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
| Function | Description |
|---|---|
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
| Parameter | Type | Description |
|---|---|---|
name | str | Model name (required) |
framework | str | ML framework (sklearn, pytorch, etc.) |
model | Any | Python model object to serialize |
artifact_path | str | Path to local model file |
volume_path | str | Path in project/shared volume |
description | str | Model description |
tags | list | Metadata tags |
RegisteredModel Methods
| Method | Description |
|---|---|
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
| Property | Description |
|---|---|
model.model_id | Unique model ID |
model.name | Model name |
model.framework | ML framework |
model.status | Deployment status |
model.endpoint | Prediction endpoint URL |
model.tags | Metadata tags |
Deployment Status Values
| Status | Description |
|---|---|
registered | Published but not deployed |
building | Building container image |
deploying | Deploying to infrastructure |
running | Deployed and serving |
stopped | Deployment stopped |
failed | Deployment failed |