Snowflake Gen AI Functions · Topic 25 of 26
Running Third-Party Models with Snowpark Container Services
Host a third-party model in Snowpark Container Services: set up the environment, Docker image, specification file, compute pool and image repository.
- 4 min
- Order: image repository, push image, compute pool, spec file, service.
- Compute pool needs
MIN_NODES,MAX_NODESandINSTANCE_FAMILY;AUTO_SUSPEND_SECSdefault is 3600. - Image path in the spec:
/database/schema/repository/image:tag.
What it is
Snowflake hosts many models for Cortex, but sometimes you need a model it does not host, such as an open model from Hugging Face or your own container. Snowpark Container Services (SPCS) runs containerized workloads inside Snowflake, with optional GPUs, and keeps the data in your account.
Four objects work together. You build an image, store it in an image repository, run it on a compute pool, as a service described by a specification file.
How it works
Environment setup
Before anything is created, an administrator prepares roles and the account.
| Need | Detail |
|---|---|
| Image repository | CREATE IMAGE REPOSITORY privilege on the schema |
| Compute pool | CREATE COMPUTE POOL privilege on the account |
| Service | A role that can create services in the schema and use the pool |
| Pull and push images | READ to list and download, WRITE to push, on the repository |
| Network | An external access integration if the container must reach the internet, for example to download model weights |
Also decide the machine type. Large models need GPU instance families, and the image must be built for the platform the pool runs (the SPCS tutorials build for linux/amd64).
Docker images
Your container image holds the model server and its dependencies. The workflow:
- Build the image with Docker for the right platform.
- Log in to the Snowflake registry. The Snowflake CLI command is
snow spcs image-registry login. - Tag the image with the repository URL and push it.
The registry hostname is <orgname>-<acctname>.registry.snowflakecomputing.com, in lowercase, with underscores in the account name replaced by dashes. The repository URL is the hostname plus /<database>/<schema>/<repository>. SHOW IMAGE REPOSITORIES shows it, and SHOW IMAGES IN IMAGE REPOSITORY lists what you pushed.
The most common trap is the platform. An image built on an Apple silicon laptop for the wrong architecture will not run on an amd64 pool.
Limits: individual images cannot be dropped, since dropping the repository removes all images in it.
Image repository
CREATE IMAGE REPOSITORY IF NOT EXISTS ml_db.public.model_repo;
SHOW IMAGE REPOSITORIES IN SCHEMA ml_db.public;
The privileges are READ (list and download), WRITE (also push) and OWNERSHIP. A service pulls the image when it starts, so the role that creates the service must be able to read the repository.
Compute pool
CREATE COMPUTE POOL llm_pool
MIN_NODES = 1
MAX_NODES = 2
INSTANCE_FAMILY = GPU_NV_S;
| Parameter | Detail |
|---|---|
MIN_NODES | Required; must be above 0 |
MAX_NODES | Required |
INSTANCE_FAMILY | Required; the machine type that sets compute and credit use. GPU families run models |
AUTO_RESUME | Default TRUE |
AUTO_SUSPEND_SECS | Default 3600; 0 disables automatic suspension |
The instance family name above is only an example. Run SHOW COMPUTE POOL INSTANCE FAMILIES to see the families available in your region. A compute pool bills while its nodes run, so suspend it when idle.
Specification file
The service specification is YAML under a top level spec.
spec:
containers:
- name: model-server
image: /ml_db/public/model_repo/llm:1.0
resources:
requests: {nvidia.com/gpu: 1}
limits: {nvidia.com/gpu: 1}
endpoints:
- name: api
port: 8000
public: false
containersis required:nameandimagefor each container.commandoverrides the Dockerfile ENTRYPOINT andargsoverrides CMD.envsets variables.- The image path is
/database/schema/repository/image:tag. resourceshasrequestsandlimitsforcpu,memoryandnvidia.com/gpu. A GPU request needs a matching limit.endpointsexpose a port.publicdefaults to false, which keeps the service private.- Optional sections:
volumes,secretsand probes for readiness and liveness.
The service is then created with CREATE SERVICE ... IN COMPUTE POOL, pointing at the spec. Access to the endpoint is granted through service roles and USAGE.
Using the hosted model with Cortex
A text generation or vision language model served from SPCS can be called with AI_COMPLETE by passing the service name as the model, in the form <db>.<schema>.<service>. The docs mark this bring your own model feature as open preview. The guardrails option is not supported there. Text embedding models hosted this way can also be used with AI_EMBED (text only, also preview).
Common mistakes
Building for the wrong CPU architecture.
Forgetting MAX_NODES or INSTANCE_FAMILY. Compute pool needs both, and MIN_NODES above 0.
Requesting a GPU without a matching limit in the spec.
Leaving the pool running. It bills for as long as nodes are active.
Do not describe SPCS bring your own model as general availability. For AI_COMPLETE and AI_EMBED it is open preview.
What to remember for the exam
- Order: image repository, push image, compute pool, spec file, service.
- Compute pool needs
MIN_NODES,MAX_NODESandINSTANCE_FAMILY;AUTO_SUSPEND_SECSdefault is 3600. - Image path in the spec:
/database/schema/repository/image:tag. READpulls,WRITEpushes;CREATE IMAGE REPOSITORYandCREATE COMPUTE POOLare separate privileges.- A hosted model is called with
AI_COMPLETEby service name (open preview).
Check yourself
Which three parameters are required in
CREATE COMPUTE POOL?MIN_NODES,MAX_NODESandINSTANCE_FAMILY.What goes in a service specification file?
A
specwith containers (name, image, resources), endpoints, and optional volumes and secrets.How do you call a model served by SPCS from
AI_COMPLETE?Pass the service name as the model, in the form database.schema.service.
Topic 25 of 26 in Snowflake Gen AI Functions
Test yourself on Snowflake Gen AI Functions
The full Snowflake GES-C02 question bank has 585 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Snowflake. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.