snowflake-ml-python 1.22.0__py3-none-any.whl → 1.23.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/ml/jobs/__init__.py +2 -0
- snowflake/ml/jobs/_utils/constants.py +1 -0
- snowflake/ml/jobs/_utils/payload_utils.py +38 -18
- snowflake/ml/jobs/_utils/query_helper.py +8 -1
- snowflake/ml/jobs/_utils/runtime_env_utils.py +117 -0
- snowflake/ml/jobs/_utils/stage_utils.py +2 -2
- snowflake/ml/jobs/_utils/types.py +22 -2
- snowflake/ml/jobs/job_definition.py +232 -0
- snowflake/ml/jobs/manager.py +16 -177
- snowflake/ml/model/_client/model/model_version_impl.py +90 -76
- snowflake/ml/model/_client/ops/model_ops.py +2 -18
- snowflake/ml/model/_client/ops/param_utils.py +124 -0
- snowflake/ml/model/_client/ops/service_ops.py +63 -18
- snowflake/ml/model/_client/service/model_deployment_spec.py +12 -5
- snowflake/ml/model/_client/service/model_deployment_spec_schema.py +1 -0
- snowflake/ml/model/_client/sql/service.py +4 -25
- snowflake/ml/model/_model_composer/model_method/infer_function.py_template +21 -3
- snowflake/ml/model/_model_composer/model_method/infer_partitioned.py_template +21 -3
- snowflake/ml/model/_model_composer/model_method/infer_table_function.py_template +21 -3
- snowflake/ml/model/_model_composer/model_method/model_method.py +2 -1
- snowflake/ml/model/_packager/model_handlers/huggingface.py +54 -10
- snowflake/ml/model/_packager/model_handlers/sentence_transformers.py +52 -16
- snowflake/ml/model/_signatures/utils.py +55 -0
- snowflake/ml/model/openai_signatures.py +97 -0
- snowflake/ml/registry/_manager/model_parameter_reconciler.py +1 -1
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.22.0.dist-info → snowflake_ml_python-1.23.0.dist-info}/METADATA +67 -1
- {snowflake_ml_python-1.22.0.dist-info → snowflake_ml_python-1.23.0.dist-info}/RECORD +31 -29
- snowflake/ml/experiment/callback/__init__.py +0 -0
- {snowflake_ml_python-1.22.0.dist-info → snowflake_ml_python-1.23.0.dist-info}/WHEEL +0 -0
- {snowflake_ml_python-1.22.0.dist-info → snowflake_ml_python-1.23.0.dist-info}/licenses/LICENSE.txt +0 -0
- {snowflake_ml_python-1.22.0.dist-info → snowflake_ml_python-1.23.0.dist-info}/top_level.txt +0 -0
snowflake/ml/jobs/manager.py
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import logging
|
|
3
|
-
import os
|
|
4
|
-
import pathlib
|
|
5
|
-
import sys
|
|
6
|
-
from pathlib import PurePath
|
|
7
2
|
from typing import Any, Callable, Optional, TypeVar, Union, cast, overload
|
|
8
|
-
from uuid import uuid4
|
|
9
3
|
|
|
10
4
|
import pandas as pd
|
|
11
5
|
|
|
@@ -13,13 +7,8 @@ from snowflake import snowpark
|
|
|
13
7
|
from snowflake.ml._internal import telemetry
|
|
14
8
|
from snowflake.ml._internal.utils import identifier
|
|
15
9
|
from snowflake.ml.jobs import job as jb
|
|
16
|
-
from snowflake.ml.jobs._utils import
|
|
17
|
-
|
|
18
|
-
feature_flags,
|
|
19
|
-
payload_utils,
|
|
20
|
-
query_helper,
|
|
21
|
-
types,
|
|
22
|
-
)
|
|
10
|
+
from snowflake.ml.jobs._utils import query_helper
|
|
11
|
+
from snowflake.ml.jobs.job_definition import MLJobDefinition
|
|
23
12
|
from snowflake.snowpark.context import get_active_session
|
|
24
13
|
from snowflake.snowpark.exceptions import SnowparkSQLException
|
|
25
14
|
from snowflake.snowpark.functions import coalesce, col, lit, when
|
|
@@ -457,7 +446,6 @@ def _submit_job(
|
|
|
457
446
|
An object representing the submitted job.
|
|
458
447
|
|
|
459
448
|
Raises:
|
|
460
|
-
ValueError: If database or schema value(s) are invalid
|
|
461
449
|
RuntimeError: If schema is not specified in session context or job submission
|
|
462
450
|
"""
|
|
463
451
|
session = _ensure_session(session)
|
|
@@ -469,94 +457,30 @@ def _submit_job(
|
|
|
469
457
|
)
|
|
470
458
|
target_instances = max(target_instances, kwargs.pop("num_instances"))
|
|
471
459
|
|
|
472
|
-
imports = None
|
|
473
460
|
if "additional_payloads" in kwargs:
|
|
474
461
|
logger.warning(
|
|
475
462
|
"'additional_payloads' is deprecated and will be removed in a future release. Use 'imports' instead."
|
|
476
463
|
)
|
|
477
|
-
imports
|
|
464
|
+
if "imports" not in kwargs:
|
|
465
|
+
imports = kwargs.pop("additional_payloads", None)
|
|
466
|
+
kwargs.update({"imports": imports})
|
|
478
467
|
|
|
479
468
|
if "runtime_environment" in kwargs:
|
|
480
469
|
logger.warning("'runtime_environment' is in private preview since 1.15.0, do not use it in production.")
|
|
481
470
|
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
imports = kwargs.pop("imports", None) or imports
|
|
493
|
-
# if the mljob is submitted from a notebook, we use the same image tag as the notebook
|
|
494
|
-
runtime_environment = kwargs.pop("runtime_environment", os.environ.get(constants.RUNTIME_IMAGE_TAG_ENV_VAR, None))
|
|
495
|
-
|
|
496
|
-
# Warn if there are unknown kwargs
|
|
497
|
-
if kwargs:
|
|
498
|
-
logger.warning(f"Ignoring unknown kwargs: {kwargs.keys()}")
|
|
499
|
-
|
|
500
|
-
# Validate parameters
|
|
501
|
-
if database and not schema:
|
|
502
|
-
raise ValueError("Schema must be specified if database is specified.")
|
|
503
|
-
if target_instances < 1:
|
|
504
|
-
raise ValueError("target_instances must be greater than 0.")
|
|
505
|
-
if not (0 < min_instances <= target_instances):
|
|
506
|
-
raise ValueError("min_instances must be greater than 0 and less than or equal to target_instances.")
|
|
507
|
-
if min_instances > 1:
|
|
508
|
-
# Validate min_instances against compute pool max_nodes
|
|
509
|
-
pool_info = jb._get_compute_pool_info(session, compute_pool)
|
|
510
|
-
max_nodes = int(pool_info["max_nodes"])
|
|
511
|
-
if min_instances > max_nodes:
|
|
512
|
-
raise ValueError(
|
|
513
|
-
f"The requested min_instances ({min_instances}) exceeds the max_nodes ({max_nodes}) "
|
|
514
|
-
f"of compute pool '{compute_pool}'. Reduce min_instances or increase max_nodes."
|
|
515
|
-
)
|
|
516
|
-
|
|
517
|
-
job_name = f"{JOB_ID_PREFIX}{str(uuid4()).replace('-', '_').upper()}"
|
|
518
|
-
job_id = identifier.get_schema_level_object_identifier(database, schema, job_name)
|
|
519
|
-
stage_path_parts = identifier.parse_snowflake_stage_path(stage_name.lstrip("@"))
|
|
520
|
-
stage_name = f"@{'.'.join(filter(None, stage_path_parts[:3]))}"
|
|
521
|
-
stage_path = pathlib.PurePosixPath(f"{stage_name}{stage_path_parts[-1].rstrip('/')}/{job_name}")
|
|
522
|
-
|
|
523
|
-
try:
|
|
524
|
-
# Upload payload
|
|
525
|
-
uploaded_payload = payload_utils.JobPayload(
|
|
526
|
-
source, entrypoint=entrypoint, pip_requirements=pip_requirements, imports=imports
|
|
527
|
-
).upload(session, stage_path)
|
|
528
|
-
except SnowparkSQLException as e:
|
|
529
|
-
if e.sql_error_code == 90106:
|
|
530
|
-
raise RuntimeError(
|
|
531
|
-
"Please specify a schema, either in the session context or as a parameter in the job submission"
|
|
532
|
-
)
|
|
533
|
-
elif e.sql_error_code == 3001 and "schema" in str(e).lower():
|
|
534
|
-
raise RuntimeError(
|
|
535
|
-
"please grant privileges on schema before submitting a job, see",
|
|
536
|
-
"https://docs.snowflake.com/en/developer-guide/snowflake-ml/ml-jobs/access-control-requirements",
|
|
537
|
-
" for more details",
|
|
538
|
-
) from e
|
|
539
|
-
raise
|
|
540
|
-
|
|
541
|
-
combined_env_vars = {**uploaded_payload.env_vars, **(env_vars or {})}
|
|
471
|
+
job_definition = MLJobDefinition.register(
|
|
472
|
+
source,
|
|
473
|
+
compute_pool,
|
|
474
|
+
stage_name,
|
|
475
|
+
session or get_active_session(),
|
|
476
|
+
entrypoint,
|
|
477
|
+
target_instances,
|
|
478
|
+
generate_suffix=True,
|
|
479
|
+
**kwargs,
|
|
480
|
+
)
|
|
542
481
|
|
|
543
482
|
try:
|
|
544
|
-
return
|
|
545
|
-
session=session,
|
|
546
|
-
payload=uploaded_payload,
|
|
547
|
-
args=args,
|
|
548
|
-
env_vars=combined_env_vars,
|
|
549
|
-
spec_overrides=spec_overrides,
|
|
550
|
-
compute_pool=compute_pool,
|
|
551
|
-
job_id=job_id,
|
|
552
|
-
external_access_integrations=external_access_integrations,
|
|
553
|
-
query_warehouse=query_warehouse,
|
|
554
|
-
target_instances=target_instances,
|
|
555
|
-
min_instances=min_instances,
|
|
556
|
-
enable_metrics=enable_metrics,
|
|
557
|
-
use_async=True,
|
|
558
|
-
runtime_environment=runtime_environment,
|
|
559
|
-
)
|
|
483
|
+
return job_definition(*(args or []))
|
|
560
484
|
except SnowparkSQLException as e:
|
|
561
485
|
if e.sql_error_code == 3001 and "schema" in str(e).lower():
|
|
562
486
|
raise RuntimeError(
|
|
@@ -567,91 +491,6 @@ def _submit_job(
|
|
|
567
491
|
raise
|
|
568
492
|
|
|
569
493
|
|
|
570
|
-
def _do_submit_job(
|
|
571
|
-
session: snowpark.Session,
|
|
572
|
-
payload: types.UploadedPayload,
|
|
573
|
-
args: Optional[list[str]],
|
|
574
|
-
env_vars: dict[str, str],
|
|
575
|
-
spec_overrides: dict[str, Any],
|
|
576
|
-
compute_pool: str,
|
|
577
|
-
job_id: Optional[str] = None,
|
|
578
|
-
external_access_integrations: Optional[list[str]] = None,
|
|
579
|
-
query_warehouse: Optional[str] = None,
|
|
580
|
-
target_instances: int = 1,
|
|
581
|
-
min_instances: int = 1,
|
|
582
|
-
enable_metrics: bool = True,
|
|
583
|
-
use_async: bool = True,
|
|
584
|
-
runtime_environment: Optional[str] = None,
|
|
585
|
-
) -> jb.MLJob[Any]:
|
|
586
|
-
"""
|
|
587
|
-
Generate the SQL query for job submission.
|
|
588
|
-
|
|
589
|
-
Args:
|
|
590
|
-
session: The Snowpark session to use.
|
|
591
|
-
payload: The uploaded job payload.
|
|
592
|
-
args: Arguments to pass to the entrypoint script.
|
|
593
|
-
env_vars: Environment variables to set in the job container.
|
|
594
|
-
spec_overrides: Custom service specification overrides.
|
|
595
|
-
compute_pool: The compute pool to use for job execution.
|
|
596
|
-
job_id: The ID of the job.
|
|
597
|
-
external_access_integrations: Optional list of external access integrations.
|
|
598
|
-
query_warehouse: Optional query warehouse to use.
|
|
599
|
-
target_instances: Number of instances for multi-node job.
|
|
600
|
-
min_instances: Minimum number of instances required to start the job.
|
|
601
|
-
enable_metrics: Whether to enable platform metrics for the job.
|
|
602
|
-
use_async: Whether to run the job asynchronously.
|
|
603
|
-
runtime_environment: image tag or full image URL to use for the job.
|
|
604
|
-
|
|
605
|
-
Returns:
|
|
606
|
-
The job object.
|
|
607
|
-
"""
|
|
608
|
-
args = [(v.as_posix() if isinstance(v, PurePath) else v) for v in payload.entrypoint] + (args or [])
|
|
609
|
-
spec_options = {
|
|
610
|
-
"STAGE_PATH": payload.stage_path.as_posix(),
|
|
611
|
-
"ENTRYPOINT": ["/usr/local/bin/_entrypoint.sh"],
|
|
612
|
-
"ARGS": args,
|
|
613
|
-
"ENV_VARS": env_vars,
|
|
614
|
-
"ENABLE_METRICS": enable_metrics,
|
|
615
|
-
"SPEC_OVERRIDES": spec_overrides,
|
|
616
|
-
}
|
|
617
|
-
if runtime_environment:
|
|
618
|
-
# for the image tag or full image URL, we use that directly
|
|
619
|
-
spec_options["RUNTIME"] = runtime_environment
|
|
620
|
-
elif feature_flags.FeatureFlags.ENABLE_RUNTIME_VERSIONS.is_enabled():
|
|
621
|
-
# when feature flag is enabled, we get the local python version and wrap it in a dict
|
|
622
|
-
# in system function, we can know whether it is python version or image tag or full image URL through the format
|
|
623
|
-
spec_options["RUNTIME"] = json.dumps({"pythonVersion": f"{sys.version_info.major}.{sys.version_info.minor}"})
|
|
624
|
-
|
|
625
|
-
job_options = {
|
|
626
|
-
"EXTERNAL_ACCESS_INTEGRATIONS": external_access_integrations,
|
|
627
|
-
"QUERY_WAREHOUSE": query_warehouse,
|
|
628
|
-
"TARGET_INSTANCES": target_instances,
|
|
629
|
-
"MIN_INSTANCES": min_instances,
|
|
630
|
-
"ASYNC": use_async,
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
if feature_flags.FeatureFlags.ENABLE_STAGE_MOUNT_V2.is_enabled(default=True):
|
|
634
|
-
spec_options["ENABLE_STAGE_MOUNT_V2"] = True
|
|
635
|
-
if payload.payload_name:
|
|
636
|
-
job_options["GENERATE_SUFFIX"] = True
|
|
637
|
-
job_options = {k: v for k, v in job_options.items() if v is not None}
|
|
638
|
-
|
|
639
|
-
query_template = "CALL SYSTEM$EXECUTE_ML_JOB(?, ?, ?, ?)"
|
|
640
|
-
if job_id:
|
|
641
|
-
database, schema, _ = identifier.parse_schema_level_object_identifier(job_id)
|
|
642
|
-
params = [
|
|
643
|
-
job_id
|
|
644
|
-
if payload.payload_name is None
|
|
645
|
-
else identifier.get_schema_level_object_identifier(database, schema, payload.payload_name) + "_",
|
|
646
|
-
compute_pool,
|
|
647
|
-
json.dumps(spec_options),
|
|
648
|
-
json.dumps(job_options),
|
|
649
|
-
]
|
|
650
|
-
actual_job_id = query_helper.run_query(session, query_template, params=params)[0][0]
|
|
651
|
-
|
|
652
|
-
return get_job(actual_job_id, session=session)
|
|
653
|
-
|
|
654
|
-
|
|
655
494
|
def _ensure_session(session: Optional[snowpark.Session]) -> snowpark.Session:
|
|
656
495
|
try:
|
|
657
496
|
session = session or get_active_session()
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import base64
|
|
2
1
|
import enum
|
|
3
|
-
import json
|
|
4
2
|
import pathlib
|
|
5
3
|
import tempfile
|
|
6
4
|
import uuid
|
|
@@ -8,7 +6,6 @@ import warnings
|
|
|
8
6
|
from typing import Any, Callable, Optional, Union, overload
|
|
9
7
|
|
|
10
8
|
import pandas as pd
|
|
11
|
-
from pydantic import TypeAdapter
|
|
12
9
|
|
|
13
10
|
from snowflake import snowpark
|
|
14
11
|
from snowflake.ml._internal import telemetry
|
|
@@ -33,7 +30,10 @@ _TELEMETRY_PROJECT = "MLOps"
|
|
|
33
30
|
_TELEMETRY_SUBPROJECT = "ModelManagement"
|
|
34
31
|
_BATCH_INFERENCE_JOB_ID_PREFIX = "BATCH_INFERENCE_"
|
|
35
32
|
_BATCH_INFERENCE_TEMPORARY_FOLDER = "_temporary"
|
|
36
|
-
|
|
33
|
+
VLLM_SUPPORTED_TASKS = [
|
|
34
|
+
"text-generation",
|
|
35
|
+
"image-text-to-text",
|
|
36
|
+
]
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class ExportMode(enum.Enum):
|
|
@@ -649,41 +649,6 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
649
649
|
method_options, target_function_info["name"]
|
|
650
650
|
)
|
|
651
651
|
|
|
652
|
-
@staticmethod
|
|
653
|
-
def _encode_column_handling(
|
|
654
|
-
column_handling: Optional[dict[str, batch_inference_specs.ColumnHandlingOptions]],
|
|
655
|
-
) -> Optional[str]:
|
|
656
|
-
"""Validate and encode column_handling to a base64 string.
|
|
657
|
-
|
|
658
|
-
Args:
|
|
659
|
-
column_handling: Optional dictionary mapping column names to file encoding options.
|
|
660
|
-
|
|
661
|
-
Returns:
|
|
662
|
-
Base64 encoded JSON string of the column handling options, or None if input is None.
|
|
663
|
-
"""
|
|
664
|
-
# TODO: validation for column names
|
|
665
|
-
if column_handling is None:
|
|
666
|
-
return None
|
|
667
|
-
adapter = TypeAdapter(dict[str, batch_inference_specs.ColumnHandlingOptions])
|
|
668
|
-
# TODO: throw error if the validate_python function fails
|
|
669
|
-
validated_input = adapter.validate_python(column_handling)
|
|
670
|
-
return base64.b64encode(adapter.dump_json(validated_input)).decode(_UTF8_ENCODING)
|
|
671
|
-
|
|
672
|
-
@staticmethod
|
|
673
|
-
def _encode_params(params: Optional[dict[str, Any]]) -> Optional[str]:
|
|
674
|
-
"""Encode params dictionary to a base64 string.
|
|
675
|
-
|
|
676
|
-
Args:
|
|
677
|
-
params: Optional dictionary of model inference parameters.
|
|
678
|
-
|
|
679
|
-
Returns:
|
|
680
|
-
Base64 encoded JSON string of the params, or None if input is None.
|
|
681
|
-
"""
|
|
682
|
-
if params is None:
|
|
683
|
-
return None
|
|
684
|
-
# TODO: validation for param names, types
|
|
685
|
-
return base64.b64encode(json.dumps(params).encode(_UTF8_ENCODING)).decode(_UTF8_ENCODING)
|
|
686
|
-
|
|
687
652
|
@telemetry.send_api_usage_telemetry(
|
|
688
653
|
project=_TELEMETRY_PROJECT,
|
|
689
654
|
subproject=_TELEMETRY_SUBPROJECT,
|
|
@@ -703,6 +668,7 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
703
668
|
job_spec: Optional[batch_inference_specs.JobSpec] = None,
|
|
704
669
|
params: Optional[dict[str, Any]] = None,
|
|
705
670
|
column_handling: Optional[dict[str, batch_inference_specs.ColumnHandlingOptions]] = None,
|
|
671
|
+
inference_engine_options: Optional[dict[str, Any]] = None,
|
|
706
672
|
) -> job.MLJob[Any]:
|
|
707
673
|
"""Execute batch inference on datasets as an SPCS job.
|
|
708
674
|
|
|
@@ -722,6 +688,10 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
722
688
|
column_handling (Optional[dict[str, batch_inference_specs.FileEncoding]]): Optional dictionary
|
|
723
689
|
specifying how to handle specific columns during file I/O. Maps column names to their
|
|
724
690
|
file encoding configuration.
|
|
691
|
+
inference_engine_options: Options for the service creation with custom inference engine.
|
|
692
|
+
Supports `engine` and `engine_args_override`.
|
|
693
|
+
`engine` is the type of the inference engine to use.
|
|
694
|
+
`engine_args_override` is a list of string arguments to pass to the inference engine.
|
|
725
695
|
|
|
726
696
|
Returns:
|
|
727
697
|
job.MLJob[Any]: A batch inference job object that can be used to monitor progress and manage the job
|
|
@@ -777,12 +747,18 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
777
747
|
subproject=_TELEMETRY_SUBPROJECT,
|
|
778
748
|
)
|
|
779
749
|
|
|
780
|
-
column_handling_as_string = self._encode_column_handling(column_handling)
|
|
781
|
-
params_as_string = self._encode_params(params)
|
|
782
|
-
|
|
783
750
|
if job_spec is None:
|
|
784
751
|
job_spec = batch_inference_specs.JobSpec()
|
|
785
752
|
|
|
753
|
+
# Validate GPU support if GPU resources are requested
|
|
754
|
+
self._throw_error_if_gpu_is_not_supported(job_spec.gpu_requests, statement_params)
|
|
755
|
+
|
|
756
|
+
inference_engine_args = self._prepare_inference_engine_args(
|
|
757
|
+
inference_engine_options,
|
|
758
|
+
job_spec.gpu_requests,
|
|
759
|
+
statement_params,
|
|
760
|
+
)
|
|
761
|
+
|
|
786
762
|
warehouse = job_spec.warehouse or self._service_ops._session.get_current_warehouse()
|
|
787
763
|
if warehouse is None:
|
|
788
764
|
raise ValueError("Warehouse is not set. Please set the warehouse field in the JobSpec.")
|
|
@@ -807,12 +783,14 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
807
783
|
else:
|
|
808
784
|
job_name = job_spec.job_name
|
|
809
785
|
|
|
786
|
+
target_function_info = self._get_function_info(function_name=job_spec.function_name)
|
|
787
|
+
|
|
810
788
|
return self._service_ops.invoke_batch_job_method(
|
|
811
789
|
# model version info
|
|
812
790
|
model_name=self._model_name,
|
|
813
791
|
version_name=self._version_name,
|
|
814
792
|
# job spec
|
|
815
|
-
function_name=
|
|
793
|
+
function_name=target_function_info["target_method"],
|
|
816
794
|
compute_pool_name=sql_identifier.SqlIdentifier(compute_pool),
|
|
817
795
|
force_rebuild=job_spec.force_rebuild,
|
|
818
796
|
image_repo_name=job_spec.image_repo,
|
|
@@ -827,12 +805,14 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
827
805
|
# input and output
|
|
828
806
|
input_stage_location=input_stage_location,
|
|
829
807
|
input_file_pattern="*",
|
|
830
|
-
column_handling=
|
|
831
|
-
params=
|
|
808
|
+
column_handling=column_handling,
|
|
809
|
+
params=params,
|
|
810
|
+
signature_params=target_function_info["signature"].params,
|
|
832
811
|
output_stage_location=output_stage_location,
|
|
833
812
|
completion_filename="_SUCCESS",
|
|
834
813
|
# misc
|
|
835
814
|
statement_params=statement_params,
|
|
815
|
+
inference_engine_args=inference_engine_args,
|
|
836
816
|
)
|
|
837
817
|
|
|
838
818
|
def _get_function_info(self, function_name: Optional[str]) -> model_manifest_schema.ModelFunctionInfo:
|
|
@@ -1048,20 +1028,55 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
1048
1028
|
" the `log_model` function."
|
|
1049
1029
|
)
|
|
1050
1030
|
|
|
1051
|
-
def
|
|
1031
|
+
def _prepare_inference_engine_args(
|
|
1032
|
+
self,
|
|
1033
|
+
inference_engine_options: Optional[dict[str, Any]],
|
|
1034
|
+
gpu_requests: Optional[Union[str, int]],
|
|
1035
|
+
statement_params: Optional[dict[str, Any]] = None,
|
|
1036
|
+
) -> Optional[service_ops.InferenceEngineArgs]:
|
|
1037
|
+
"""Prepare and validate inference engine arguments.
|
|
1038
|
+
|
|
1039
|
+
This method handles the common logic for processing inference engine options:
|
|
1040
|
+
1. Parse inference engine options into InferenceEngineArgs
|
|
1041
|
+
2. Validate that the model is a HuggingFace text-generation model (if inference engine is specified)
|
|
1042
|
+
3. Enrich inference engine args
|
|
1043
|
+
|
|
1044
|
+
Args:
|
|
1045
|
+
inference_engine_options: Optional dictionary containing inference engine configuration.
|
|
1046
|
+
gpu_requests: GPU resource request string (e.g., "4").
|
|
1047
|
+
statement_params: Optional dictionary of statement parameters for SQL commands.
|
|
1048
|
+
|
|
1049
|
+
Returns:
|
|
1050
|
+
Prepared InferenceEngineArgs or None if no inference engine is specified.
|
|
1051
|
+
"""
|
|
1052
|
+
inference_engine_args = inference_engine_utils._get_inference_engine_args(inference_engine_options)
|
|
1053
|
+
|
|
1054
|
+
if inference_engine_args is not None:
|
|
1055
|
+
# Validate that model is HuggingFace vLLM supported model and is logged with
|
|
1056
|
+
# OpenAI compatible signature.
|
|
1057
|
+
self._check_huggingface_vllm_supported_model(statement_params)
|
|
1058
|
+
# Enrich with GPU configuration
|
|
1059
|
+
inference_engine_args = inference_engine_utils._enrich_inference_engine_args(
|
|
1060
|
+
inference_engine_args,
|
|
1061
|
+
gpu_requests,
|
|
1062
|
+
)
|
|
1063
|
+
|
|
1064
|
+
return inference_engine_args
|
|
1065
|
+
|
|
1066
|
+
def _check_huggingface_vllm_supported_model(
|
|
1052
1067
|
self,
|
|
1053
1068
|
statement_params: Optional[dict[str, Any]] = None,
|
|
1054
1069
|
) -> None:
|
|
1055
|
-
"""Check if the model is a HuggingFace pipeline with
|
|
1056
|
-
and is logged with
|
|
1070
|
+
"""Check if the model is a HuggingFace pipeline with vLLM supported task
|
|
1071
|
+
and is logged with OpenAI compatible signature.
|
|
1057
1072
|
|
|
1058
1073
|
Args:
|
|
1059
1074
|
statement_params: Optional dictionary of statement parameters to include
|
|
1060
1075
|
in the SQL command to fetch model spec.
|
|
1061
1076
|
|
|
1062
1077
|
Raises:
|
|
1063
|
-
ValueError: If the model is not a HuggingFace
|
|
1064
|
-
if the model is not logged with
|
|
1078
|
+
ValueError: If the model is not a HuggingFace vLLM supported model or
|
|
1079
|
+
if the model is not logged with OpenAI compatible signature.
|
|
1065
1080
|
"""
|
|
1066
1081
|
# Fetch model spec
|
|
1067
1082
|
model_spec = self._get_model_spec(statement_params)
|
|
@@ -1070,34 +1085,37 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
1070
1085
|
model_type = model_spec.get("model_type")
|
|
1071
1086
|
if model_type != "huggingface_pipeline":
|
|
1072
1087
|
raise ValueError(
|
|
1073
|
-
f"Inference engine is only supported for HuggingFace
|
|
1088
|
+
f"Inference engine is only supported for HuggingFace vLLM supported models. "
|
|
1074
1089
|
f"Found model_type: {model_type}"
|
|
1075
1090
|
)
|
|
1076
1091
|
|
|
1077
|
-
# Check if model supports
|
|
1092
|
+
# Check if model supports vLLM supported task
|
|
1078
1093
|
# There should only be one model in the list because we don't support multiple models in a single model spec
|
|
1079
1094
|
models = model_spec.get("models", {})
|
|
1080
|
-
|
|
1095
|
+
is_vllm_supported_task = False
|
|
1081
1096
|
found_tasks: list[str] = []
|
|
1082
1097
|
|
|
1083
|
-
# As long as the model supports
|
|
1098
|
+
# As long as the model supports vLLM supported task, we can use it
|
|
1084
1099
|
for _, model_info in models.items():
|
|
1085
1100
|
options = model_info.get("options", {})
|
|
1086
1101
|
task = options.get("task")
|
|
1087
1102
|
if task:
|
|
1088
1103
|
found_tasks.append(str(task))
|
|
1089
|
-
if task
|
|
1090
|
-
|
|
1104
|
+
if task in VLLM_SUPPORTED_TASKS:
|
|
1105
|
+
is_vllm_supported_task = True
|
|
1091
1106
|
break
|
|
1092
1107
|
|
|
1093
|
-
if not
|
|
1108
|
+
if not is_vllm_supported_task:
|
|
1094
1109
|
tasks_str = ", ".join(found_tasks)
|
|
1095
1110
|
found_tasks_str = (
|
|
1096
1111
|
f"Found task(s): {tasks_str} in model spec." if found_tasks else "No task found in model spec."
|
|
1097
1112
|
)
|
|
1098
|
-
|
|
1113
|
+
supported_tasks_str = ", ".join(VLLM_SUPPORTED_TASKS)
|
|
1114
|
+
raise ValueError(
|
|
1115
|
+
f"Inference engine is only supported for vLLM supported tasks. {supported_tasks_str}. {found_tasks_str}"
|
|
1116
|
+
)
|
|
1099
1117
|
|
|
1100
|
-
# Check if the model is logged with
|
|
1118
|
+
# Check if the model is logged with OpenAI compatible signature.
|
|
1101
1119
|
signatures_dict = model_spec.get("signatures", {})
|
|
1102
1120
|
|
|
1103
1121
|
# Deserialize signatures from model spec to ModelSignature objects for proper semantic comparison.
|
|
@@ -1105,11 +1123,16 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
1105
1123
|
func_name: core.ModelSignature.from_dict(sig_dict) for func_name, sig_dict in signatures_dict.items()
|
|
1106
1124
|
}
|
|
1107
1125
|
|
|
1108
|
-
if deserialized_signatures
|
|
1126
|
+
if deserialized_signatures not in [
|
|
1127
|
+
openai_signatures.OPENAI_CHAT_SIGNATURE,
|
|
1128
|
+
openai_signatures.OPENAI_CHAT_SIGNATURE_WITH_CONTENT_FORMAT_STRING,
|
|
1129
|
+
]:
|
|
1109
1130
|
raise ValueError(
|
|
1110
|
-
"Inference engine requires the model to be logged with OPENAI_CHAT_SIGNATURE
|
|
1131
|
+
"Inference engine requires the model to be logged with openai_signatures.OPENAI_CHAT_SIGNATURE or "
|
|
1132
|
+
"openai_signatures.OPENAI_CHAT_SIGNATURE_WITH_CONTENT_FORMAT_STRING. "
|
|
1111
1133
|
f"Found signatures: {signatures_dict}. "
|
|
1112
|
-
"Please log the model with: signatures=openai_signatures.OPENAI_CHAT_SIGNATURE"
|
|
1134
|
+
"Please log the model again with: signatures=openai_signatures.OPENAI_CHAT_SIGNATURE or "
|
|
1135
|
+
"signatures=openai_signatures.OPENAI_CHAT_SIGNATURE_WITH_CONTENT_FORMAT_STRING"
|
|
1113
1136
|
)
|
|
1114
1137
|
|
|
1115
1138
|
@overload
|
|
@@ -1350,20 +1373,11 @@ class ModelVersion(lineage_node.LineageNode):
|
|
|
1350
1373
|
# Validate GPU support if GPU resources are requested
|
|
1351
1374
|
self._throw_error_if_gpu_is_not_supported(gpu_requests, statement_params)
|
|
1352
1375
|
|
|
1353
|
-
inference_engine_args =
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
if inference_engine_args is not None:
|
|
1359
|
-
self._check_huggingface_text_generation_model(statement_params)
|
|
1360
|
-
|
|
1361
|
-
# Enrich inference engine args if inference engine is specified
|
|
1362
|
-
if inference_engine_args is not None:
|
|
1363
|
-
inference_engine_args = inference_engine_utils._enrich_inference_engine_args(
|
|
1364
|
-
inference_engine_args,
|
|
1365
|
-
gpu_requests,
|
|
1366
|
-
)
|
|
1376
|
+
inference_engine_args = self._prepare_inference_engine_args(
|
|
1377
|
+
inference_engine_options,
|
|
1378
|
+
gpu_requests,
|
|
1379
|
+
statement_params,
|
|
1380
|
+
)
|
|
1367
1381
|
|
|
1368
1382
|
from snowflake.ml.model import event_handler
|
|
1369
1383
|
from snowflake.snowpark import exceptions
|
|
@@ -14,7 +14,7 @@ from snowflake.ml._internal import platform_capabilities
|
|
|
14
14
|
from snowflake.ml._internal.exceptions import error_codes, exceptions
|
|
15
15
|
from snowflake.ml._internal.utils import formatting, identifier, sql_identifier, url
|
|
16
16
|
from snowflake.ml.model import model_signature, type_hints
|
|
17
|
-
from snowflake.ml.model._client.ops import deployment_step, metadata_ops
|
|
17
|
+
from snowflake.ml.model._client.ops import deployment_step, metadata_ops, param_utils
|
|
18
18
|
from snowflake.ml.model._client.sql import (
|
|
19
19
|
model as model_sql,
|
|
20
20
|
model_version as model_version_sql,
|
|
@@ -1063,23 +1063,7 @@ class ModelOperator:
|
|
|
1063
1063
|
col_name = sql_identifier.SqlIdentifier(input_feature.name.upper(), case_sensitive=True)
|
|
1064
1064
|
input_args.append(col_name)
|
|
1065
1065
|
|
|
1066
|
-
method_parameters
|
|
1067
|
-
if signature.params:
|
|
1068
|
-
# Start with defaults from signature
|
|
1069
|
-
final_params = {}
|
|
1070
|
-
for param_spec in signature.params:
|
|
1071
|
-
if hasattr(param_spec, "default_value"):
|
|
1072
|
-
final_params[param_spec.name] = param_spec.default_value
|
|
1073
|
-
|
|
1074
|
-
# Override with provided runtime parameters
|
|
1075
|
-
if params:
|
|
1076
|
-
final_params.update(params)
|
|
1077
|
-
|
|
1078
|
-
# Convert to list of tuples with SqlIdentifier for parameter names
|
|
1079
|
-
method_parameters = [
|
|
1080
|
-
(sql_identifier.SqlIdentifier(param_name), param_value)
|
|
1081
|
-
for param_name, param_value in final_params.items()
|
|
1082
|
-
]
|
|
1066
|
+
method_parameters = param_utils.validate_and_resolve_params(params, signature.params)
|
|
1083
1067
|
|
|
1084
1068
|
returns = []
|
|
1085
1069
|
for output_feature in signature.outputs:
|