Skip to main content

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​

ConceptDescription
RegistryA schema-level catalog of all logged models
ModelA named entry representing a logical ML model
VersionA specific trained instance of a model with artifacts
TagKey-value metadata attached to a model or version
DeploymentServing 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​

ParameterRequiredDescription
model_nameYesLogical name for the model
version_nameYesUnique version identifier
modelYesTrained model object
sample_input_dataNoExample input for schema inference
commentNoFree-text description
metricsNoDict of evaluation metrics
conda_dependenciesNoAdditional 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:

  1. Preprocess data using Snowpark ML transformers.
  2. Train a model within Snowpark or using a local framework.
  3. Evaluate on a holdout set and compute metrics.
  4. Log the model with log_model, attaching metrics and tags.
  5. Compare versions by querying metrics across versions.
  6. Deploy the best version as a service or use run for batch inference.
  7. Monitor by logging new metrics over time and retraining when performance degrades.

Access Control​

Model Registry operations require appropriate privileges:

OperationRequired Privilege
Log a modelCREATE MODEL on schema
Read/list modelsUSAGE on schema
Run inferenceUSAGE on model
Delete modelOWNERSHIP 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_model to persist trained models with metadata, metrics, and tags.
  • Deploy model versions for batch or real-time inference directly in SQL.