snowflake-ml-python 1.0.1__py3-none-any.whl → 1.0.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/ml/_internal/env_utils.py +2 -1
- snowflake/ml/_internal/file_utils.py +35 -40
- snowflake/ml/_internal/telemetry.py +5 -8
- snowflake/ml/_internal/utils/identifier.py +74 -7
- snowflake/ml/_internal/utils/uri.py +7 -2
- snowflake/ml/model/_core_requirements.py +1 -1
- snowflake/ml/model/_deploy_client/image_builds/base_image_builder.py +15 -0
- snowflake/ml/model/_deploy_client/image_builds/client_image_builder.py +259 -0
- snowflake/ml/model/_deploy_client/image_builds/docker_context.py +89 -0
- snowflake/ml/model/_deploy_client/image_builds/gunicorn_run.sh +24 -0
- snowflake/ml/model/_deploy_client/image_builds/inference_server/main.py +118 -0
- snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +40 -0
- snowflake/ml/model/_deploy_client/snowservice/deploy.py +199 -0
- snowflake/ml/model/_deploy_client/snowservice/deploy_options.py +88 -0
- snowflake/ml/model/_deploy_client/snowservice/templates/service_spec_template +24 -0
- snowflake/ml/model/_deploy_client/utils/constants.py +47 -0
- snowflake/ml/model/_deploy_client/utils/snowservice_client.py +178 -0
- snowflake/ml/model/_deploy_client/warehouse/deploy.py +25 -28
- snowflake/ml/model/_deploy_client/warehouse/infer_template.py +7 -4
- snowflake/ml/model/_deployer.py +14 -27
- snowflake/ml/model/_env.py +4 -4
- snowflake/ml/model/_handlers/_base.py +3 -1
- snowflake/ml/model/_handlers/custom.py +14 -2
- snowflake/ml/model/_handlers/pytorch.py +186 -0
- snowflake/ml/model/_handlers/sklearn.py +14 -8
- snowflake/ml/model/_handlers/snowmlmodel.py +14 -9
- snowflake/ml/model/_handlers/torchscript.py +180 -0
- snowflake/ml/model/_handlers/xgboost.py +19 -9
- snowflake/ml/model/_model.py +27 -21
- snowflake/ml/model/_model_meta.py +33 -19
- snowflake/ml/model/model_signature.py +446 -66
- snowflake/ml/model/type_hints.py +28 -15
- snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +79 -43
- snowflake/ml/modeling/cluster/affinity_propagation.py +79 -43
- snowflake/ml/modeling/cluster/agglomerative_clustering.py +79 -43
- snowflake/ml/modeling/cluster/birch.py +79 -43
- snowflake/ml/modeling/cluster/bisecting_k_means.py +79 -43
- snowflake/ml/modeling/cluster/dbscan.py +79 -43
- snowflake/ml/modeling/cluster/feature_agglomeration.py +79 -43
- snowflake/ml/modeling/cluster/k_means.py +79 -43
- snowflake/ml/modeling/cluster/mean_shift.py +79 -43
- snowflake/ml/modeling/cluster/mini_batch_k_means.py +79 -43
- snowflake/ml/modeling/cluster/optics.py +79 -43
- snowflake/ml/modeling/cluster/spectral_biclustering.py +79 -43
- snowflake/ml/modeling/cluster/spectral_clustering.py +79 -43
- snowflake/ml/modeling/cluster/spectral_coclustering.py +79 -43
- snowflake/ml/modeling/compose/column_transformer.py +79 -43
- snowflake/ml/modeling/compose/transformed_target_regressor.py +79 -43
- snowflake/ml/modeling/covariance/elliptic_envelope.py +79 -43
- snowflake/ml/modeling/covariance/empirical_covariance.py +79 -43
- snowflake/ml/modeling/covariance/graphical_lasso.py +79 -43
- snowflake/ml/modeling/covariance/graphical_lasso_cv.py +79 -43
- snowflake/ml/modeling/covariance/ledoit_wolf.py +79 -43
- snowflake/ml/modeling/covariance/min_cov_det.py +79 -43
- snowflake/ml/modeling/covariance/oas.py +79 -43
- snowflake/ml/modeling/covariance/shrunk_covariance.py +79 -43
- snowflake/ml/modeling/decomposition/dictionary_learning.py +79 -43
- snowflake/ml/modeling/decomposition/factor_analysis.py +79 -43
- snowflake/ml/modeling/decomposition/fast_ica.py +79 -43
- snowflake/ml/modeling/decomposition/incremental_pca.py +79 -43
- snowflake/ml/modeling/decomposition/kernel_pca.py +79 -43
- snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +79 -43
- snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +79 -43
- snowflake/ml/modeling/decomposition/pca.py +79 -43
- snowflake/ml/modeling/decomposition/sparse_pca.py +79 -43
- snowflake/ml/modeling/decomposition/truncated_svd.py +79 -43
- snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +79 -43
- snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +79 -43
- snowflake/ml/modeling/ensemble/ada_boost_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/ada_boost_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/bagging_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/bagging_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/extra_trees_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/extra_trees_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/isolation_forest.py +79 -43
- snowflake/ml/modeling/ensemble/random_forest_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/random_forest_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/stacking_regressor.py +79 -43
- snowflake/ml/modeling/ensemble/voting_classifier.py +79 -43
- snowflake/ml/modeling/ensemble/voting_regressor.py +79 -43
- snowflake/ml/modeling/feature_selection/generic_univariate_select.py +79 -43
- snowflake/ml/modeling/feature_selection/select_fdr.py +79 -43
- snowflake/ml/modeling/feature_selection/select_fpr.py +79 -43
- snowflake/ml/modeling/feature_selection/select_fwe.py +79 -43
- snowflake/ml/modeling/feature_selection/select_k_best.py +79 -43
- snowflake/ml/modeling/feature_selection/select_percentile.py +79 -43
- snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +79 -43
- snowflake/ml/modeling/feature_selection/variance_threshold.py +79 -43
- snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +79 -43
- snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +79 -43
- snowflake/ml/modeling/impute/iterative_imputer.py +79 -43
- snowflake/ml/modeling/impute/knn_imputer.py +79 -43
- snowflake/ml/modeling/impute/missing_indicator.py +79 -43
- snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +79 -43
- snowflake/ml/modeling/kernel_approximation/nystroem.py +79 -43
- snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +79 -43
- snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +79 -43
- snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +79 -43
- snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +79 -43
- snowflake/ml/modeling/lightgbm/lgbm_classifier.py +79 -43
- snowflake/ml/modeling/lightgbm/lgbm_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/ard_regression.py +79 -43
- snowflake/ml/modeling/linear_model/bayesian_ridge.py +79 -43
- snowflake/ml/modeling/linear_model/elastic_net.py +79 -43
- snowflake/ml/modeling/linear_model/elastic_net_cv.py +79 -43
- snowflake/ml/modeling/linear_model/gamma_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/huber_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/lars.py +79 -43
- snowflake/ml/modeling/linear_model/lars_cv.py +79 -43
- snowflake/ml/modeling/linear_model/lasso.py +79 -43
- snowflake/ml/modeling/linear_model/lasso_cv.py +79 -43
- snowflake/ml/modeling/linear_model/lasso_lars.py +79 -43
- snowflake/ml/modeling/linear_model/lasso_lars_cv.py +79 -43
- snowflake/ml/modeling/linear_model/lasso_lars_ic.py +79 -43
- snowflake/ml/modeling/linear_model/linear_regression.py +79 -43
- snowflake/ml/modeling/linear_model/logistic_regression.py +79 -43
- snowflake/ml/modeling/linear_model/logistic_regression_cv.py +79 -43
- snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +79 -43
- snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +79 -43
- snowflake/ml/modeling/linear_model/multi_task_lasso.py +79 -43
- snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +79 -43
- snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +79 -43
- snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +79 -43
- snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/perceptron.py +79 -43
- snowflake/ml/modeling/linear_model/poisson_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/ransac_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/ridge.py +79 -43
- snowflake/ml/modeling/linear_model/ridge_classifier.py +79 -43
- snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +79 -43
- snowflake/ml/modeling/linear_model/ridge_cv.py +79 -43
- snowflake/ml/modeling/linear_model/sgd_classifier.py +79 -43
- snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +79 -43
- snowflake/ml/modeling/linear_model/sgd_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/theil_sen_regressor.py +79 -43
- snowflake/ml/modeling/linear_model/tweedie_regressor.py +79 -43
- snowflake/ml/modeling/manifold/isomap.py +79 -43
- snowflake/ml/modeling/manifold/mds.py +79 -43
- snowflake/ml/modeling/manifold/spectral_embedding.py +79 -43
- snowflake/ml/modeling/manifold/tsne.py +79 -43
- snowflake/ml/modeling/metrics/classification.py +6 -1
- snowflake/ml/modeling/metrics/regression.py +517 -9
- snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +79 -43
- snowflake/ml/modeling/mixture/gaussian_mixture.py +79 -43
- snowflake/ml/modeling/model_selection/grid_search_cv.py +79 -43
- snowflake/ml/modeling/model_selection/randomized_search_cv.py +79 -43
- snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +79 -43
- snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +79 -43
- snowflake/ml/modeling/multiclass/output_code_classifier.py +79 -43
- snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +79 -43
- snowflake/ml/modeling/naive_bayes/categorical_nb.py +79 -43
- snowflake/ml/modeling/naive_bayes/complement_nb.py +79 -43
- snowflake/ml/modeling/naive_bayes/gaussian_nb.py +79 -43
- snowflake/ml/modeling/naive_bayes/multinomial_nb.py +79 -43
- snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +79 -43
- snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +79 -43
- snowflake/ml/modeling/neighbors/kernel_density.py +79 -43
- snowflake/ml/modeling/neighbors/local_outlier_factor.py +79 -43
- snowflake/ml/modeling/neighbors/nearest_centroid.py +79 -43
- snowflake/ml/modeling/neighbors/nearest_neighbors.py +79 -43
- snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +79 -43
- snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +79 -43
- snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +79 -43
- snowflake/ml/modeling/neural_network/bernoulli_rbm.py +79 -43
- snowflake/ml/modeling/neural_network/mlp_classifier.py +79 -43
- snowflake/ml/modeling/neural_network/mlp_regressor.py +79 -43
- snowflake/ml/modeling/pipeline/pipeline.py +24 -0
- snowflake/ml/modeling/preprocessing/one_hot_encoder.py +18 -19
- snowflake/ml/modeling/preprocessing/ordinal_encoder.py +2 -0
- snowflake/ml/modeling/preprocessing/polynomial_features.py +79 -43
- snowflake/ml/modeling/semi_supervised/label_propagation.py +79 -43
- snowflake/ml/modeling/semi_supervised/label_spreading.py +79 -43
- snowflake/ml/modeling/svm/linear_svc.py +79 -43
- snowflake/ml/modeling/svm/linear_svr.py +79 -43
- snowflake/ml/modeling/svm/nu_svc.py +79 -43
- snowflake/ml/modeling/svm/nu_svr.py +79 -43
- snowflake/ml/modeling/svm/svc.py +79 -43
- snowflake/ml/modeling/svm/svr.py +79 -43
- snowflake/ml/modeling/tree/decision_tree_classifier.py +79 -43
- snowflake/ml/modeling/tree/decision_tree_regressor.py +79 -43
- snowflake/ml/modeling/tree/extra_tree_classifier.py +79 -43
- snowflake/ml/modeling/tree/extra_tree_regressor.py +79 -43
- snowflake/ml/modeling/xgboost/xgb_classifier.py +79 -43
- snowflake/ml/modeling/xgboost/xgb_regressor.py +79 -43
- snowflake/ml/modeling/xgboost/xgbrf_classifier.py +79 -43
- snowflake/ml/modeling/xgboost/xgbrf_regressor.py +79 -43
- snowflake/ml/registry/model_registry.py +123 -121
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.0.1.dist-info → snowflake_ml_python-1.0.3.dist-info}/METADATA +50 -8
- snowflake_ml_python-1.0.3.dist-info/RECORD +259 -0
- snowflake_ml_python-1.0.1.dist-info/RECORD +0 -246
- {snowflake_ml_python-1.0.1.dist-info → snowflake_ml_python-1.0.3.dist-info}/WHEEL +0 -0
@@ -1,12 +1,13 @@
|
|
1
1
|
import dataclasses
|
2
|
+
import importlib
|
2
3
|
import os
|
3
4
|
import sys
|
4
5
|
import warnings
|
6
|
+
from collections import namedtuple
|
5
7
|
from contextlib import contextmanager
|
6
8
|
from datetime import datetime
|
7
|
-
from pathlib import Path
|
8
9
|
from types import ModuleType
|
9
|
-
from typing import Any, Callable, Dict, Generator, List, Optional, Sequence,
|
10
|
+
from typing import Any, Callable, Dict, Generator, List, Optional, Sequence, cast
|
10
11
|
|
11
12
|
import cloudpickle
|
12
13
|
import yaml
|
@@ -24,7 +25,7 @@ from snowflake.snowpark import DataFrame as SnowparkDataFrame
|
|
24
25
|
MODEL_METADATA_VERSION = 1
|
25
26
|
_BASIC_DEPENDENCIES = _core_requirements.REQUIREMENTS
|
26
27
|
|
27
|
-
|
28
|
+
Dependency = namedtuple("Dependency", ["conda_name", "pip_name"])
|
28
29
|
|
29
30
|
|
30
31
|
@dataclasses.dataclass
|
@@ -84,6 +85,10 @@ def _create_model_metadata(
|
|
84
85
|
A model metadata object.
|
85
86
|
"""
|
86
87
|
model_dir_path = os.path.normpath(model_dir_path)
|
88
|
+
embed_local_ml_library = kwargs.pop("embed_local_ml_library", False)
|
89
|
+
if embed_local_ml_library:
|
90
|
+
snowml_path = list(importlib.import_module("snowflake.ml").__path__)[0]
|
91
|
+
kwargs["local_ml_library_version"] = f"{snowml_env.VERSION}+{file_utils.hash_directory(snowml_path)}"
|
87
92
|
|
88
93
|
model_meta = ModelMetadata(
|
89
94
|
name=name,
|
@@ -100,6 +105,14 @@ def _create_model_metadata(
|
|
100
105
|
os.makedirs(code_dir_path, exist_ok=True)
|
101
106
|
for code_path in code_paths:
|
102
107
|
file_utils.copy_file_or_tree(code_path, code_dir_path)
|
108
|
+
|
109
|
+
if embed_local_ml_library:
|
110
|
+
code_dir_path = os.path.join(model_dir_path, ModelMetadata.MODEL_CODE_DIR)
|
111
|
+
snowml_path = list(importlib.import_module("snowflake.ml").__path__)[0]
|
112
|
+
snowml_path_in_code = os.path.join(code_dir_path, "snowflake")
|
113
|
+
os.makedirs(snowml_path_in_code, exist_ok=True)
|
114
|
+
file_utils.copy_file_or_tree(snowml_path, snowml_path_in_code)
|
115
|
+
|
103
116
|
try:
|
104
117
|
imported_modules = []
|
105
118
|
if ext_modules:
|
@@ -117,8 +130,7 @@ def _create_model_metadata(
|
|
117
130
|
|
118
131
|
def _load_model_metadata(model_dir_path: str) -> "ModelMetadata":
|
119
132
|
"""Load models for a directory. Model is initially loaded normally. If additional codes are included when packed,
|
120
|
-
the code path is added to system path to be imported
|
121
|
-
been imported.
|
133
|
+
the code path is added to system path to be imported with highest priority.
|
122
134
|
|
123
135
|
Args:
|
124
136
|
model_dir_path: Path to the directory containing the model to be loaded.
|
@@ -131,14 +143,12 @@ def _load_model_metadata(model_dir_path: str) -> "ModelMetadata":
|
|
131
143
|
meta = ModelMetadata.load_model_metadata(model_dir_path)
|
132
144
|
code_path = os.path.join(model_dir_path, ModelMetadata.MODEL_CODE_DIR)
|
133
145
|
if os.path.exists(code_path):
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
if p.is_file() and p.name != "__init__.py" and p.name != "__main__.py"
|
139
|
-
]
|
146
|
+
if code_path in sys.path:
|
147
|
+
sys.path.remove(code_path)
|
148
|
+
sys.path.insert(0, code_path)
|
149
|
+
modules = file_utils.get_all_modules(code_path)
|
140
150
|
for module in modules:
|
141
|
-
sys.modules.pop(module, None)
|
151
|
+
sys.modules.pop(module.name, None)
|
142
152
|
return meta
|
143
153
|
|
144
154
|
|
@@ -206,8 +216,12 @@ class ModelMetadata:
|
|
206
216
|
self._pip_requirements = env_utils.validate_pip_requirement_string_list(
|
207
217
|
pip_requirements if pip_requirements else []
|
208
218
|
)
|
209
|
-
|
210
|
-
|
219
|
+
if "local_ml_library_version" in kwargs:
|
220
|
+
self._include_if_absent([Dependency(conda_name=dep, pip_name=dep) for dep in _BASIC_DEPENDENCIES])
|
221
|
+
else:
|
222
|
+
self._include_if_absent(
|
223
|
+
[Dependency(conda_name=dep, pip_name=dep) for dep in _BASIC_DEPENDENCIES + [env_utils._SNOWML_PKG_NAME]]
|
224
|
+
)
|
211
225
|
|
212
226
|
self.__dict__.update(kwargs)
|
213
227
|
|
@@ -225,7 +239,7 @@ class ModelMetadata:
|
|
225
239
|
for req in reqs
|
226
240
|
)
|
227
241
|
|
228
|
-
def _include_if_absent(self, pkgs: List[
|
242
|
+
def _include_if_absent(self, pkgs: List[Dependency]) -> None:
|
229
243
|
conda_reqs_str, pip_reqs_str = tuple(zip(*pkgs))
|
230
244
|
pip_reqs = env_utils.validate_pip_requirement_string_list(list(pip_reqs_str))
|
231
245
|
conda_reqs = env_utils.validate_conda_dependency_string_list(list(conda_reqs_str))
|
@@ -318,7 +332,7 @@ class ModelMetadata:
|
|
318
332
|
path: The path of the directory to write a yaml file in it.
|
319
333
|
"""
|
320
334
|
model_yaml_path = os.path.join(path, ModelMetadata.MODEL_METADATA_FILE)
|
321
|
-
with open(model_yaml_path, "w") as out:
|
335
|
+
with open(model_yaml_path, "w", encoding="utf-8") as out:
|
322
336
|
yaml.safe_dump({**self.to_dict(), "version": MODEL_METADATA_VERSION}, stream=out, default_flow_style=False)
|
323
337
|
|
324
338
|
env_dir_path = os.path.join(path, ModelMetadata.ENV_DIR)
|
@@ -341,10 +355,10 @@ class ModelMetadata:
|
|
341
355
|
Loaded model metadata object.
|
342
356
|
"""
|
343
357
|
model_yaml_path = os.path.join(path, ModelMetadata.MODEL_METADATA_FILE)
|
344
|
-
with open(model_yaml_path) as f:
|
358
|
+
with open(model_yaml_path, encoding="utf-8") as f:
|
345
359
|
loaded_mata = yaml.safe_load(f.read())
|
346
360
|
|
347
|
-
loaded_mata_version = loaded_mata.
|
361
|
+
loaded_mata_version = loaded_mata.pop("version", None)
|
348
362
|
if not loaded_mata_version or loaded_mata_version != MODEL_METADATA_VERSION:
|
349
363
|
raise NotImplementedError("Unknown or unsupported model metadata file found.")
|
350
364
|
|
@@ -383,7 +397,7 @@ def _validate_signature(
|
|
383
397
|
if isinstance(sample_input, SnowparkDataFrame):
|
384
398
|
# Added because of Any from missing stubs.
|
385
399
|
trunc_sample_input = cast(SnowparkDataFrame, trunc_sample_input)
|
386
|
-
local_sample_input =
|
400
|
+
local_sample_input = model_signature._SnowparkDataFrameHandler.convert_to_df(trunc_sample_input)
|
387
401
|
else:
|
388
402
|
local_sample_input = trunc_sample_input
|
389
403
|
for target_method in target_methods:
|