snowflake-ml-python 1.6.1__py3-none-any.whl → 1.6.3__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/cortex/__init__.py +4 -0
- snowflake/cortex/_classify_text.py +2 -2
- snowflake/cortex/_embed_text_1024.py +37 -0
- snowflake/cortex/_embed_text_768.py +37 -0
- snowflake/cortex/_extract_answer.py +2 -2
- snowflake/cortex/_sentiment.py +2 -2
- snowflake/cortex/_summarize.py +2 -2
- snowflake/cortex/_translate.py +2 -2
- snowflake/cortex/_util.py +4 -4
- snowflake/ml/_internal/env_utils.py +5 -5
- snowflake/ml/_internal/exceptions/error_codes.py +2 -0
- snowflake/ml/_internal/telemetry.py +142 -20
- snowflake/ml/_internal/utils/db_utils.py +50 -0
- snowflake/ml/_internal/utils/identifier.py +48 -11
- snowflake/ml/_internal/utils/service_logger.py +63 -0
- snowflake/ml/_internal/utils/snowflake_env.py +23 -13
- snowflake/ml/_internal/utils/sql_identifier.py +26 -2
- snowflake/ml/_internal/utils/table_manager.py +19 -1
- snowflake/ml/data/_internal/arrow_ingestor.py +1 -11
- snowflake/ml/data/data_connector.py +33 -7
- snowflake/ml/data/ingestor_utils.py +20 -10
- snowflake/ml/data/torch_utils.py +68 -0
- snowflake/ml/dataset/dataset.py +1 -3
- snowflake/ml/feature_store/access_manager.py +3 -3
- snowflake/ml/feature_store/feature_store.py +60 -19
- snowflake/ml/feature_store/feature_view.py +84 -30
- snowflake/ml/fileset/embedded_stage_fs.py +1 -1
- snowflake/ml/fileset/fileset.py +1 -1
- snowflake/ml/fileset/sfcfs.py +9 -3
- snowflake/ml/fileset/stage_fs.py +2 -1
- snowflake/ml/lineage/lineage_node.py +7 -2
- snowflake/ml/model/__init__.py +1 -2
- snowflake/ml/model/_client/model/model_version_impl.py +96 -12
- snowflake/ml/model/_client/ops/model_ops.py +124 -6
- snowflake/ml/model/_client/ops/service_ops.py +309 -9
- snowflake/ml/model/_client/service/model_deployment_spec.py +8 -5
- snowflake/ml/model/_client/service/model_deployment_spec_schema.py +2 -2
- snowflake/ml/model/_client/sql/_base.py +5 -0
- snowflake/ml/model/_client/sql/model.py +1 -0
- snowflake/ml/model/_client/sql/model_version.py +9 -5
- snowflake/ml/model/_client/sql/service.py +121 -20
- snowflake/ml/model/_model_composer/model_composer.py +11 -39
- snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +31 -11
- snowflake/ml/model/_packager/model_env/model_env.py +4 -38
- snowflake/ml/model/_packager/model_handlers/_utils.py +134 -28
- snowflake/ml/model/_packager/model_handlers/catboost.py +31 -30
- snowflake/ml/model/_packager/model_handlers/huggingface_pipeline.py +26 -18
- snowflake/ml/model/_packager/model_handlers/lightgbm.py +31 -58
- snowflake/ml/model/_packager/model_handlers/mlflow.py +3 -5
- snowflake/ml/model/_packager/model_handlers/model_objective_utils.py +169 -0
- snowflake/ml/model/_packager/model_handlers/sentence_transformers.py +15 -8
- snowflake/ml/model/_packager/model_handlers/sklearn.py +56 -60
- snowflake/ml/model/_packager/model_handlers/snowmlmodel.py +141 -9
- snowflake/ml/model/_packager/model_handlers/torchscript.py +2 -2
- snowflake/ml/model/_packager/model_handlers/xgboost.py +63 -48
- snowflake/ml/model/_packager/model_meta/model_meta.py +16 -42
- snowflake/ml/model/_packager/model_meta/model_meta_schema.py +1 -14
- snowflake/ml/model/_packager/model_packager.py +14 -8
- snowflake/ml/model/_packager/model_runtime/model_runtime.py +11 -0
- snowflake/ml/model/_signatures/pytorch_handler.py +1 -1
- snowflake/ml/model/_signatures/snowpark_handler.py +3 -2
- snowflake/ml/model/_signatures/utils.py +9 -0
- snowflake/ml/model/type_hints.py +12 -145
- snowflake/ml/modeling/_internal/constants.py +1 -0
- snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +5 -5
- snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +9 -6
- snowflake/ml/modeling/_internal/model_specifications.py +2 -0
- snowflake/ml/modeling/_internal/model_trainer.py +1 -0
- snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +2 -4
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +5 -5
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +130 -166
- snowflake/ml/modeling/_internal/snowpark_implementations/xgboost_external_memory_trainer.py +0 -1
- snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +61 -21
- snowflake/ml/modeling/cluster/affinity_propagation.py +61 -21
- snowflake/ml/modeling/cluster/agglomerative_clustering.py +61 -21
- snowflake/ml/modeling/cluster/birch.py +61 -21
- snowflake/ml/modeling/cluster/bisecting_k_means.py +61 -21
- snowflake/ml/modeling/cluster/dbscan.py +61 -21
- snowflake/ml/modeling/cluster/feature_agglomeration.py +61 -21
- snowflake/ml/modeling/cluster/k_means.py +61 -21
- snowflake/ml/modeling/cluster/mean_shift.py +61 -21
- snowflake/ml/modeling/cluster/mini_batch_k_means.py +61 -21
- snowflake/ml/modeling/cluster/optics.py +61 -21
- snowflake/ml/modeling/cluster/spectral_biclustering.py +61 -21
- snowflake/ml/modeling/cluster/spectral_clustering.py +61 -21
- snowflake/ml/modeling/cluster/spectral_coclustering.py +61 -21
- snowflake/ml/modeling/compose/column_transformer.py +61 -21
- snowflake/ml/modeling/compose/transformed_target_regressor.py +61 -21
- snowflake/ml/modeling/covariance/elliptic_envelope.py +61 -21
- snowflake/ml/modeling/covariance/empirical_covariance.py +61 -21
- snowflake/ml/modeling/covariance/graphical_lasso.py +61 -21
- snowflake/ml/modeling/covariance/graphical_lasso_cv.py +61 -21
- snowflake/ml/modeling/covariance/ledoit_wolf.py +61 -21
- snowflake/ml/modeling/covariance/min_cov_det.py +61 -21
- snowflake/ml/modeling/covariance/oas.py +61 -21
- snowflake/ml/modeling/covariance/shrunk_covariance.py +61 -21
- snowflake/ml/modeling/decomposition/dictionary_learning.py +61 -21
- snowflake/ml/modeling/decomposition/factor_analysis.py +61 -21
- snowflake/ml/modeling/decomposition/fast_ica.py +61 -21
- snowflake/ml/modeling/decomposition/incremental_pca.py +61 -21
- snowflake/ml/modeling/decomposition/kernel_pca.py +61 -21
- snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +61 -21
- snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +61 -21
- snowflake/ml/modeling/decomposition/pca.py +61 -21
- snowflake/ml/modeling/decomposition/sparse_pca.py +61 -21
- snowflake/ml/modeling/decomposition/truncated_svd.py +61 -21
- snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +61 -21
- snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +61 -21
- snowflake/ml/modeling/ensemble/ada_boost_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/ada_boost_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/bagging_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/bagging_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/extra_trees_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/extra_trees_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/isolation_forest.py +61 -21
- snowflake/ml/modeling/ensemble/random_forest_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/random_forest_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/stacking_regressor.py +61 -21
- snowflake/ml/modeling/ensemble/voting_classifier.py +61 -21
- snowflake/ml/modeling/ensemble/voting_regressor.py +61 -21
- snowflake/ml/modeling/feature_selection/generic_univariate_select.py +61 -21
- snowflake/ml/modeling/feature_selection/select_fdr.py +61 -21
- snowflake/ml/modeling/feature_selection/select_fpr.py +61 -21
- snowflake/ml/modeling/feature_selection/select_fwe.py +61 -21
- snowflake/ml/modeling/feature_selection/select_k_best.py +61 -21
- snowflake/ml/modeling/feature_selection/select_percentile.py +61 -21
- snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +61 -21
- snowflake/ml/modeling/feature_selection/variance_threshold.py +61 -21
- snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +61 -21
- snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +61 -21
- snowflake/ml/modeling/impute/iterative_imputer.py +61 -21
- snowflake/ml/modeling/impute/knn_imputer.py +61 -21
- snowflake/ml/modeling/impute/missing_indicator.py +61 -21
- snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +61 -21
- snowflake/ml/modeling/kernel_approximation/nystroem.py +61 -21
- snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +61 -21
- snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +61 -21
- snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +61 -21
- snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +61 -21
- snowflake/ml/modeling/lightgbm/lgbm_classifier.py +61 -21
- snowflake/ml/modeling/lightgbm/lgbm_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/ard_regression.py +61 -21
- snowflake/ml/modeling/linear_model/bayesian_ridge.py +61 -21
- snowflake/ml/modeling/linear_model/elastic_net.py +61 -21
- snowflake/ml/modeling/linear_model/elastic_net_cv.py +61 -21
- snowflake/ml/modeling/linear_model/gamma_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/huber_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/lars.py +61 -21
- snowflake/ml/modeling/linear_model/lars_cv.py +61 -21
- snowflake/ml/modeling/linear_model/lasso.py +61 -21
- snowflake/ml/modeling/linear_model/lasso_cv.py +61 -21
- snowflake/ml/modeling/linear_model/lasso_lars.py +61 -21
- snowflake/ml/modeling/linear_model/lasso_lars_cv.py +61 -21
- snowflake/ml/modeling/linear_model/lasso_lars_ic.py +61 -21
- snowflake/ml/modeling/linear_model/linear_regression.py +61 -21
- snowflake/ml/modeling/linear_model/logistic_regression.py +61 -21
- snowflake/ml/modeling/linear_model/logistic_regression_cv.py +61 -21
- snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +61 -21
- snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +61 -21
- snowflake/ml/modeling/linear_model/multi_task_lasso.py +61 -21
- snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +61 -21
- snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +61 -21
- snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +61 -21
- snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/perceptron.py +61 -21
- snowflake/ml/modeling/linear_model/poisson_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/ransac_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/ridge.py +61 -21
- snowflake/ml/modeling/linear_model/ridge_classifier.py +61 -21
- snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +61 -21
- snowflake/ml/modeling/linear_model/ridge_cv.py +61 -21
- snowflake/ml/modeling/linear_model/sgd_classifier.py +61 -21
- snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +61 -21
- snowflake/ml/modeling/linear_model/sgd_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/theil_sen_regressor.py +61 -21
- snowflake/ml/modeling/linear_model/tweedie_regressor.py +61 -21
- snowflake/ml/modeling/manifold/isomap.py +61 -21
- snowflake/ml/modeling/manifold/mds.py +61 -21
- snowflake/ml/modeling/manifold/spectral_embedding.py +61 -21
- snowflake/ml/modeling/manifold/tsne.py +61 -21
- snowflake/ml/modeling/metrics/metrics_utils.py +2 -2
- snowflake/ml/modeling/metrics/ranking.py +0 -3
- snowflake/ml/modeling/metrics/regression.py +0 -3
- snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +61 -21
- snowflake/ml/modeling/mixture/gaussian_mixture.py +61 -21
- snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +61 -21
- snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +61 -21
- snowflake/ml/modeling/multiclass/output_code_classifier.py +61 -21
- snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +61 -21
- snowflake/ml/modeling/naive_bayes/categorical_nb.py +61 -21
- snowflake/ml/modeling/naive_bayes/complement_nb.py +61 -21
- snowflake/ml/modeling/naive_bayes/gaussian_nb.py +61 -21
- snowflake/ml/modeling/naive_bayes/multinomial_nb.py +61 -21
- snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +61 -21
- snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +61 -21
- snowflake/ml/modeling/neighbors/kernel_density.py +61 -21
- snowflake/ml/modeling/neighbors/local_outlier_factor.py +61 -21
- snowflake/ml/modeling/neighbors/nearest_centroid.py +61 -21
- snowflake/ml/modeling/neighbors/nearest_neighbors.py +61 -21
- snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +61 -21
- snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +61 -21
- snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +61 -21
- snowflake/ml/modeling/neural_network/bernoulli_rbm.py +61 -21
- snowflake/ml/modeling/neural_network/mlp_classifier.py +61 -21
- snowflake/ml/modeling/neural_network/mlp_regressor.py +61 -21
- snowflake/ml/modeling/parameters/disable_model_tracer.py +5 -0
- snowflake/ml/modeling/pipeline/pipeline.py +1 -13
- snowflake/ml/modeling/preprocessing/polynomial_features.py +61 -21
- snowflake/ml/modeling/semi_supervised/label_propagation.py +61 -21
- snowflake/ml/modeling/semi_supervised/label_spreading.py +61 -21
- snowflake/ml/modeling/svm/linear_svc.py +61 -21
- snowflake/ml/modeling/svm/linear_svr.py +61 -21
- snowflake/ml/modeling/svm/nu_svc.py +61 -21
- snowflake/ml/modeling/svm/nu_svr.py +61 -21
- snowflake/ml/modeling/svm/svc.py +61 -21
- snowflake/ml/modeling/svm/svr.py +61 -21
- snowflake/ml/modeling/tree/decision_tree_classifier.py +61 -21
- snowflake/ml/modeling/tree/decision_tree_regressor.py +61 -21
- snowflake/ml/modeling/tree/extra_tree_classifier.py +61 -21
- snowflake/ml/modeling/tree/extra_tree_regressor.py +61 -21
- snowflake/ml/modeling/xgboost/xgb_classifier.py +64 -23
- snowflake/ml/modeling/xgboost/xgb_regressor.py +64 -23
- snowflake/ml/modeling/xgboost/xgbrf_classifier.py +64 -23
- snowflake/ml/modeling/xgboost/xgbrf_regressor.py +64 -23
- snowflake/ml/monitoring/_client/model_monitor.py +126 -0
- snowflake/ml/monitoring/_client/model_monitor_manager.py +361 -0
- snowflake/ml/monitoring/_client/model_monitor_version.py +1 -0
- snowflake/ml/monitoring/_client/monitor_sql_client.py +1335 -0
- snowflake/ml/monitoring/_client/queries/record_count.ssql +14 -0
- snowflake/ml/monitoring/_client/queries/rmse.ssql +28 -0
- snowflake/ml/monitoring/entities/model_monitor_config.py +28 -0
- snowflake/ml/monitoring/entities/model_monitor_interval.py +46 -0
- snowflake/ml/monitoring/entities/output_score_type.py +90 -0
- snowflake/ml/registry/_manager/model_manager.py +4 -0
- snowflake/ml/registry/registry.py +166 -8
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.6.1.dist-info → snowflake_ml_python-1.6.3.dist-info}/METADATA +43 -9
- snowflake_ml_python-1.6.3.dist-info/RECORD +400 -0
- {snowflake_ml_python-1.6.1.dist-info → snowflake_ml_python-1.6.3.dist-info}/WHEEL +1 -1
- snowflake/ml/_internal/container_services/image_registry/credential.py +0 -84
- snowflake/ml/_internal/container_services/image_registry/http_client.py +0 -127
- snowflake/ml/_internal/container_services/image_registry/imagelib.py +0 -400
- snowflake/ml/_internal/container_services/image_registry/registry_client.py +0 -212
- snowflake/ml/_internal/utils/log_stream_processor.py +0 -30
- snowflake/ml/_internal/utils/session_token_manager.py +0 -46
- snowflake/ml/_internal/utils/spcs_attribution_utils.py +0 -122
- snowflake/ml/_internal/utils/uri.py +0 -77
- snowflake/ml/data/torch_dataset.py +0 -33
- snowflake/ml/model/_api.py +0 -568
- snowflake/ml/model/_deploy_client/image_builds/base_image_builder.py +0 -12
- snowflake/ml/model/_deploy_client/image_builds/client_image_builder.py +0 -249
- snowflake/ml/model/_deploy_client/image_builds/docker_context.py +0 -130
- snowflake/ml/model/_deploy_client/image_builds/gunicorn_run.sh +0 -36
- snowflake/ml/model/_deploy_client/image_builds/inference_server/main.py +0 -268
- snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +0 -215
- snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +0 -53
- snowflake/ml/model/_deploy_client/image_builds/templates/image_build_job_spec_template +0 -38
- snowflake/ml/model/_deploy_client/image_builds/templates/kaniko_shell_script_template +0 -105
- snowflake/ml/model/_deploy_client/snowservice/deploy.py +0 -611
- snowflake/ml/model/_deploy_client/snowservice/deploy_options.py +0 -116
- snowflake/ml/model/_deploy_client/snowservice/instance_types.py +0 -10
- snowflake/ml/model/_deploy_client/snowservice/templates/service_spec_template +0 -28
- snowflake/ml/model/_deploy_client/snowservice/templates/service_spec_template_with_model +0 -21
- snowflake/ml/model/_deploy_client/utils/constants.py +0 -48
- snowflake/ml/model/_deploy_client/utils/snowservice_client.py +0 -280
- snowflake/ml/model/_deploy_client/warehouse/deploy.py +0 -202
- snowflake/ml/model/_deploy_client/warehouse/infer_template.py +0 -99
- snowflake/ml/model/_packager/model_handlers/llm.py +0 -267
- snowflake/ml/model/_packager/model_meta/_core_requirements.py +0 -11
- snowflake/ml/model/deploy_platforms.py +0 -6
- snowflake/ml/model/models/llm.py +0 -104
- snowflake/ml/monitoring/monitor.py +0 -203
- snowflake/ml/registry/_initial_schema.py +0 -142
- snowflake/ml/registry/_schema.py +0 -82
- snowflake/ml/registry/_schema_upgrade_plans.py +0 -116
- snowflake/ml/registry/_schema_version_manager.py +0 -163
- snowflake/ml/registry/model_registry.py +0 -2048
- snowflake_ml_python-1.6.1.dist-info/RECORD +0 -422
- {snowflake_ml_python-1.6.1.dist-info → snowflake_ml_python-1.6.3.dist-info}/LICENSE.txt +0 -0
- {snowflake_ml_python-1.6.1.dist-info → snowflake_ml_python-1.6.3.dist-info}/top_level.txt +0 -0
@@ -2,7 +2,6 @@ import os
|
|
2
2
|
import pathlib
|
3
3
|
import sys
|
4
4
|
import tempfile
|
5
|
-
import warnings
|
6
5
|
import zipfile
|
7
6
|
from contextlib import contextmanager
|
8
7
|
from datetime import datetime
|
@@ -18,7 +17,6 @@ from snowflake.ml._internal import env as snowml_env, env_utils, file_utils
|
|
18
17
|
from snowflake.ml.model import model_signature, type_hints as model_types
|
19
18
|
from snowflake.ml.model._packager.model_env import model_env
|
20
19
|
from snowflake.ml.model._packager.model_meta import (
|
21
|
-
_core_requirements,
|
22
20
|
_packaging_requirements,
|
23
21
|
model_blob_meta,
|
24
22
|
model_meta_schema,
|
@@ -29,14 +27,10 @@ from snowflake.ml.model._packager.model_runtime import model_runtime
|
|
29
27
|
MODEL_METADATA_FILE = "model.yaml"
|
30
28
|
MODEL_CODE_DIR = "code"
|
31
29
|
|
32
|
-
_PACKAGING_CORE_DEPENDENCIES = [
|
33
|
-
str(env_utils.get_package_spec_with_supported_ops_only(requirements.Requirement(r)))
|
34
|
-
for r in _core_requirements.REQUIREMENTS
|
35
|
-
] # Legacy Model only
|
36
30
|
_PACKAGING_REQUIREMENTS = [
|
37
31
|
str(env_utils.get_package_spec_with_supported_ops_only(requirements.Requirement(r)))
|
38
32
|
for r in _packaging_requirements.REQUIREMENTS
|
39
|
-
]
|
33
|
+
]
|
40
34
|
_SNOWFLAKE_PKG_NAME = "snowflake"
|
41
35
|
_SNOWFLAKE_ML_PKG_NAME = f"{_SNOWFLAKE_PKG_NAME}.ml"
|
42
36
|
|
@@ -55,6 +49,7 @@ def create_model_metadata(
|
|
55
49
|
conda_dependencies: Optional[List[str]] = None,
|
56
50
|
pip_requirements: Optional[List[str]] = None,
|
57
51
|
python_version: Optional[str] = None,
|
52
|
+
task: model_types.Task = model_types.Task.UNKNOWN,
|
58
53
|
**kwargs: Any,
|
59
54
|
) -> Generator["ModelMetadata", None, None]:
|
60
55
|
"""Create a generator for model metadata object. Use generator to ensure correct register and unregister for
|
@@ -74,6 +69,9 @@ def create_model_metadata(
|
|
74
69
|
pip_requirements: List of pip Python packages requirements for running the model. Defaults to None.
|
75
70
|
python_version: A string of python version where model is run. Used for user override. If specified as None,
|
76
71
|
current version would be captured. Defaults to None.
|
72
|
+
task: The task of the Model Version. It is an enum class Task with values TABULAR_REGRESSION,
|
73
|
+
TABULAR_BINARY_CLASSIFICATION, TABULAR_MULTI_CLASSIFICATION, TABULAR_RANKING, or UNKNOWN. By default,
|
74
|
+
it is set to Task.UNKNOWN and may be overridden by inferring from the Model Object.
|
77
75
|
**kwargs: Dict of attributes and values of the metadata. Used when loading from file.
|
78
76
|
|
79
77
|
Raises:
|
@@ -84,18 +82,6 @@ def create_model_metadata(
|
|
84
82
|
"""
|
85
83
|
model_dir_path = os.path.normpath(model_dir_path)
|
86
84
|
embed_local_ml_library = kwargs.pop("embed_local_ml_library", False)
|
87
|
-
legacy_save = kwargs.pop("_legacy_save", False)
|
88
|
-
if "relax_version" not in kwargs:
|
89
|
-
warnings.warn(
|
90
|
-
(
|
91
|
-
"`relax_version` is not set and therefore defaulted to True. Dependency version constraints relaxed "
|
92
|
-
"from ==x.y.z to >=x.y, <(x+1). To use specific dependency versions for compatibility, "
|
93
|
-
"reproducibility, etc., set `options={'relax_version': False}` when logging the model."
|
94
|
-
),
|
95
|
-
category=UserWarning,
|
96
|
-
stacklevel=2,
|
97
|
-
)
|
98
|
-
relax_version = kwargs.pop("relax_version", True)
|
99
85
|
|
100
86
|
if embed_local_ml_library:
|
101
87
|
# Use the last one which is loaded first, that is mean, it is loaded from site-packages.
|
@@ -118,7 +104,6 @@ def create_model_metadata(
|
|
118
104
|
pip_requirements=pip_requirements,
|
119
105
|
python_version=python_version,
|
120
106
|
embed_local_ml_library=embed_local_ml_library,
|
121
|
-
legacy_save=legacy_save,
|
122
107
|
)
|
123
108
|
|
124
109
|
if embed_local_ml_library:
|
@@ -131,17 +116,13 @@ def create_model_metadata(
|
|
131
116
|
model_type=model_type,
|
132
117
|
signatures=signatures,
|
133
118
|
function_properties=function_properties,
|
119
|
+
task=task,
|
134
120
|
)
|
135
121
|
|
136
122
|
code_dir_path = os.path.join(model_dir_path, MODEL_CODE_DIR)
|
137
|
-
if
|
123
|
+
if code_paths:
|
138
124
|
os.makedirs(code_dir_path, exist_ok=True)
|
139
125
|
|
140
|
-
if embed_local_ml_library and legacy_save:
|
141
|
-
snowml_path_in_code = os.path.join(code_dir_path, _SNOWFLAKE_PKG_NAME)
|
142
|
-
os.makedirs(snowml_path_in_code, exist_ok=True)
|
143
|
-
file_utils.copy_file_or_tree(path_to_copy, snowml_path_in_code)
|
144
|
-
|
145
126
|
if code_paths:
|
146
127
|
for code_path in code_paths:
|
147
128
|
# This part is to prevent users from providing code following our naming and overwrite our code.
|
@@ -160,8 +141,6 @@ def create_model_metadata(
|
|
160
141
|
cloudpickle.register_pickle_by_value(mod)
|
161
142
|
imported_modules.append(mod)
|
162
143
|
yield model_meta
|
163
|
-
if relax_version:
|
164
|
-
model_meta.env.relax_version()
|
165
144
|
model_meta.save(model_dir_path)
|
166
145
|
finally:
|
167
146
|
for mod in imported_modules:
|
@@ -174,7 +153,6 @@ def _create_env_for_model_metadata(
|
|
174
153
|
pip_requirements: Optional[List[str]] = None,
|
175
154
|
python_version: Optional[str] = None,
|
176
155
|
embed_local_ml_library: bool = False,
|
177
|
-
legacy_save: bool = False,
|
178
156
|
) -> model_env.ModelEnv:
|
179
157
|
env = model_env.ModelEnv()
|
180
158
|
|
@@ -184,7 +162,7 @@ def _create_env_for_model_metadata(
|
|
184
162
|
env.python_version = python_version # type: ignore[assignment]
|
185
163
|
env.snowpark_ml_version = snowml_env.VERSION
|
186
164
|
|
187
|
-
requirements_to_add =
|
165
|
+
requirements_to_add = _PACKAGING_REQUIREMENTS
|
188
166
|
|
189
167
|
if embed_local_ml_library:
|
190
168
|
env.include_if_absent(
|
@@ -237,7 +215,7 @@ class ModelMetadata:
|
|
237
215
|
function_properties: A dict mapping function names to dict mapping function property key to value.
|
238
216
|
metadata: User provided key-value metadata of the model. Defaults to None.
|
239
217
|
creation_timestamp: Unix timestamp when the model metadata is created.
|
240
|
-
|
218
|
+
task: Model task like TABULAR_REGRESSION, tabular_classification, timeseries_forecasting etc.
|
241
219
|
"""
|
242
220
|
|
243
221
|
def telemetry_metadata(self) -> ModelMetadataTelemetryDict:
|
@@ -261,7 +239,7 @@ class ModelMetadata:
|
|
261
239
|
min_snowpark_ml_version: Optional[str] = None,
|
262
240
|
models: Optional[Dict[str, model_blob_meta.ModelBlobMeta]] = None,
|
263
241
|
original_metadata_version: Optional[str] = model_meta_schema.MODEL_METADATA_VERSION,
|
264
|
-
|
242
|
+
task: model_types.Task = model_types.Task.UNKNOWN,
|
265
243
|
explain_algorithm: Optional[model_meta_schema.ModelExplainAlgorithm] = None,
|
266
244
|
) -> None:
|
267
245
|
self.name = name
|
@@ -287,9 +265,7 @@ class ModelMetadata:
|
|
287
265
|
|
288
266
|
self.original_metadata_version = original_metadata_version
|
289
267
|
|
290
|
-
self.
|
291
|
-
model_objective or model_meta_schema.ModelObjective.UNKNOWN
|
292
|
-
)
|
268
|
+
self.task: model_types.Task = task
|
293
269
|
self.explain_algorithm: Optional[model_meta_schema.ModelExplainAlgorithm] = explain_algorithm
|
294
270
|
|
295
271
|
@property
|
@@ -306,10 +282,10 @@ class ModelMetadata:
|
|
306
282
|
if self._runtimes and "cpu" in self._runtimes:
|
307
283
|
return self._runtimes
|
308
284
|
runtimes = {
|
309
|
-
"cpu": model_runtime.ModelRuntime("cpu", self.env),
|
285
|
+
"cpu": model_runtime.ModelRuntime("cpu", self.env, is_warehouse=False),
|
310
286
|
}
|
311
287
|
if self.env.cuda_version:
|
312
|
-
runtimes.update({"gpu": model_runtime.ModelRuntime("gpu", self.env, is_gpu=True)})
|
288
|
+
runtimes.update({"gpu": model_runtime.ModelRuntime("gpu", self.env, is_warehouse=False, is_gpu=True)})
|
313
289
|
return runtimes
|
314
290
|
|
315
291
|
def save(self, model_dir_path: str) -> None:
|
@@ -343,7 +319,7 @@ class ModelMetadata:
|
|
343
319
|
"signatures": {func_name: sig.to_dict() for func_name, sig in self.signatures.items()},
|
344
320
|
"version": model_meta_schema.MODEL_METADATA_VERSION,
|
345
321
|
"min_snowpark_ml_version": self.min_snowpark_ml_version,
|
346
|
-
"
|
322
|
+
"task": self.task.value,
|
347
323
|
"explainability": (
|
348
324
|
model_meta_schema.ExplainabilityMetadataDict(algorithm=self.explain_algorithm.value)
|
349
325
|
if self.explain_algorithm
|
@@ -387,7 +363,7 @@ class ModelMetadata:
|
|
387
363
|
signatures=loaded_meta["signatures"],
|
388
364
|
version=original_loaded_meta_version,
|
389
365
|
min_snowpark_ml_version=loaded_meta_min_snowpark_ml_version,
|
390
|
-
|
366
|
+
task=loaded_meta.get("task", model_types.Task.UNKNOWN.value),
|
391
367
|
explainability=loaded_meta.get("explainability", None),
|
392
368
|
function_properties=loaded_meta.get("function_properties", {}),
|
393
369
|
)
|
@@ -442,9 +418,7 @@ class ModelMetadata:
|
|
442
418
|
min_snowpark_ml_version=model_dict["min_snowpark_ml_version"],
|
443
419
|
models=models,
|
444
420
|
original_metadata_version=model_dict["version"],
|
445
|
-
|
446
|
-
model_dict.get("model_objective", model_meta_schema.ModelObjective.UNKNOWN.value)
|
447
|
-
),
|
421
|
+
task=model_types.Task(model_dict.get("task", model_types.Task.UNKNOWN.value)),
|
448
422
|
explain_algorithm=explanation_algorithm,
|
449
423
|
function_properties=model_dict.get("function_properties", {}),
|
450
424
|
)
|
@@ -50,10 +50,6 @@ class LightGBMModelBlobOptions(BaseModelBlobOptions):
|
|
50
50
|
lightgbm_estimator_type: Required[str]
|
51
51
|
|
52
52
|
|
53
|
-
class LLMModelBlobOptions(BaseModelBlobOptions):
|
54
|
-
batch_size: Required[int]
|
55
|
-
|
56
|
-
|
57
53
|
class MLFlowModelBlobOptions(BaseModelBlobOptions):
|
58
54
|
artifact_path: Required[str]
|
59
55
|
|
@@ -65,7 +61,6 @@ class XgboostModelBlobOptions(BaseModelBlobOptions):
|
|
65
61
|
ModelBlobOptions = Union[
|
66
62
|
BaseModelBlobOptions,
|
67
63
|
HuggingFacePipelineModelBlobOptions,
|
68
|
-
LLMModelBlobOptions,
|
69
64
|
MLFlowModelBlobOptions,
|
70
65
|
XgboostModelBlobOptions,
|
71
66
|
]
|
@@ -96,18 +91,10 @@ class ModelMetadataDict(TypedDict):
|
|
96
91
|
signatures: Required[Dict[str, Dict[str, Any]]]
|
97
92
|
version: Required[str]
|
98
93
|
min_snowpark_ml_version: Required[str]
|
99
|
-
|
94
|
+
task: Required[str]
|
100
95
|
explainability: NotRequired[Optional[ExplainabilityMetadataDict]]
|
101
96
|
function_properties: NotRequired[Dict[str, Dict[str, Any]]]
|
102
97
|
|
103
98
|
|
104
|
-
class ModelObjective(Enum):
|
105
|
-
UNKNOWN = "unknown"
|
106
|
-
BINARY_CLASSIFICATION = "binary_classification"
|
107
|
-
MULTI_CLASSIFICATION = "multi_classification"
|
108
|
-
REGRESSION = "regression"
|
109
|
-
RANKING = "ranking"
|
110
|
-
|
111
|
-
|
112
99
|
class ModelExplainAlgorithm(Enum):
|
113
100
|
SHAP = "shap"
|
@@ -47,7 +47,9 @@ class ModelPackager:
|
|
47
47
|
ext_modules: Optional[List[ModuleType]] = None,
|
48
48
|
code_paths: Optional[List[str]] = None,
|
49
49
|
options: Optional[model_types.ModelSaveOption] = None,
|
50
|
+
task: model_types.Task = model_types.Task.UNKNOWN,
|
50
51
|
) -> model_meta.ModelMetadata:
|
52
|
+
|
51
53
|
if (signatures is None) and (sample_input_data is None) and not model_handler.is_auto_signature_model(model):
|
52
54
|
raise snowml_exceptions.SnowflakeMLException(
|
53
55
|
error_code=error_codes.INVALID_ARGUMENT,
|
@@ -56,17 +58,20 @@ class ModelPackager:
|
|
56
58
|
),
|
57
59
|
)
|
58
60
|
|
59
|
-
if (signatures is not None) and (sample_input_data is not None):
|
60
|
-
raise snowml_exceptions.SnowflakeMLException(
|
61
|
-
error_code=error_codes.INVALID_ARGUMENT,
|
62
|
-
original_exception=ValueError(
|
63
|
-
"Signatures and sample_input_data both cannot be specified at the same time."
|
64
|
-
),
|
65
|
-
)
|
66
|
-
|
67
61
|
if not options:
|
68
62
|
options = model_types.BaseModelSaveOption()
|
69
63
|
|
64
|
+
# here handling the case of enable_explainability is False/None
|
65
|
+
enable_explainability = options.get("enable_explainability", None)
|
66
|
+
if enable_explainability is False or enable_explainability is None:
|
67
|
+
if (signatures is not None) and (sample_input_data is not None):
|
68
|
+
raise snowml_exceptions.SnowflakeMLException(
|
69
|
+
error_code=error_codes.INVALID_ARGUMENT,
|
70
|
+
original_exception=ValueError(
|
71
|
+
"Signatures and sample_input_data both cannot be specified at the same time."
|
72
|
+
),
|
73
|
+
)
|
74
|
+
|
70
75
|
handler = model_handler.find_handler(model)
|
71
76
|
if handler is None:
|
72
77
|
raise snowml_exceptions.SnowflakeMLException(
|
@@ -84,6 +89,7 @@ class ModelPackager:
|
|
84
89
|
conda_dependencies=conda_dependencies,
|
85
90
|
pip_requirements=pip_requirements,
|
86
91
|
python_version=python_version,
|
92
|
+
task=task,
|
87
93
|
**options,
|
88
94
|
) as meta:
|
89
95
|
model_blobs_path = os.path.join(self.local_dir_path, ModelPackager.MODEL_BLOBS_DIR)
|
@@ -36,6 +36,7 @@ class ModelRuntime:
|
|
36
36
|
name: str,
|
37
37
|
env: model_env.ModelEnv,
|
38
38
|
imports: Optional[List[str]] = None,
|
39
|
+
is_warehouse: bool = False,
|
39
40
|
is_gpu: bool = False,
|
40
41
|
loading_from_file: bool = False,
|
41
42
|
) -> None:
|
@@ -60,6 +61,16 @@ class ModelRuntime:
|
|
60
61
|
],
|
61
62
|
)
|
62
63
|
|
64
|
+
if not is_warehouse and self.embed_local_ml_library:
|
65
|
+
self.runtime_env.include_if_absent(
|
66
|
+
[
|
67
|
+
model_env.ModelDependency(
|
68
|
+
requirement="pyarrow",
|
69
|
+
pip_name="pyarrow",
|
70
|
+
)
|
71
|
+
],
|
72
|
+
)
|
73
|
+
|
63
74
|
if is_gpu:
|
64
75
|
self.runtime_env.generate_env_for_cuda()
|
65
76
|
|
@@ -30,7 +30,7 @@ class SeqOfPyTorchTensorHandler(base_handler.BaseDataHandler[Sequence["torch.Ten
|
|
30
30
|
|
31
31
|
@staticmethod
|
32
32
|
def count(data: Sequence["torch.Tensor"]) -> int:
|
33
|
-
return min(data_col.shape[0] for data_col in data)
|
33
|
+
return min(data_col.shape[0] for data_col in data) # type: ignore[no-any-return]
|
34
34
|
|
35
35
|
@staticmethod
|
36
36
|
def truncate(data: Sequence["torch.Tensor"]) -> Sequence["torch.Tensor"]:
|
@@ -14,9 +14,10 @@ from snowflake.ml._internal.exceptions import (
|
|
14
14
|
)
|
15
15
|
from snowflake.ml._internal.utils import identifier
|
16
16
|
from snowflake.ml.model import type_hints as model_types
|
17
|
-
from snowflake.ml.model._deploy_client.warehouse import infer_template
|
18
17
|
from snowflake.ml.model._signatures import base_handler, core, pandas_handler
|
19
18
|
|
19
|
+
_KEEP_ORDER_COL_NAME = "_ID"
|
20
|
+
|
20
21
|
|
21
22
|
class SnowparkDataFrameHandler(base_handler.BaseDataHandler[snowflake.snowpark.DataFrame]):
|
22
23
|
@staticmethod
|
@@ -109,7 +110,7 @@ class SnowparkDataFrameHandler(base_handler.BaseDataHandler[snowflake.snowpark.D
|
|
109
110
|
# Role will be no effect on the column index. That is to say, the feature name is the actual column name.
|
110
111
|
if keep_order:
|
111
112
|
df = df.reset_index(drop=True)
|
112
|
-
df[
|
113
|
+
df[_KEEP_ORDER_COL_NAME] = df.index
|
113
114
|
sp_df = session.create_dataframe(df)
|
114
115
|
column_names = []
|
115
116
|
columns = []
|
@@ -110,6 +110,15 @@ def huggingface_pipeline_signature_auto_infer(task: str, params: Dict[str, Any])
|
|
110
110
|
# https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.ConversationalPipeline
|
111
111
|
# Needs to convert to conversation object.
|
112
112
|
if task == "conversational":
|
113
|
+
warnings.warn(
|
114
|
+
(
|
115
|
+
"Conversational pipeline is removed from transformers since 4.42.0. "
|
116
|
+
"Support will be removed from snowflake-ml-python soon."
|
117
|
+
),
|
118
|
+
category=DeprecationWarning,
|
119
|
+
stacklevel=1,
|
120
|
+
)
|
121
|
+
|
113
122
|
return core.ModelSignature(
|
114
123
|
inputs=[
|
115
124
|
core.FeatureSpec(name="user_inputs", dtype=core.DataType.STRING, shape=(-1,)),
|
snowflake/ml/model/type_hints.py
CHANGED
@@ -1,22 +1,9 @@
|
|
1
1
|
# mypy: disable-error-code="import"
|
2
|
-
from
|
3
|
-
|
4
|
-
Any,
|
5
|
-
Dict,
|
6
|
-
List,
|
7
|
-
Literal,
|
8
|
-
Optional,
|
9
|
-
Sequence,
|
10
|
-
TypedDict,
|
11
|
-
TypeVar,
|
12
|
-
Union,
|
13
|
-
)
|
2
|
+
from enum import Enum
|
3
|
+
from typing import TYPE_CHECKING, Dict, Literal, Sequence, TypedDict, TypeVar, Union
|
14
4
|
|
15
5
|
import numpy.typing as npt
|
16
|
-
from typing_extensions import NotRequired
|
17
|
-
|
18
|
-
from snowflake.ml.model import deploy_platforms
|
19
|
-
from snowflake.ml.model._signatures import core
|
6
|
+
from typing_extensions import NotRequired
|
20
7
|
|
21
8
|
if TYPE_CHECKING:
|
22
9
|
import catboost
|
@@ -34,7 +21,6 @@ if TYPE_CHECKING:
|
|
34
21
|
|
35
22
|
import snowflake.ml.model.custom_model
|
36
23
|
import snowflake.ml.model.models.huggingface_pipeline
|
37
|
-
import snowflake.ml.model.models.llm
|
38
24
|
import snowflake.snowpark
|
39
25
|
from snowflake.ml.modeling.framework import base # noqa: F401
|
40
26
|
|
@@ -90,7 +76,6 @@ SupportedNoSignatureRequirementsModelType = Union[
|
|
90
76
|
"transformers.Pipeline",
|
91
77
|
"sentence_transformers.SentenceTransformer",
|
92
78
|
"snowflake.ml.model.models.huggingface_pipeline.HuggingFacePipelineModel",
|
93
|
-
"snowflake.ml.model.models.llm.LLM",
|
94
79
|
]
|
95
80
|
|
96
81
|
SupportedModelType = Union[
|
@@ -133,86 +118,11 @@ SupportedModelHandlerType = Literal[
|
|
133
118
|
"tensorflow",
|
134
119
|
"torchscript",
|
135
120
|
"xgboost",
|
136
|
-
"llm",
|
137
121
|
]
|
138
122
|
|
139
123
|
_ModelType = TypeVar("_ModelType", bound=SupportedModelType)
|
140
124
|
|
141
125
|
|
142
|
-
class DeployOptions(TypedDict):
|
143
|
-
"""Common Options for deploying to Snowflake."""
|
144
|
-
|
145
|
-
...
|
146
|
-
|
147
|
-
|
148
|
-
class WarehouseDeployOptions(DeployOptions):
|
149
|
-
"""Options for deploying to the Snowflake Warehouse.
|
150
|
-
|
151
|
-
|
152
|
-
permanent_udf_stage_location: A Snowflake stage option where the UDF should be persisted. If specified, the model
|
153
|
-
will be deployed as a permanent UDF, otherwise temporary.
|
154
|
-
relax_version: Whether or not relax the version constraints of the dependencies if unresolvable. It detects any
|
155
|
-
==x.y.z in specifiers and replaced with >=x.y, <(x+1). Defaults to False.
|
156
|
-
replace_udf: Flag to indicate when deploying model as permanent UDF, whether overwriting existed UDF is allowed.
|
157
|
-
Default to False.
|
158
|
-
"""
|
159
|
-
|
160
|
-
permanent_udf_stage_location: NotRequired[str]
|
161
|
-
relax_version: NotRequired[bool]
|
162
|
-
replace_udf: NotRequired[bool]
|
163
|
-
|
164
|
-
|
165
|
-
class SnowparkContainerServiceDeployOptions(DeployOptions):
|
166
|
-
"""Deployment options for deploying to SnowService.
|
167
|
-
When type hint is updated, please ensure the concrete class is updated accordingly at:
|
168
|
-
//snowflake/ml/model/_deploy_client/snowservice/_deploy_options
|
169
|
-
|
170
|
-
compute_pool[REQUIRED]: SnowService compute pool name. Please refer to official doc for how to create a
|
171
|
-
compute pool: https://docs.snowflake.com/LIMITEDACCESS/snowpark-containers/reference/compute-pool
|
172
|
-
image_repo: SnowService image repo path. e.g. "<image_registry>/<db>/<schema>/<repo>". Default to auto
|
173
|
-
inferred based on session information.
|
174
|
-
min_instances: Minimum number of service replicas. Default to 1.
|
175
|
-
max_instances: Maximum number of service replicas. Default to 1.
|
176
|
-
prebuilt_snowflake_image: When provided, the image-building step is skipped, and the pre-built image from
|
177
|
-
Snowflake is used as is. This option is for users who consistently use the same image for multiple use
|
178
|
-
cases, allowing faster deployment. The snowflake image used for deployment is logged to the console for
|
179
|
-
future use. Default to None.
|
180
|
-
num_gpus: Number of GPUs to be used for the service. Default to 0.
|
181
|
-
num_workers: Number of workers used for model inference. Please ensure that the number of workers is set lower than
|
182
|
-
the total available memory divided by the size of model to prevent memory-related issues. Default is number of
|
183
|
-
CPU cores * 2 + 1.
|
184
|
-
enable_remote_image_build: When set to True, will enable image build on a remote SnowService job. Default is True.
|
185
|
-
force_image_build: When set to True, an image rebuild will occur. The default is False, which means the system
|
186
|
-
will automatically check whether a previously built image can be reused
|
187
|
-
model_in_image: When set to True, image would container full model weights. The default if False, which
|
188
|
-
means image without model weights and we do stage mount to access weights.
|
189
|
-
debug_mode: When set to True, deployment artifacts will be persisted in a local temp directory.
|
190
|
-
enable_ingress: When set to True, will expose HTTP endpoint for access to the predict method of the created
|
191
|
-
service.
|
192
|
-
external_access_integrations: External Access Integrations name used to build image and deploy the model.
|
193
|
-
Please refer to the doc for how to create an External Access Integrations: https://docs.snowflake.com/
|
194
|
-
developer-guide/snowpark-container-services/additional-considerations-services-jobs
|
195
|
-
#configuring-network-capabilities .
|
196
|
-
To make sure your image could be built, access to the following endpoint must be allowed.
|
197
|
-
docker.com:80, docker.com:443, anaconda.com:80, anaconda.com:443, anaconda.org:80, anaconda.org:443,
|
198
|
-
pypi.org:80, pypi.org:443
|
199
|
-
"""
|
200
|
-
|
201
|
-
compute_pool: str
|
202
|
-
image_repo: NotRequired[str]
|
203
|
-
min_instances: NotRequired[int]
|
204
|
-
max_instances: NotRequired[int]
|
205
|
-
prebuilt_snowflake_image: NotRequired[str]
|
206
|
-
num_gpus: NotRequired[int]
|
207
|
-
num_workers: NotRequired[int]
|
208
|
-
enable_remote_image_build: NotRequired[bool]
|
209
|
-
force_image_build: NotRequired[bool]
|
210
|
-
model_in_image: NotRequired[bool]
|
211
|
-
debug_mode: NotRequired[bool]
|
212
|
-
enable_ingress: NotRequired[bool]
|
213
|
-
external_access_integrations: List[str]
|
214
|
-
|
215
|
-
|
216
126
|
class ModelMethodSaveOptions(TypedDict):
|
217
127
|
case_sensitive: NotRequired[bool]
|
218
128
|
max_batch_size: NotRequired[int]
|
@@ -223,16 +133,14 @@ class BaseModelSaveOption(TypedDict):
|
|
223
133
|
"""Options for saving the model.
|
224
134
|
|
225
135
|
embed_local_ml_library: Embedding local SnowML into the code directory of the folder.
|
226
|
-
relax_version: Whether or not relax the version constraints of the dependencies if unresolvable
|
227
|
-
==x.y.z in specifiers and replaced with >=x.y, <(x+1). Defaults to
|
136
|
+
relax_version: Whether or not relax the version constraints of the dependencies if unresolvable in Warehouse.
|
137
|
+
It detects any ==x.y.z in specifiers and replaced with >=x.y, <(x+1). Defaults to True.
|
228
138
|
"""
|
229
139
|
|
230
140
|
embed_local_ml_library: NotRequired[bool]
|
231
141
|
relax_version: NotRequired[bool]
|
232
|
-
_legacy_save: NotRequired[bool]
|
233
142
|
function_type: NotRequired[Literal["FUNCTION", "TABLE_FUNCTION"]]
|
234
143
|
method_options: NotRequired[Dict[str, ModelMethodSaveOptions]]
|
235
|
-
include_pip_dependencies: NotRequired[bool]
|
236
144
|
enable_explainability: NotRequired[bool]
|
237
145
|
|
238
146
|
|
@@ -293,10 +201,6 @@ class SentenceTransformersSaveOptions(BaseModelSaveOption):
|
|
293
201
|
cuda_version: NotRequired[str]
|
294
202
|
|
295
203
|
|
296
|
-
class LLMSaveOptions(BaseModelSaveOption):
|
297
|
-
cuda_version: NotRequired[str]
|
298
|
-
|
299
|
-
|
300
204
|
ModelSaveOption = Union[
|
301
205
|
BaseModelSaveOption,
|
302
206
|
CatBoostModelSaveOptions,
|
@@ -311,7 +215,6 @@ ModelSaveOption = Union[
|
|
311
215
|
MLFlowSaveOptions,
|
312
216
|
HuggingFaceSaveOptions,
|
313
217
|
SentenceTransformersSaveOptions,
|
314
|
-
LLMSaveOptions,
|
315
218
|
]
|
316
219
|
|
317
220
|
|
@@ -369,10 +272,7 @@ class HuggingFaceLoadOptions(BaseModelLoadOption):
|
|
369
272
|
|
370
273
|
class SentenceTransformersLoadOptions(BaseModelLoadOption):
|
371
274
|
use_gpu: NotRequired[bool]
|
372
|
-
|
373
|
-
|
374
|
-
class LLMLoadOptions(BaseModelLoadOption):
|
375
|
-
...
|
275
|
+
device: NotRequired[str]
|
376
276
|
|
377
277
|
|
378
278
|
ModelLoadOption = Union[
|
@@ -389,45 +289,12 @@ ModelLoadOption = Union[
|
|
389
289
|
MLFlowLoadOptions,
|
390
290
|
HuggingFaceLoadOptions,
|
391
291
|
SentenceTransformersLoadOptions,
|
392
|
-
LLMLoadOptions,
|
393
292
|
]
|
394
293
|
|
395
294
|
|
396
|
-
class
|
397
|
-
""
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
""
|
402
|
-
|
403
|
-
service_info: Optional[Dict[str, Any]]
|
404
|
-
service_function_sql: str
|
405
|
-
|
406
|
-
|
407
|
-
class WarehouseDeployDetails(TypedDict):
|
408
|
-
...
|
409
|
-
|
410
|
-
|
411
|
-
DeployDetails = Union[
|
412
|
-
SnowparkContainerServiceDeployDetails,
|
413
|
-
WarehouseDeployDetails,
|
414
|
-
]
|
415
|
-
|
416
|
-
|
417
|
-
class Deployment(TypedDict):
|
418
|
-
"""Deployment information.
|
419
|
-
|
420
|
-
Attributes:
|
421
|
-
name: Name of the deployment.
|
422
|
-
platform: Target platform to deploy the model.
|
423
|
-
target_method: Target method name.
|
424
|
-
signature: The signature of the model method.
|
425
|
-
options: Additional options when deploying the model.
|
426
|
-
"""
|
427
|
-
|
428
|
-
name: Required[str]
|
429
|
-
platform: Required[deploy_platforms.TargetPlatform]
|
430
|
-
target_method: Required[str]
|
431
|
-
signature: core.ModelSignature
|
432
|
-
options: Required[DeployOptions]
|
433
|
-
details: NotRequired[DeployDetails]
|
295
|
+
class Task(Enum):
|
296
|
+
UNKNOWN = "UNKNOWN"
|
297
|
+
TABULAR_BINARY_CLASSIFICATION = "TABULAR_BINARY_CLASSIFICATION"
|
298
|
+
TABULAR_MULTI_CLASSIFICATION = "TABULAR_MULTI_CLASSIFICATION"
|
299
|
+
TABULAR_REGRESSION = "TABULAR_REGRESSION"
|
300
|
+
TABULAR_RANKING = "TABULAR_RANKING"
|
@@ -166,10 +166,10 @@ class PandasTransformHandlers:
|
|
166
166
|
SnowflakeMLException: The input column list does not have one of `X` and `X_test`.
|
167
167
|
"""
|
168
168
|
assert hasattr(self.estimator, "score") # make type checker happy
|
169
|
-
|
170
|
-
if "X" in
|
169
|
+
params = inspect.signature(self.estimator.score).parameters
|
170
|
+
if "X" in params:
|
171
171
|
score_args = {"X": self.dataset[input_cols]}
|
172
|
-
elif "X_test" in
|
172
|
+
elif "X_test" in params:
|
173
173
|
score_args = {"X_test": self.dataset[input_cols]}
|
174
174
|
else:
|
175
175
|
raise exceptions.SnowflakeMLException(
|
@@ -178,10 +178,10 @@ class PandasTransformHandlers:
|
|
178
178
|
)
|
179
179
|
|
180
180
|
if len(label_cols) > 0:
|
181
|
-
label_arg_name = "Y" if "Y" in
|
181
|
+
label_arg_name = "Y" if "Y" in params else "y"
|
182
182
|
score_args[label_arg_name] = self.dataset[label_cols].squeeze()
|
183
183
|
|
184
|
-
if sample_weight_col is not None and "sample_weight" in
|
184
|
+
if sample_weight_col is not None and "sample_weight" in params:
|
185
185
|
score_args["sample_weight"] = self.dataset[sample_weight_col].squeeze()
|
186
186
|
|
187
187
|
score = self.estimator.score(**score_args)
|
@@ -43,14 +43,14 @@ class PandasModelTrainer:
|
|
43
43
|
Trained model
|
44
44
|
"""
|
45
45
|
assert hasattr(self.estimator, "fit") # Keep mypy happy
|
46
|
-
|
46
|
+
params = inspect.signature(self.estimator.fit).parameters
|
47
47
|
args = {"X": self.dataset[self.input_cols]}
|
48
48
|
|
49
49
|
if self.label_cols:
|
50
|
-
label_arg_name = "Y" if "Y" in
|
50
|
+
label_arg_name = "Y" if "Y" in params else "y"
|
51
51
|
args[label_arg_name] = self.dataset[self.label_cols].squeeze()
|
52
52
|
|
53
|
-
if self.sample_weight_col is not None and "sample_weight" in
|
53
|
+
if self.sample_weight_col is not None and "sample_weight" in params:
|
54
54
|
args["sample_weight"] = self.dataset[self.sample_weight_col].squeeze()
|
55
55
|
|
56
56
|
return self.estimator.fit(**args)
|
@@ -59,6 +59,7 @@ class PandasModelTrainer:
|
|
59
59
|
self,
|
60
60
|
expected_output_cols_list: List[str],
|
61
61
|
drop_input_cols: Optional[bool] = False,
|
62
|
+
example_output_pd_df: Optional[pd.DataFrame] = None,
|
62
63
|
) -> Tuple[pd.DataFrame, object]:
|
63
64
|
"""Trains the model using specified features and target columns from the dataset.
|
64
65
|
This API is different from fit itself because it would also provide the predict
|
@@ -69,6 +70,8 @@ class PandasModelTrainer:
|
|
69
70
|
name as a list. Defaults to None.
|
70
71
|
drop_input_cols (Optional[bool]): Boolean to determine whether to
|
71
72
|
drop the input columns from the output dataset.
|
73
|
+
example_output_pd_df (Optional[pd.DataFrame]): Example output dataframe
|
74
|
+
This is not used in PandasModelTrainer. It is used in SnowparkModelTrainer.
|
72
75
|
|
73
76
|
Returns:
|
74
77
|
Tuple[pd.DataFrame, object]: [predicted dataset, estimator]
|
@@ -108,13 +111,13 @@ class PandasModelTrainer:
|
|
108
111
|
assert hasattr(self.estimator, "fit") # make type checker happy
|
109
112
|
assert hasattr(self.estimator, "fit_transform") # make type checker happy
|
110
113
|
|
111
|
-
|
114
|
+
params = inspect.signature(self.estimator.fit).parameters
|
112
115
|
args = {"X": self.dataset[self.input_cols]}
|
113
116
|
if self.label_cols:
|
114
|
-
label_arg_name = "Y" if "Y" in
|
117
|
+
label_arg_name = "Y" if "Y" in params else "y"
|
115
118
|
args[label_arg_name] = self.dataset[self.label_cols].squeeze()
|
116
119
|
|
117
|
-
if self.sample_weight_col is not None and "sample_weight" in
|
120
|
+
if self.sample_weight_col is not None and "sample_weight" in params:
|
118
121
|
args["sample_weight"] = self.dataset[self.sample_weight_col].squeeze()
|
119
122
|
|
120
123
|
inference_res = self.estimator.fit_transform(**args)
|
@@ -53,11 +53,13 @@ class SKLearnModelSpecifications(ModelSpecifications):
|
|
53
53
|
|
54
54
|
class XGBoostModelSpecifications(ModelSpecifications):
|
55
55
|
def __init__(self) -> None:
|
56
|
+
import sklearn
|
56
57
|
import xgboost
|
57
58
|
|
58
59
|
imports: List[str] = ["xgboost"]
|
59
60
|
pkgDependencies: List[str] = [
|
60
61
|
f"numpy=={np.__version__}",
|
62
|
+
f"scikit-learn=={sklearn.__version__}",
|
61
63
|
f"xgboost=={xgboost.__version__}",
|
62
64
|
f"cloudpickle=={cp.__version__}",
|
63
65
|
]
|