snowflake.ml.model.batch_inference.BatchInferenceTask

class snowflake.ml.model.batch_inference.BatchInferenceTask(name: str, *, model_version: ModelVersion, compute_pool: str, output_spec: OutputSpec, query: str | None = None, input_stage_location: str | None = None, input_spec: InputSpec | None = None, resources_spec: ResourcesSpec | None = None, inference_spec: InferenceSpec | None = None, image_build_spec: ImageBuildSpec | None = None, function_name: str | None = None, replicas: int | None = None, **dagtask_kwargs: Any)

Bases: DAGTask

A DAGTask that runs a batch inference job for a registered model version.

Construct it inside a with DAG(...) block (or pass dag= explicitly) and chain it with other tasks using >>. Requires the snowflake.core package to be installed.

The job runs synchronously, so the DAG step completes when the job does. Each run gets a server-generated job name, and results are written under <output_spec.stage_location>/<job_name>/. The job publishes that location as the task return value, so a successor can read it with SYSTEM$GET_PREDECESSOR_RETURN_VALUE() rather than hardcoding the path.

The DAG must supply a warehouse, via DAG(warehouse=...) or warehouse= on the task; serverless DAGs are unsupported.

Prefer fully qualified stage paths: an unqualified path is resolved against the session namespace when the task is built, but against the task owner’s namespace when it runs.

Build a batch inference task.

Parameters:
  • name – Task name within the DAG.

  • model_version – The model version to run.

  • compute_pool – Compute pool used by the job and the image build.

  • output_spec – Output block. stage_location is treated as a base; results are written under <stage_location>/<job_name>/.

  • query – SQL query producing the input rows. Provide exactly one of query or input_stage_location.

  • input_stage_location – Existing stage path holding the input data. Provide exactly one of query or input_stage_location.

  • input_spec – Optional input block.

  • resources_spec – Optional resources block.

  • inference_spec – Optional inference block.

  • image_build_spec – Optional image build block.

  • function_name – Model function name. Resolved against the model’s function list when omitted.

  • replicas – Optional REPLICAS value.

  • dagtask_kwargs – Passed through to DAGTask (dag, condition, warehouse, session_parameters, and so on).

Raises:
  • ImportError – If the snowflake.core package is not installed.

  • TypeError – If definition is passed; the task builds its own.

Attributes

dag

Return the DAG of this task.

full_name

The full name of the child task.

predecessors

Return the predecessors of the Task.

name

Name of the Task.

definition

refer to snowflake.core.task.Task.definition.

condition

refer to snowflake.core.task.Task.condition.

session_parameters

refer to snowflake.core.task.Task.session_parameter.

comment

comment for the task.

target_completion_interval

refer to snowflake.core.task.Task.target_completion_interval.

serverless_task_min_statement_size

refer to snowflake.core.task.Task.serverless_task_min_statement_size.

serverless_task_max_statement_size

refer to snowflake.core.task.Task.serverless_task_max_statement_size.

user_task_timeout_ms

refer to snowflake.core.task.user_task_timeout_ms