EXECUTE INFERENCE JOB SERVICE

statementnot supportedAI & ML

docs.snowflake.com ↗

Note This operation is not currently covered by the Service Level set forth in Snowflake’s Support Policy and Service Level Agreement. Runs batch inference on a model in the Snowflake Model Registry as a Snowpark Container Services (SPCS) job. This command is the SQL equivalent of the run_batch method in the snowflake-ml-python API. For more information, see Batch inference jobs. You provide a compute pool, a batch inference job specification, an input data source (a query or a stage), and the model to run. Snowflake runs inference over the input and writes the results to the output stage that you specify in the specification. When all containers exit, the job is done. By default, the job runs asynchronously; the command returns while the job runs in the background. (If the model’s container image must be built first, the command waits for the image build to finish before returning.) You can use the DESCRIBE SERVICE command to poll for job completion and then call the SYSTEM$WAIT_FOR_SERVICES function to wait for the job to complete. To run the job synchronously, so that the command finishes only after all containers exit, specify ASYNC = FALSE. After a job service completes, Snowflake automatically cleans up the resources allocated to the job service to help reduce costs. You can still access job metadata for up to 30 days by using the DESCRIBE SERVICE and SHOW SERVICES commands. After 30 days, Snowflake automatically deletes the job. Note that the command parameters must be specified in a specific order. For more information, see Usage notes. Snowpark Container Services is available to accounts in AWS, Microsoft Azure, and Google Cloud Platform commercial regions, with some exceptions. For more information, see Available regions and considerations.

Syntax

EXECUTE INFERENCE JOB SERVICE
  IN COMPUTE POOL <compute_pool_name>
  WITH SPECIFICATION <specification_text>
  FROM { ( <subquery> ) | @[<namespace>.]<stage_name>[/<path>] }
  MODEL = [<db>.<schema>.]<model_name>
  [ VERSION = <version_or_alias> ]
  [ FUNCTION = '<function_name>' ]
  [ NAME = [<db>.<schema>.]<name> ]
  [ ASYNC = { TRUE | FALSE } ]
  [ REPLICAS = <num> ]

Parameters

NameRequiredDescription
IN COMPUTE POOL compute_pool_namerequiredSpecifies the name of the compute pool in your account on which to run the inference job.
WITH SPECIFICATION specification_textrequiredSpecifies the batch inference job specification, as inline YAML. You can use a pair of dollar signs ($$) to delimit the beginning and ending of the specification string. For the fields you can set, see Specification.
FROM { ( subquery ) | @[namespace.]stage_name[/path] }requiredSpecifies the input data for inference, as one of the following: A subquery that produces the input rows; for example, ( SELECT id, feature_1 FROM my_table ). A stage path that references the input files; for example, @my_db.my_schema.my_stage/data/. Use a stage path for file-based input.
MODEL = [db.schema.]model_namerequiredSpecifies the model in the Snowflake Model Registry to run inference with. If you omit the database and schema, Snowflake uses the current database and schema for the session.
VERSION = version_or_aliasoptionalSpecifies the model version (or a version alias) to use. Default: The model’s default version.
FUNCTION = 'function_name'optionalSpecifies the name of the model function (method) to invoke, for example 'predict'. To list the functions available for a model version, run SHOW FUNCTIONS IN MODEL <model_name> VERSION <version>. Default: For a model that exposes a single function, that function.
NAME = [db.schema.]nameoptionalThe name (that is, the identifier) for the service that executes like a job; it must be unique for the schema in which the service is created. Quoted names for special characters or case-sensitive names are not supported. The same constraint also applies to database and schema names where you create a service. That is, database and schema names without quotes are valid when creating a service. Default: If not specified, Snowflake generates a name for the service in the format <db>.<schema>.BATCH_INFERENCE_<UUID>.
ASYNC = { TRUE | FALSE }optionalSpecifies whether to execute the job asynchronously. When TRUE, the command returns while the job runs (after waiting for the image build, if one is needed). When FALSE, the command finishes only after all containers exit. Default: TRUE
REPLICAS = numoptionalSpecifies the number of job replicas to run. For more information, see Run multiple replicas of a job service (batch jobs). Default: 1.

Usage notes

Specification

The specification is a YAML document that configures how the batch inference job runs and where it writes results. It supports the following top-level sections. Only output is required. output: Required. Configures where the job writes results. stage_location (required): The base stage location for results. Snowflake writes each job’s output to a per-job subdirectory of this location, <stage_location>/<job_name>/, where <job_name> is the job’s unqualified name (from the NAME parameter, or auto-generated in the format BATCH_INFERENCE_<UUID> if you don’t specify one). mode: What happens when the output location already contains files. error (the default) fails the job; overwrite removes the existing files first. resources: Configures the compute resources requested for the job containers. cpu_requests: The CPU limit for CPU-based inference, as an integer, fractional, or string value. If omitted, the job uses all of the node’s vCPUs. memory_requests: The memory limit, as an integer or fractional value with a unit (for example, 8GiB or 512MiB). If omitted, the job uses all of the node’s memory. gpu_requests: The GPU count for GPU-based inference, as an integer or string value. If omitted, the job runs on CPU. inference: Tunes inference execution. num_workers: The number of workers per service instance that process requests in parallel. Defaults to 2 * vCPU + 1 for CPU-based inference and 1 for GPU-based inference. max_batch_rows: The maximum number of rows to process in a single batch. Auto-determined if omitted; larger values can improve throughput. engine_options: Inference engine settings: engine: The inference engine, one of DEFAULT, VLLM, or PYTHON_GENERIC. engine_args_override: A list of engine arguments to override (for example, --max-model-len=18048 for vLLM). adapters: Optional list of LoRA adapters to attach for the job. Each item has the keys name, version, and optional alias. Set input.params.model to the alias of the adapter to use for the whole job. Requires the VLLM engine. See LoRA adapters. input: Configures how the input rows are processed. params: A dictionary of model inference parameters (for example, temperature or top_k for LLMs). These are passed as keyword arguments to the model function. column_handling: Maps an input column to file-handling options, so the model receives the file’s contents instead of the stage path string. For each column name, provide: input_format: How to interpret the column value. Supported value: full_stage_path (the value is a full stage path to a file). convert_to: The encoding in which the file contents are passed to the model, one of raw_bytes, base64, or base64_data_url. partition_column: The name of a column to partition the input by. Each partition is processed independently, which is useful for partitioned models. image_build: Configures the container image build for the job. image_repo: The image repository to use for the job’s container image. If omitted, the job uses the default repository. force_rebuild: Whether to rebuild the container image even if a cached image exists. Default: false. For example:

Access control requirements

A role used to execute this operation must have the following privileges at a minimum: Privilege | Object | Notes CREATE SERVICE | Schema | Schema in which the job service is created. USAGE | Compute pool | USAGE | Model | Model referenced by the MODEL clause. READ | Model | Each LoRA adapter attached in inference.adapters. READ | Stage | Input stage and the stage where the specification is stored. WRITE | Stage | Output stage where results are written (the specification’s output.stage_location). READ | Image Repository | Repository of images referenced by the specification. Operating on an object in a schema requires at least one privilege on the parent database and at least one privilege on the parent schema. For instructions on creating a custom role with a specified set of privileges, see Creating custom roles. For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

See also