What you will be able to do
- Log a model version with the dependencies, signature and target platforms that serving needs
- Run inference from a registry version with mv.run or SQL model methods, and choose a warehouse or Snowpark Container Services
- Grant production roles the right privilege on a model: USAGE for warehouse inference, READ for SPCS
- Deploy a model version as an SPCS service with create_service
- Score in batches with a vectorized Python UDF and move files to internal stages with PUT and LIST
- Train and predict with SQL ML Functions and save their output to a table
Key concept
Registered model version as the unit of serving — Production inference in Snowflake starts from a model version logged in the Model Registry. You call that version from SQL, from Python, or through a REST endpoint, and the same logged artifact runs either on a virtual warehouse or in Snowpark Container Services.
1.The registry as the way into production
A trained model is only a Python object in a notebook until you log it. Logging it in the Snowflake Model Registry turns it into a first-class, schema-level object. The object has its own privileges, it shows up in the information schema, and it has methods you can call. Any schema can act as a registry without setup, though a dedicated schema such as ML.REGISTRY keeps production models in one place.
Once a version is logged, it can run in one of two places. A virtual warehouse runs the model's methods the way it runs functions or stored procedures, which suits CPU batch scoring. Snowpark Container Services (SPCS) serves the model in containers, which is the route to GPUs, large models and HTTP endpoints. The registry gives you one interface to both, so the choice comes down to latency, hardware and package needs, not a rewrite of your code.
The registry has built-in support for scikit-learn, xgboost, LightGBM, Prophet, CatBoost, PyTorch, TensorFlow, Keras, Hugging Face pipelines, Sentence Transformer and MLFlow pyfunc models. Custom processing code is supported as well. In Python you work with three classes: Registry manages the models in a schema, Model represents a model, and ModelVersion represents one version of it.
Checkpoint 1 of 7· Match them up
Match each Snowflake Model Registry Python class to its role
Tap a term, then the definition that fits it.
Registry works at the schema level, Model is the named model object, and ModelVersion is one specific version of that model. Inference and deployment start from a ModelVersion, which is why it is the unit of serving.
“snowflake.ml.registry.Registry: Manages models within a schema. snowflake.ml.model.Model: Represents a model. snowflake.ml.model.ModelVersion: Represents a version of a model.”Source: docs.snowflake.com
2.Logging a version so it can be served
Metadata such as comments and metrics is part of the logging step, and that side is covered under Model Registry: logging versions with metadata. For deployment, three arguments to log_model matter more: the input schema, the dependencies and the target platforms. If any of them is wrong, the version either refuses to log or will not run where you need it.
Input schema. Most models need either sample_input_data, a DataFrame from which the registry extracts feature names and types, or explicit signatures. Snowpark ML models, MLFlow models and Hugging Face pipelines are the exceptions. Snowflake can call a method only if it knows the method's input and output columns.
Dependencies. conda_dependencies lists Conda packages. If you give no channel, the Snowflake channel is assumed on a warehouse and conda-forge is assumed on SPCS. pip_requirements lists PyPI packages. A model that targets a warehouse needs an artifact repository for pip packages, which you set with artifact_repository_map. On SPCS you need a repository only when the packages are not on public PyPI, for example a private internal library.
Target platforms. target_platforms accepts WAREHOUSE, SNOWPARK_CONTAINER_SERVICES, or both. The check runs when you log, not when you serve. If you name WAREHOUSE and the model cannot run there because of its dependencies, a GPU requirement or its size, log_model() fails. The default is SPCS only inside Container Runtime and both platforms everywhere else.
mv = reg.log_model(
my_model,
model_name="internal_scoring_model",
version_name="v1",
target_platforms=target_platform.SNOWPARK_CONTAINER_SERVICES_ONLY,
sample_input_data=pandas_test_df,
pip_requirements=["internal-scoring-lib==1.2.3", "scikit-learn"],
artifact_repository_map={
"pip": "my_db.my_schema.my_python_repo"
},
)Preprocessing should travel with the model. If you fit the transforms and the estimator together as described in Snowflake ML preprocessing (scaling, normalization, encoding) in a Pipeline, you log the whole fitted Pipeline as the model object. Serving then applies the same scaling and encoding that training used, with no second copy of that logic in the scoring code. For files the model needs at load time, code_paths names directories of code to import, and user_files uploads local files into a stage subdirectory next to the model files.
Checkpoint 2 of 7· Check yourself
A team's model imports scikit-learn when it scores rows. They want Snowflake to install that library alongside the logged version, with no extra setup when it runs. Which log_model argument does this?
Packages the model needs at runtime are listed as dependencies, here in conda_dependencies, and Snowflake deploys them with the version. code_paths and user_files ship your own code directories and files. sample_input_data only gives the input schema (feature names and types), not the dependencies.
“You may specify conda_dependencies lists; the specified packages will be deployed with the model.”Source: docs.snowflake.com
Sources1
3.Running inference from a registry version
In Python, you get a version and call run. registry.get_model('my_model').version('my_version') returns a ModelVersion. mv.run(input_features, function_name="predict") scores a Snowpark or pandas DataFrame and returns a DataFrame of the same type. If you add service_name="example_spcs_service" to the same call, the scoring runs on the SPCS service instead of the warehouse. mv.show_functions() lists the methods you can call.
# Run inference on a warehouse
# mv: snowflake.ml.model.ModelVersion
remote_prediction = mv.run(input_features, function_name="predict")
remote_prediction.show()In SQL, you call the model's methods as functions. SELECT MODEL(my_model)!predict(...) FROM my_table uses the default version. MODEL(my_model, v1) or MODEL(my_model, production) targets a named version or an alias. A function deployed to a service is called as my_service!predict(...). SHOW FUNCTIONS IN MODEL mymodel VERSION myversion shows each method's signature. Because this scoring is plain SQL, it fits into Dynamic Tables, dbt models and Tasks wherever you need to persist predictions.
Production code should name the default version or an alias, never a specific version. Promotion then becomes a registry change with no code change: after ALTER MODEL my_model SET DEFAULT_VERSION = new_version, every my_model!predict call scores with the new version. The mechanics are covered under Default version and aliases (promotion and rollback).
| Consideration | Virtual warehouse | Snowpark Container Services |
|---|---|---|
| Best for | In-database batch inference with CPU-runnable models such as scikit-learn or XGBoost | LLMs, deep learning models needing high memory, models needing GPUs |
| Model size | Avoid above 15GB (the limit is lower on smaller warehouses) | Large models |
| Packages | Snowflake channel; pip only through an artifact repository | Specific pip packages or a custom OS-level environment |
| Python call | mv.run(input_features, function_name="predict") | mv.run(..., service_name="example_spcs_service") |
| SQL call | MODEL(my_model)!predict(...) | my_service!predict(...) |
| Avoid when | The model requires a GPU | SPCS is not enabled in the account, or you are in a government region |
To check whether a version you already have can run on a warehouse, run SHOW VERSIONS IN MODEL. If the runnable_in column contains WAREHOUSE, the version can be scored there.
Checkpoint 3 of 7· Fill the gap
Production queries call my_model!predict(...) without naming a version. A new version, new_version, has passed evaluation. Which keyword completes the statement so every existing call scores with new_version, with no change to the query code?
ALTER MODEL my_model SET ? = new_version;A call with no version, such as my_model!predict or MODEL(my_model)!predict, uses the model's default version. Setting DEFAULT_VERSION to new_version switches those calls over with no code change. An alias is a label on a version, and only calls that name it, as in MODEL(my_model, production), use it.
Source: docs.snowflake.com4.Granting production roles access to a model
A model object has three privileges, and they map onto the two compute engines. OWNERSHIP gives full control, including managing versions and metadata. USAGE allows warehouse inference and SHOW MODELS, but not the code, weights or other artifacts, so a scoring role can call the model without being able to copy it. READ allows SPCS inference and also exposes model files, comments, tags and metrics. Giving a role USAGE and then pointing it at an SPCS service does not work.
GRANT USAGE ON MODEL my_model TO ROLE prod_role;
-- OR
GRANT READ ON MODEL my_model TO ROLE prod_role;Grants can cover a whole schema. GRANT USAGE ON ALL MODELS IN SCHEMA <schema> TO ROLE <role> covers the models that exist now, and GRANT USAGE ON FUTURE MODELS IN SCHEMA covers models logged later. The same syntax works with READ. The role also needs USAGE on the schema that contains the model. Services have one more layer: by default only the service owner can call service functions, so another role that calls service_name!method_name(...) needs the INFERENCE_SERVICE_FUNCTION_USAGE service role, granted with GRANT SERVICE ROLE.
Checkpoint 4 of 7· Check yourself
Your security team approves a reporting role to score rows on a virtual warehouse with MODEL(churn_model)!predict(...). The role must not be able to see or copy the model's code, weights or other artifacts. Which grant on the model meets both requirements?
USAGE allows warehouse inference but does not expose the code, weights or artifacts, so it is the least-privilege fit here. READ also exposes model files and metadata. OWNERSHIP gives full control. CREATE MODEL lets a role create models in the schema and does not grant use of existing ones.
“Roles with only USAGE cannot access the model code, weights, or other artifacts.”Source: docs.snowflake.com
5.Serving a version from Snowpark Container Services
create_service deploys a model version as a managed service. Snowflake builds the inference image, runs it on a compute pool, and can expose an HTTP endpoint, so you never manage Docker images or Kubernetes. You call it on a ModelVersion, either one you just logged or one you retrieve from the registry.
# reg is a snowflake.ml.registry.Registry object
example_mv_object = reg.get_model("mymodel_name").version("version_name") # a snowflake.ml.model.ModelVersion object
example_mv_object.create_service(service_name="myservice",
service_compute_pool="my_compute_pool",
ingress_enabled=True,
gpu_requests=None)The arguments correspond to the infrastructure. service_name must be unique in the account. service_compute_pool chooses CPU or GPU nodes. ingress_enabled=True creates the public endpoint, which requires the BIND SERVICE ENDPOINT privilege on the account. gpu_requests and max_instances set GPU use and scale-out. The role also needs USAGE or OWNERSHIP on the compute pool. The GPU example for a Hugging Face sentence transformer needs both a GPU compute pool and an image repository, and passes image_repo in some calls.
There are three operational limits to know. A model trained with Snowpark ML modeling classes cannot be deployed to a GPU environment, so you extract the native model, for example with regressor.to_xgboost(), and log that instead. Models with table functions cannot be served online. When warehouse SQL routes requests to a service, use an XSMALL or SMALL warehouse, because a larger one sends enough parallel requests to overwhelm the service. A suspended service resumes on the next request, but the query can fail if the compute pool has no free nodes.
Checkpoint 5 of 7· Fill the gap
To let an external web app reach the model, the service must expose a public HTTP endpoint. The role creating it holds BIND SERVICE ENDPOINT on the account. Which argument completes the call so the service gets that endpoint?
# reg is a snowflake.ml.registry.Registry object
example_mv_object = reg.get_model("mymodel_name").version("version_name") # a snowflake.ml.model.ModelVersion object
example_mv_object.create_service(service_name="myservice",
service_compute_pool="my_compute_pool",
? =True,
gpu_requests=None)ingress_enabled=True tells create_service to create the public endpoint. BIND SERVICE ENDPOINT is the account privilege that the role needs for this, not an argument of create_service. service_compute_pool and gpu_requests set the hardware, not network exposure.
Source: docs.snowflake.com6.Batch scoring with vectorized UDFs, and staging files
A Python UDF is the other in-warehouse route: you write the scoring function yourself instead of relying on the registry's generated methods. The basics are in Python UDFs (scalar and vectorized). For inference, the vectorized form is the one to use. A scalar UDF processes one row at a time. A vectorized UDF receives a pandas DataFrame per batch, so a model's predict, which already expects a DataFrame, runs once per batch instead of once per row. Your SQL stays the same, because the UDF framework does the batching.
CREATE FUNCTION add_one_to_inputs(x NUMBER(10, 0), y NUMBER(10, 0))
RETURNS NUMBER(10, 0)
LANGUAGE PYTHON
RUNTIME_VERSION = 3.12
PACKAGES = ('pandas')
HANDLER = 'add_one_to_inputs'
AS $$
import pandas
from _snowflake import vectorized
@vectorized(input=pandas.DataFrame, max_batch_size=100)
def add_one_to_inputs(df):
return df[0] + df[1] + 1
$$;The handler has a contract. Arguments arrive as columns by position (df[0], df[1]), and the Series it returns must have exactly as many rows as the input. Each call must finish within 180 seconds. A batch can hold up to a few thousand rows, so for a slow model, set max_batch_size to cap the rows per batch. It is a ceiling, not a way to ask for bigger batches. Snowflake does not guarantee which handler instance receives which batch, so each call must be able to score its batch on its own.
Model files and handler code reach Snowflake through internal stages. PUT uploads local files to an internal stage: a named stage (@my_stage), a table stage (@%mytable) or your user stage (@~). It cannot upload to an external stage. Two defaults affect model files. AUTO_COMPRESS = TRUE gzips each file. OVERWRITE = FALSE means a second PUT of a retrained model.pkl does not replace the staged copy unless you set it to TRUE. On Google Cloud, PUT always overwrites. LIST @my_stage shows what is staged. GET is the companion command in the same family.
Checkpoint 6 of 7· Fill the gap
A slow scoring handler only finishes inside the 180-second limit if it gets no more than 100 rows per call. Which decorator argument caps the rows in each input DataFrame?
CREATE FUNCTION add_one_to_inputs(x NUMBER(10, 0), y NUMBER(10, 0))
RETURNS NUMBER(10, 0)
LANGUAGE PYTHON
RUNTIME_VERSION = 3.12
PACKAGES = ('pandas')
HANDLER = 'add_one_to_inputs'
AS $$
import pandas
from _snowflake import vectorized
@vectorized(input=pandas.DataFrame, ? =100)
def add_one_to_inputs(df):
return df[0] + df[1] + 1
$$;max_batch_size sets the most rows Snowflake will put in each DataFrame it passes to the handler. That keeps a slow model's calls under the 180-second limit. It only lowers the ceiling: setting a larger value does not make Snowflake send bigger batches.
Source: docs.snowflake.com7.Pre-built ML Functions and stored predictions
Some use cases need no model code. Snowflake ML Functions provide a ready-made model type for each task. FORECAST predicts future values of a time series, ANOMALY_DETECTION flags values that differ from expectations, and CLASSIFICATION sorts rows into classes. You train with a SQL statement such as CREATE SNOWFLAKE.ML.FORECAST model1(INPUT_DATA => TABLE(v1), TIMESTAMP_COLNAME => 'date', TARGET_COLNAME => 'sales') and predict with CALL model1!FORECAST(FORECASTING_PERIODS => 3).
These models are separate from the registry. A FORECAST model is an instance object that you create, show and drop with its own commands. It does not appear in the Model Registry, so registry versioning, aliases and model privileges do not apply to it. From Snowpark you call it with session.sql, because session.call does not yet work with ML Function models.
Saving predictions makes them available downstream: dashboards, alerts and later checks of forecast against actual read a table, not a CALL result. To save a forecast, drop CALL, wrap the method in TABLE(...) and select from it inside CREATE TABLE … AS SELECT:
CREATE TABLE my_forecasts AS
SELECT * FROM TABLE(model1!FORECAST(FORECASTING_PERIODS => 3));The stored rows carry SERIES, TS, FORECAST, LOWER_BOUND and UPPER_BOUND. If a model was trained with SERIES_COLNAME, pass SERIES_VALUE to forecast a single series. That is cheaper than forecasting every series and filtering afterwards, because only the one forecast is generated.
Checkpoint 7 of 7· Check yourself
After training sales_fc with CREATE SNOWFLAKE.ML.FORECAST, a team wants to manage it like their other production models: promote new versions with a default version or a production alias, and control access with model privileges. What happens?
ML Function models such as FORECAST are their own instance objects, which you create, show and drop with their own commands. They never appear in the Model Registry, so default versions, aliases and model privileges cannot be used to manage them.
“Models trained using Snowflake ML Functions (for example, FORECAST) do not appear in the model registry.”Source: docs.snowflake.com
Sources
(12)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“The model registry stores machine learning models as first-class schema-level objects in Snowflake.”
↩︎ The registry as the way into production“or serve the model in Snowpark Container Services for GPU-based inference.”
↩︎ The registry as the way into production“Either this argument or signatures must be provided for all models except Snowpark ML and MLFlow models and Hugging Face pipelines.”
↩︎ Logging a version so it can be served“and the model is not runnable in the warehouse (due to dependencies, gpu requirement, model size etc), log_model() fails.”
↩︎ Logging a version so it can be served“If you do not specify a channel, the Snowflake channel is assumed when the model runs on a warehouse.”
↩︎ Logging a version so it can be served“List of paths to directories of code to import when loading or deploying the model.”
↩︎ Logging a version so it can be served“GRANT USAGE ON FUTURE MODELS IN SCHEMA <schema> TO ROLE <role>;”
↩︎ Granting production roles access to a model“Serves models and runs distributed inference at scale using Python, SQL, or REST API endpoints.”
↩︎ Key concept“The READ privilege allows grantees to use the model for SPCS inference and also see its metadata, such as its comments, tags, and metrics.”
↩︎ Exam trap 1“Models that target a warehouse require an artifact repository for pip packages.”
↩︎ Exam trap 2“Models trained using Snowflake ML Functions (for example, FORECAST) do not appear in the model registry.”
↩︎ Exam trap 3“snowflake.ml.registry.Registry: Manages models within a schema. snowflake.ml.model.Model: Represents a model. snowflake.ml.model.ModelVersion: Represents a version of a model.”
↩︎ Checkpoint“You may specify conda_dependencies lists; the specified packages will be deployed with the model.”
↩︎ Checkpoint“Models trained using Snowflake ML Functions (for example, FORECAST) do not appear in the model registry.”
↩︎ Checkpoint - 2.https://docs.snowflake.com/en/developer-guide/snowflake-ml/inference/inference-overviewOfficial docs
“The Snowflake Model Registry provides a unified interface to both engines.”
↩︎ The registry as the way into production“batch workloads can integrate with Dynamic Tables, Snowpark, dbt, and User Tasks.”
↩︎ Running inference from a registry version - 3.https://docs.snowflake.com/en/developer-guide/snowflake-ml/inference/native-batch-inference-sqlOfficial docs
“To run inference on SPCS instead of a warehouse, add the service_name argument to the run call:”
↩︎ Running inference from a registry version“grant the service role INFERENCE_SERVICE_FUNCTION_USAGE using GRANT SERVICE ROLE.”
↩︎ Granting production roles access to a model“the recommendation is to utilize an XSMALL or SMALL warehouse when the model is deployed to SPCS.”
↩︎ Serving a version from Snowpark Container Services“Model owners or users with the READ privilege on the model can deploy the model to a service.”
↩︎ Prediction - 4.https://docs.snowflake.com/en/developer-guide/snowflake-ml/model-registry/model-managementOfficial docs
“production code only ever calls the default version of the model.”
↩︎ Running inference from a registry version“Roles with only USAGE cannot access the model code, weights, or other artifacts.”
↩︎ Granting production roles access to a model“GRANT USAGE ON SCHEMA model_database.model_schema TO ROLE prod_role;”
↩︎ Granting production roles access to a model - 5.https://docs.snowflake.com/en/developer-guide/snowflake-ml/inference/real-time-inference-rest-apiOfficial docs
“BIND SERVICE ENDPOINT privilege on account to be able to create a public endpoint.”
↩︎ Serving a version from Snowpark Container Services“This name must be unique within your Snowflake account.”
↩︎ Serving a version from Snowpark Container Services - 6.https://docs.snowflake.com/en/developer-guide/snowflake-ml/inference/real-time-inference-examplesOfficial docs
“This example requires the sentence-transformers package, a GPU compute pool and an image repository.”
↩︎ Serving a version from Snowpark Container Services“Models developed using Snowpark ML modeling classes cannot be deployed to environments that have a GPU.”
↩︎ Exam trap 4 - 7.
“receive batches of input rows as Pandas DataFrames and return batches of results as Pandas arrays or Series”
↩︎ Batch scoring with vectorized UDFs, and staging files“Calls to the Python handler function must execute within a time limit, which is 180 seconds”
↩︎ Batch scoring with vectorized UDFs, and staging files“there is no guarantee of which instances of your handler code will see which batches of input.”
↩︎ Batch scoring with vectorized UDFs, and staging files - 8.https://docs.snowflake.com/en/sql-reference/sql/putOfficial docs
“Uploads one or more data files from a local file system onto an internal stage.”
↩︎ Batch scoring with vectorized UDFs, and staging files“PUT does not support uploading files onto an external stage.”
↩︎ Batch scoring with vectorized UDFs, and staging files - 9.
“To see files that have been uploaded to a Snowflake stage, use the LIST command:”
↩︎ Batch scoring with vectorized UDFs, and staging files - 10.
“Anomaly Detection flags metric values that differ from typical expectations.”
↩︎ Pre-built ML Functions and stored predictions“session.call is not yet compatible with models created by ML functions.”
↩︎ Pre-built ML Functions and stored predictions - 11.
“when calling the method, omit the CALL command. Instead, put the call in parentheses, preceded by the TABLE keyword.”
↩︎ Pre-built ML Functions and stored predictions
Also cited
“PUT compresses files with gzip by default”
↩︎ Prediction