snowflake.ml.model.HuggingFacePipelineModel

class snowflake.ml.model.HuggingFacePipelineModel(task: Optional[str] = None, model: Optional[str] = None, *, revision: Optional[str] = None, token: Optional[str] = None, trust_remote_code: Optional[bool] = None, model_kwargs: Optional[dict[str, Any]] = None, **kwargs: Any)

Bases: object

Utility factory method to build a wrapper over transformers [Pipeline]. When deploying, this wrapper will create a real pipeline object and loading tokenizers and models.

For pipelines docs, please refer: https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.pipeline

Parameters:
  • task – The task that pipeline will be used. If None it would be inferred from model. For available tasks, please refer Transformers’s documentation. Defaults to None.

  • model – The model that will be used by the pipeline to make predictions. This can only be a model identifier currently. If not provided, the default for the task will be loaded. Defaults to None.

  • revision – When passing a task name or a string model identifier: The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so revision can be any identifier allowed by git. Defaults to None.

  • token – The token to use as HTTP bearer authorization for remote files. Defaults to None.

  • trust_remote_code – Whether or not to allow for custom code defined on the Hub in their own modeling, configuration, tokenization or even pipeline files. This option should only be set to True for repositories you trust and in which you have read the code, as it will execute code present on the Hub. Defaults to None.

  • model_kwargs – Additional dictionary of keyword arguments passed along to the model’s from_pretrained(…,. Defaults to None.

  • kwargs – Additional keyword arguments passed along to the specific pipeline init (see the documentation for the corresponding pipeline class for possible values).

Returns:

A wrapper over transformers [Pipeline].

Raises:
  • RuntimeError – Raised when the input argument cannot determine the pipeline.

  • ValueError – Raised when the pipeline contains remote code but trust_remote_code is not set or False.

  • ValueError – Raised when having conflicting arguments.

Methods

create_service(*, session: Session, model_name: str, version_name: Optional[str] = None, pip_requirements: Optional[list[str]] = None, conda_dependencies: Optional[list[str]] = None, comment: Optional[str] = None, service_name: str, service_compute_pool: str, image_repo: str, image_build_compute_pool: Optional[str] = None, ingress_enabled: bool = False, max_instances: int = 1, cpu_requests: Optional[str] = None, memory_requests: Optional[str] = None, gpu_requests: Optional[Union[str, int]] = None, num_workers: Optional[int] = None, max_batch_rows: Optional[int] = None, force_rebuild: bool = False, build_external_access_integrations: Optional[list[str]] = None, block: bool = True) Union[str, AsyncJob]

Logs a Hugging Face model and creates a service in Snowflake.

Parameters:
  • session – The Snowflake session object.

  • model_name – The name of the model in Snowflake.

  • version_name – The version name of the model. Defaults to None.

  • pip_requirements – Pip requirements for the model. Defaults to None.

  • conda_dependencies – Conda dependencies for the model. Defaults to None.

  • comment – Comment for the model. Defaults to None.

  • service_name – The name of the service to create.

  • service_compute_pool – The compute pool for the service.

  • image_repo – The name of the image repository.

  • image_build_compute_pool – The name of the compute pool used to build the model inference image. It uses

  • None. (the service compute pool if) –

  • ingress_enabled – Whether ingress is enabled. Defaults to False.

  • max_instances – Maximum number of instances. Defaults to 1.

  • cpu_requests – CPU requests configuration. Defaults to None.

  • memory_requests – Memory requests configuration. Defaults to None.

  • gpu_requests – GPU requests configuration. Defaults to None.

  • num_workers – Number of workers. Defaults to None.

  • max_batch_rows – Maximum batch rows. Defaults to None.

  • force_rebuild – Whether to force rebuild the image. Defaults to False.

  • build_external_access_integrations – External access integrations for building the image. Defaults to None.

  • block – Whether to block the operation. Defaults to True.

Raises:
  • ValueError – if database and schema name is not provided and session doesn’t have a

  • database and schema name.

Returns:

The service ID or an async job object.

This function or method is in private preview since 1.9.1.