Snowpark ML Model Registry
The Snowpark ML Model Registry provides a centralized repository for managing machine learning models within Snowflake. It handles versioning, metadata tracking, and deployment — all without moving data outside the platform.
Why a Model Registry?
Without a registry, teams resort to saving pickle files on local disks or object storage with ad-hoc naming conventions. This leads to lost models, version confusion, and no audit trail. The Model Registry solves these problems natively inside Snowflake.
Core Concepts
| Concept | Description |
|---|---|
| Registry | A schema-level catalog of all logged models |
| Model | A named entry representing a logical ML model |
| Version | A specific trained instance of a model with artifacts |
| Tag | Key-value metadata attached to a model or version |
| Deployment | Serving a model version as a Snowflake UDF |
Setting Up the Registry
from snowflake.ml.registry import Registry
reg = Registry(session=session, database_name="ML_DB", schema_name="REGISTRY")
The registry uses the specified schema to store model artifacts and metadata in managed Snowflake objects.
Logging a Model
After training a model, log it to the registry with log_model.
from sklearn.ensemble import RandomForestClassifier
from snowflake.ml.modeling.metrics import accuracy_score
# Train
clf = RandomForestClassifier(n_estimators=100, random_state=42)
clf.fit(X_train, y_train)
# Log
model_ref = reg.log_model(
model_name="churn_classifier",
version_name="v1",
model=clf,
sample_input_data=train_df.select(feature_cols).limit(10),
comment="Baseline RF model, 100 trees"
)
Required and Optional Parameters
| Parameter | Required | Description |
|---|---|---|
model_name | Yes | Logical name for the model |
version_name | Yes | Unique version identifier |
model | Yes | Trained model object |
sample_input_data | No | Example input for schema inference |
comment | No | Free-text description |
metrics | No | Dict of evaluation metrics |
conda_dependencies | No | Additional package requirements |
Adding Metrics and Tags
model_ref.set_metric("accuracy", 0.934)
model_ref.set_metric("f1_score", 0.891)
model_ref.set_tag("team", "data-science")
model_ref.set_tag("use_case", "customer-churn")
Listing Models and Versions
# List all models
models = reg.show_models()
print(models)
# Get a specific model
model = reg.get_model("churn_classifier")
# List versions of a model
versions = model.show_versions()
print(versions)
Loading and Running Inference
Retrieve a logged model version and use it for predictions.
# Get model version reference
mv = reg.get_model("churn_classifier").version("v1")
# Run inference on a Snowpark DataFrame
predictions = mv.run(test_df.select(feature_cols), function_name="predict")
predictions.show()
Deploying as a UDF
Model versions can be deployed as vectorized UDFs for use in SQL queries.
# The run method already creates a temporary UDF internally.
# For a permanent UDF, use the model version in SQL context:
mv.create_service(
service_name="CHURN_PREDICT_SVC",
compute_pool="ML_POOL"
)
After deployment, call the model from SQL:
SELECT
CUSTOMER_ID,
CHURN_PREDICT_SVC!PREDICT(INCOME, BALANCE, TENURE_MONTHS) AS CHURN_PREDICTION
FROM ANALYTICS.CUSTOMERS;
Deleting Models and Versions
# Delete a specific version
model = reg.get_model("churn_classifier")
model.delete_version("v1")
# Delete the entire model (all versions)
reg.delete_model("churn_classifier")
Practical Workflow
A typical end-to-end workflow follows these steps:
- Preprocess data using Snowpark ML transformers.
- Train a model within Snowpark or using a local framework.
- Evaluate on a holdout set and compute metrics.
- Log the model with
log_model, attaching metrics and tags. - Compare versions by querying metrics across versions.
- Deploy the best version as a service or use
runfor batch inference. - Monitor by logging new metrics over time and retraining when performance degrades.
Access Control
Model Registry operations require appropriate privileges:
| Operation | Required Privilege |
|---|---|
| Log a model | CREATE MODEL on schema |
| Read/list models | USAGE on schema |
| Run inference | USAGE on model |
| Delete model | OWNERSHIP on model |
Key Takeaways
- The Model Registry lives inside Snowflake — no external MLflow or artifact store needed.
- Every model version is immutable and auditable.
- Use
log_modelto persist trained models with metadata, metrics, and tags. - Deploy model versions for batch or real-time inference directly in SQL.