snowflake-ml-python 1.4.0__py3-none-any.whl → 1.5.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/_internal/env_utils.py +77 -32
- snowflake/ml/_internal/exceptions/dataset_error_messages.py +5 -0
- snowflake/ml/_internal/exceptions/dataset_errors.py +24 -0
- snowflake/ml/_internal/exceptions/error_codes.py +3 -0
- snowflake/ml/_internal/lineage/data_source.py +10 -0
- snowflake/ml/_internal/lineage/dataset_dataframe.py +44 -0
- snowflake/ml/_internal/utils/identifier.py +3 -1
- snowflake/ml/_internal/utils/sql_identifier.py +2 -6
- snowflake/ml/dataset/__init__.py +10 -0
- snowflake/ml/dataset/dataset.py +454 -129
- snowflake/ml/dataset/dataset_factory.py +53 -0
- snowflake/ml/dataset/dataset_metadata.py +103 -0
- snowflake/ml/dataset/dataset_reader.py +202 -0
- snowflake/ml/feature_store/feature_store.py +531 -332
- snowflake/ml/feature_store/feature_view.py +40 -23
- snowflake/ml/fileset/embedded_stage_fs.py +146 -0
- snowflake/ml/fileset/sfcfs.py +56 -54
- snowflake/ml/fileset/snowfs.py +159 -0
- snowflake/ml/fileset/stage_fs.py +49 -17
- snowflake/ml/model/__init__.py +2 -2
- snowflake/ml/model/_api.py +16 -1
- snowflake/ml/model/_client/model/model_impl.py +27 -0
- snowflake/ml/model/_client/model/model_version_impl.py +137 -50
- snowflake/ml/model/_client/ops/model_ops.py +159 -40
- snowflake/ml/model/_client/sql/model.py +25 -2
- snowflake/ml/model/_client/sql/model_version.py +131 -2
- snowflake/ml/model/_deploy_client/image_builds/server_image_builder.py +5 -1
- snowflake/ml/model/_deploy_client/image_builds/templates/dockerfile_template +1 -0
- snowflake/ml/model/_deploy_client/snowservice/deploy.py +2 -0
- snowflake/ml/model/_deploy_client/utils/constants.py +0 -5
- snowflake/ml/model/_deploy_client/utils/snowservice_client.py +21 -50
- snowflake/ml/model/_model_composer/model_composer.py +22 -1
- snowflake/ml/model/_model_composer/model_manifest/model_manifest.py +38 -51
- snowflake/ml/model/_model_composer/model_manifest/model_manifest_schema.py +19 -1
- snowflake/ml/model/_model_composer/model_method/model_method.py +6 -10
- snowflake/ml/model/_packager/model_env/model_env.py +41 -0
- snowflake/ml/model/_packager/model_handlers/catboost.py +206 -0
- snowflake/ml/model/_packager/model_handlers/lightgbm.py +218 -0
- snowflake/ml/model/_packager/model_handlers/sklearn.py +3 -0
- snowflake/ml/model/_packager/model_meta/_core_requirements.py +1 -1
- snowflake/ml/model/_packager/model_meta/model_meta.py +37 -11
- snowflake/ml/model/_packager/model_meta/model_meta_schema.py +20 -1
- snowflake/ml/model/_packager/model_meta_migrator/migrator_plans.py +3 -1
- snowflake/ml/model/_packager/model_packager.py +2 -5
- snowflake/ml/model/{_model_composer/model_runtime/_runtime_requirements.py → _packager/model_runtime/_snowml_inference_alternative_requirements.py} +1 -1
- snowflake/ml/model/_packager/model_runtime/model_runtime.py +137 -0
- snowflake/ml/model/type_hints.py +21 -2
- snowflake/ml/modeling/_internal/estimator_utils.py +16 -11
- snowflake/ml/modeling/_internal/local_implementations/pandas_handlers.py +4 -1
- snowflake/ml/modeling/_internal/local_implementations/pandas_trainer.py +55 -3
- snowflake/ml/modeling/_internal/ml_runtime_implementations/ml_runtime_handlers.py +34 -18
- snowflake/ml/modeling/_internal/model_trainer.py +7 -0
- snowflake/ml/modeling/_internal/model_trainer_builder.py +42 -9
- snowflake/ml/modeling/_internal/snowpark_implementations/distributed_hpo_trainer.py +13 -14
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_handlers.py +29 -7
- snowflake/ml/modeling/_internal/snowpark_implementations/snowpark_trainer.py +261 -16
- snowflake/ml/modeling/calibration/calibrated_classifier_cv.py +246 -175
- snowflake/ml/modeling/cluster/affinity_propagation.py +246 -175
- snowflake/ml/modeling/cluster/agglomerative_clustering.py +246 -175
- snowflake/ml/modeling/cluster/birch.py +248 -175
- snowflake/ml/modeling/cluster/bisecting_k_means.py +248 -175
- snowflake/ml/modeling/cluster/dbscan.py +246 -175
- snowflake/ml/modeling/cluster/feature_agglomeration.py +248 -175
- snowflake/ml/modeling/cluster/k_means.py +248 -175
- snowflake/ml/modeling/cluster/mean_shift.py +246 -175
- snowflake/ml/modeling/cluster/mini_batch_k_means.py +248 -175
- snowflake/ml/modeling/cluster/optics.py +246 -175
- snowflake/ml/modeling/cluster/spectral_biclustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_clustering.py +246 -175
- snowflake/ml/modeling/cluster/spectral_coclustering.py +246 -175
- snowflake/ml/modeling/compose/column_transformer.py +248 -175
- snowflake/ml/modeling/compose/transformed_target_regressor.py +246 -175
- snowflake/ml/modeling/covariance/elliptic_envelope.py +246 -175
- snowflake/ml/modeling/covariance/empirical_covariance.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso.py +246 -175
- snowflake/ml/modeling/covariance/graphical_lasso_cv.py +246 -175
- snowflake/ml/modeling/covariance/ledoit_wolf.py +246 -175
- snowflake/ml/modeling/covariance/min_cov_det.py +246 -175
- snowflake/ml/modeling/covariance/oas.py +246 -175
- snowflake/ml/modeling/covariance/shrunk_covariance.py +246 -175
- snowflake/ml/modeling/decomposition/dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/factor_analysis.py +248 -175
- snowflake/ml/modeling/decomposition/fast_ica.py +248 -175
- snowflake/ml/modeling/decomposition/incremental_pca.py +248 -175
- snowflake/ml/modeling/decomposition/kernel_pca.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_dictionary_learning.py +248 -175
- snowflake/ml/modeling/decomposition/mini_batch_sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/pca.py +248 -175
- snowflake/ml/modeling/decomposition/sparse_pca.py +248 -175
- snowflake/ml/modeling/decomposition/truncated_svd.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/linear_discriminant_analysis.py +248 -175
- snowflake/ml/modeling/discriminant_analysis/quadratic_discriminant_analysis.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/ada_boost_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/bagging_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/extra_trees_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/hist_gradient_boosting_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/isolation_forest.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_classifier.py +246 -175
- snowflake/ml/modeling/ensemble/random_forest_regressor.py +246 -175
- snowflake/ml/modeling/ensemble/stacking_regressor.py +248 -175
- snowflake/ml/modeling/ensemble/voting_classifier.py +248 -175
- snowflake/ml/modeling/ensemble/voting_regressor.py +248 -175
- snowflake/ml/modeling/feature_selection/generic_univariate_select.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fdr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fpr.py +248 -175
- snowflake/ml/modeling/feature_selection/select_fwe.py +248 -175
- snowflake/ml/modeling/feature_selection/select_k_best.py +248 -175
- snowflake/ml/modeling/feature_selection/select_percentile.py +248 -175
- snowflake/ml/modeling/feature_selection/sequential_feature_selector.py +248 -175
- snowflake/ml/modeling/feature_selection/variance_threshold.py +248 -175
- snowflake/ml/modeling/framework/_utils.py +8 -1
- snowflake/ml/modeling/framework/base.py +72 -37
- snowflake/ml/modeling/gaussian_process/gaussian_process_classifier.py +246 -175
- snowflake/ml/modeling/gaussian_process/gaussian_process_regressor.py +246 -175
- snowflake/ml/modeling/impute/iterative_imputer.py +248 -175
- snowflake/ml/modeling/impute/knn_imputer.py +248 -175
- snowflake/ml/modeling/impute/missing_indicator.py +248 -175
- snowflake/ml/modeling/kernel_approximation/additive_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/nystroem.py +248 -175
- snowflake/ml/modeling/kernel_approximation/polynomial_count_sketch.py +248 -175
- snowflake/ml/modeling/kernel_approximation/rbf_sampler.py +248 -175
- snowflake/ml/modeling/kernel_approximation/skewed_chi2_sampler.py +248 -175
- snowflake/ml/modeling/kernel_ridge/kernel_ridge.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_classifier.py +246 -175
- snowflake/ml/modeling/lightgbm/lgbm_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ard_regression.py +246 -175
- snowflake/ml/modeling/linear_model/bayesian_ridge.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/gamma_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/huber_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/lars.py +246 -175
- snowflake/ml/modeling/linear_model/lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_cv.py +246 -175
- snowflake/ml/modeling/linear_model/lasso_lars_ic.py +246 -175
- snowflake/ml/modeling/linear_model/linear_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression.py +246 -175
- snowflake/ml/modeling/linear_model/logistic_regression_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_elastic_net_cv.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso.py +246 -175
- snowflake/ml/modeling/linear_model/multi_task_lasso_cv.py +246 -175
- snowflake/ml/modeling/linear_model/orthogonal_matching_pursuit.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/passive_aggressive_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/perceptron.py +246 -175
- snowflake/ml/modeling/linear_model/poisson_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ransac_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/ridge.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_classifier_cv.py +246 -175
- snowflake/ml/modeling/linear_model/ridge_cv.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_classifier.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_one_class_svm.py +246 -175
- snowflake/ml/modeling/linear_model/sgd_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/theil_sen_regressor.py +246 -175
- snowflake/ml/modeling/linear_model/tweedie_regressor.py +246 -175
- snowflake/ml/modeling/manifold/isomap.py +248 -175
- snowflake/ml/modeling/manifold/mds.py +248 -175
- snowflake/ml/modeling/manifold/spectral_embedding.py +248 -175
- snowflake/ml/modeling/manifold/tsne.py +248 -175
- snowflake/ml/modeling/mixture/bayesian_gaussian_mixture.py +246 -175
- snowflake/ml/modeling/mixture/gaussian_mixture.py +246 -175
- snowflake/ml/modeling/model_selection/grid_search_cv.py +63 -41
- snowflake/ml/modeling/model_selection/randomized_search_cv.py +80 -38
- snowflake/ml/modeling/multiclass/one_vs_one_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/one_vs_rest_classifier.py +246 -175
- snowflake/ml/modeling/multiclass/output_code_classifier.py +246 -175
- snowflake/ml/modeling/naive_bayes/bernoulli_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/categorical_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/complement_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/gaussian_nb.py +246 -175
- snowflake/ml/modeling/naive_bayes/multinomial_nb.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/k_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neighbors/kernel_density.py +246 -175
- snowflake/ml/modeling/neighbors/local_outlier_factor.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_centroid.py +246 -175
- snowflake/ml/modeling/neighbors/nearest_neighbors.py +246 -175
- snowflake/ml/modeling/neighbors/neighborhood_components_analysis.py +248 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_classifier.py +246 -175
- snowflake/ml/modeling/neighbors/radius_neighbors_regressor.py +246 -175
- snowflake/ml/modeling/neural_network/bernoulli_rbm.py +248 -175
- snowflake/ml/modeling/neural_network/mlp_classifier.py +246 -175
- snowflake/ml/modeling/neural_network/mlp_regressor.py +246 -175
- snowflake/ml/modeling/pipeline/pipeline.py +517 -35
- snowflake/ml/modeling/preprocessing/binarizer.py +1 -5
- snowflake/ml/modeling/preprocessing/k_bins_discretizer.py +1 -5
- snowflake/ml/modeling/preprocessing/label_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/max_abs_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/min_max_scaler.py +10 -12
- snowflake/ml/modeling/preprocessing/normalizer.py +1 -5
- snowflake/ml/modeling/preprocessing/one_hot_encoder.py +13 -5
- snowflake/ml/modeling/preprocessing/ordinal_encoder.py +1 -5
- snowflake/ml/modeling/preprocessing/polynomial_features.py +248 -175
- snowflake/ml/modeling/preprocessing/robust_scaler.py +1 -5
- snowflake/ml/modeling/preprocessing/standard_scaler.py +11 -11
- snowflake/ml/modeling/semi_supervised/label_propagation.py +246 -175
- snowflake/ml/modeling/semi_supervised/label_spreading.py +246 -175
- snowflake/ml/modeling/svm/linear_svc.py +246 -175
- snowflake/ml/modeling/svm/linear_svr.py +246 -175
- snowflake/ml/modeling/svm/nu_svc.py +246 -175
- snowflake/ml/modeling/svm/nu_svr.py +246 -175
- snowflake/ml/modeling/svm/svc.py +246 -175
- snowflake/ml/modeling/svm/svr.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/decision_tree_regressor.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_classifier.py +246 -175
- snowflake/ml/modeling/tree/extra_tree_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgb_regressor.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_classifier.py +246 -175
- snowflake/ml/modeling/xgboost/xgbrf_regressor.py +246 -175
- snowflake/ml/registry/model_registry.py +3 -149
- snowflake/ml/registry/registry.py +1 -1
- snowflake/ml/version.py +1 -1
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/METADATA +129 -57
- snowflake_ml_python-1.5.0.dist-info/RECORD +380 -0
- snowflake/ml/model/_model_composer/model_runtime/model_runtime.py +0 -97
- snowflake/ml/registry/_artifact_manager.py +0 -156
- snowflake/ml/registry/artifact.py +0 -46
- snowflake_ml_python-1.4.0.dist-info/RECORD +0 -370
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/LICENSE.txt +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/WHEEL +0 -0
- {snowflake_ml_python-1.4.0.dist-info → snowflake_ml_python-1.5.0.dist-info}/top_level.txt +0 -0
@@ -70,13 +70,16 @@ class SnowServiceClient:
|
|
70
70
|
logger.debug(f"Create service with SQL: \n {sql}")
|
71
71
|
self.session.sql(sql).collect()
|
72
72
|
|
73
|
-
def create_job(
|
73
|
+
def create_job(
|
74
|
+
self, job_name: str, compute_pool: str, spec_stage_location: str, external_access_integrations: List[str]
|
75
|
+
) -> None:
|
74
76
|
"""Execute the job creation SQL command. Note that the job creation is synchronous, hence we execute it in a
|
75
77
|
async way so that we can query the log in the meantime.
|
76
78
|
|
77
79
|
Upon job failure, full job container log will be logged.
|
78
80
|
|
79
81
|
Args:
|
82
|
+
job_name: name of the job
|
80
83
|
compute_pool: name of the compute pool
|
81
84
|
spec_stage_location: path to the stage location where the spec is located at.
|
82
85
|
external_access_integrations: EAIs for network connection.
|
@@ -84,19 +87,18 @@ class SnowServiceClient:
|
|
84
87
|
stage, path = uri.get_stage_and_path(spec_stage_location)
|
85
88
|
sql = textwrap.dedent(
|
86
89
|
f"""
|
87
|
-
EXECUTE SERVICE
|
90
|
+
EXECUTE JOB SERVICE
|
88
91
|
IN COMPUTE POOL {compute_pool}
|
89
92
|
FROM {stage}
|
90
|
-
|
93
|
+
SPECIFICATION_FILE = '{path}'
|
94
|
+
NAME = {job_name}
|
91
95
|
EXTERNAL_ACCESS_INTEGRATIONS = ({', '.join(external_access_integrations)})
|
92
96
|
"""
|
93
97
|
)
|
94
98
|
logger.debug(f"Create job with SQL: \n {sql}")
|
95
|
-
|
96
|
-
cur.execute_async(sql)
|
97
|
-
job_id = cur._sfqid
|
99
|
+
self.session.sql(sql).collect_nowait()
|
98
100
|
self.block_until_resource_is_ready(
|
99
|
-
resource_name=
|
101
|
+
resource_name=job_name,
|
100
102
|
resource_type=constants.ResourceType.JOB,
|
101
103
|
container_name=constants.KANIKO_CONTAINER_NAME,
|
102
104
|
max_retries=240,
|
@@ -182,10 +184,7 @@ class SnowServiceClient:
|
|
182
184
|
"""
|
183
185
|
assert resource_type == constants.ResourceType.SERVICE or resource_type == constants.ResourceType.JOB
|
184
186
|
query_command = ""
|
185
|
-
|
186
|
-
query_command = f"CALL SYSTEM$GET_SERVICE_LOGS('{resource_name}', '0', '{container_name}')"
|
187
|
-
elif resource_type == constants.ResourceType.JOB:
|
188
|
-
query_command = f"CALL SYSTEM$GET_JOB_LOGS('{resource_name}', '{container_name}')"
|
187
|
+
query_command = f"CALL SYSTEM$GET_SERVICE_LOGS('{resource_name}', '0', '{container_name}')"
|
189
188
|
logger.warning(
|
190
189
|
f"Best-effort log streaming from SPCS will be enabled when python logging level is set to INFO."
|
191
190
|
f"Alternatively, you can also query the logs by running the query '{query_command}'"
|
@@ -201,7 +200,7 @@ class SnowServiceClient:
|
|
201
200
|
)
|
202
201
|
lsp.process_new_logs(resource_log, log_level=logging.INFO)
|
203
202
|
|
204
|
-
status = self.get_resource_status(resource_name=resource_name
|
203
|
+
status = self.get_resource_status(resource_name=resource_name)
|
205
204
|
|
206
205
|
if resource_type == constants.ResourceType.JOB and status == constants.ResourceStatus.DONE:
|
207
206
|
return
|
@@ -246,52 +245,24 @@ class SnowServiceClient:
|
|
246
245
|
def get_resource_log(
|
247
246
|
self, resource_name: str, resource_type: constants.ResourceType, container_name: str
|
248
247
|
) -> Optional[str]:
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
try:
|
259
|
-
row = self.session.sql(f"CALL SYSTEM$GET_JOB_LOGS('{resource_name}', '{container_name}')").collect()
|
260
|
-
return str(row[0]["SYSTEM$GET_JOB_LOGS"])
|
261
|
-
except Exception:
|
262
|
-
return None
|
263
|
-
else:
|
264
|
-
raise snowml_exceptions.SnowflakeMLException(
|
265
|
-
error_code=error_codes.NOT_IMPLEMENTED,
|
266
|
-
original_exception=NotImplementedError(
|
267
|
-
f"{resource_type.name} is not yet supported in get_resource_log function"
|
268
|
-
),
|
269
|
-
)
|
270
|
-
|
271
|
-
def get_resource_status(
|
272
|
-
self, resource_name: str, resource_type: constants.ResourceType
|
273
|
-
) -> Optional[constants.ResourceStatus]:
|
248
|
+
try:
|
249
|
+
row = self.session.sql(
|
250
|
+
f"CALL SYSTEM$GET_SERVICE_LOGS('{resource_name}', '0', '{container_name}')"
|
251
|
+
).collect()
|
252
|
+
return str(row[0]["SYSTEM$GET_SERVICE_LOGS"])
|
253
|
+
except Exception:
|
254
|
+
return None
|
255
|
+
|
256
|
+
def get_resource_status(self, resource_name: str) -> Optional[constants.ResourceStatus]:
|
274
257
|
"""Get resource status.
|
275
258
|
|
276
259
|
Args:
|
277
260
|
resource_name: Name of the resource.
|
278
|
-
resource_type: Type of the resource.
|
279
|
-
|
280
|
-
Raises:
|
281
|
-
SnowflakeMLException: If resource type does not have a corresponding system function for querying status.
|
282
|
-
SnowflakeMLException: If corresponding status call failed.
|
283
261
|
|
284
262
|
Returns:
|
285
263
|
Optional[constants.ResourceStatus]: The status of the resource, or None if the resource status is empty.
|
286
264
|
"""
|
287
|
-
|
288
|
-
raise snowml_exceptions.SnowflakeMLException(
|
289
|
-
error_code=error_codes.INVALID_ARGUMENT,
|
290
|
-
original_exception=ValueError(
|
291
|
-
f"Status querying is not supported for resources of type '{resource_type}'."
|
292
|
-
),
|
293
|
-
)
|
294
|
-
status_func = constants.RESOURCE_TO_STATUS_FUNCTION_MAPPING[resource_type]
|
265
|
+
status_func = "SYSTEM$GET_SERVICE_STATUS"
|
295
266
|
try:
|
296
267
|
row = self.session.sql(f"CALL {status_func}('{resource_name}');").collect()
|
297
268
|
except Exception:
|
@@ -8,8 +8,10 @@ from typing import Any, Dict, List, Optional
|
|
8
8
|
|
9
9
|
from absl import logging
|
10
10
|
from packaging import requirements
|
11
|
+
from typing_extensions import deprecated
|
11
12
|
|
12
13
|
from snowflake.ml._internal import env as snowml_env, env_utils, file_utils
|
14
|
+
from snowflake.ml._internal.lineage import data_source
|
13
15
|
from snowflake.ml.model import model_signature, type_hints as model_types
|
14
16
|
from snowflake.ml.model._model_composer.model_manifest import model_manifest
|
15
17
|
from snowflake.ml.model._packager import model_packager
|
@@ -134,6 +136,7 @@ class ModelComposer:
|
|
134
136
|
model_meta=self.packager.meta,
|
135
137
|
model_file_rel_path=pathlib.PurePosixPath(self.model_file_rel_path),
|
136
138
|
options=options,
|
139
|
+
data_sources=self._get_data_sources(model),
|
137
140
|
)
|
138
141
|
|
139
142
|
file_utils.upload_directory_to_stage(
|
@@ -143,7 +146,8 @@ class ModelComposer:
|
|
143
146
|
statement_params=self._statement_params,
|
144
147
|
)
|
145
148
|
|
146
|
-
|
149
|
+
@deprecated("Only used by PrPr model registry. Use static method version of load instead.")
|
150
|
+
def legacy_load(
|
147
151
|
self,
|
148
152
|
*,
|
149
153
|
meta_only: bool = False,
|
@@ -163,3 +167,20 @@ class ModelComposer:
|
|
163
167
|
with zipfile.ZipFile(self.model_local_path, mode="r", compression=zipfile.ZIP_DEFLATED) as zf:
|
164
168
|
zf.extractall(path=self._packager_workspace_path)
|
165
169
|
self.packager.load(meta_only=meta_only, options=options)
|
170
|
+
|
171
|
+
@staticmethod
|
172
|
+
def load(
|
173
|
+
workspace_path: pathlib.Path,
|
174
|
+
*,
|
175
|
+
meta_only: bool = False,
|
176
|
+
options: Optional[model_types.ModelLoadOption] = None,
|
177
|
+
) -> model_packager.ModelPackager:
|
178
|
+
mp = model_packager.ModelPackager(str(workspace_path / ModelComposer.MODEL_DIR_REL_PATH))
|
179
|
+
mp.load(meta_only=meta_only, options=options)
|
180
|
+
return mp
|
181
|
+
|
182
|
+
def _get_data_sources(self, model: model_types.SupportedModelType) -> Optional[List[data_source.DataSource]]:
|
183
|
+
data_sources = getattr(model, "_data_sources", None)
|
184
|
+
if isinstance(data_sources, list) and all(isinstance(item, data_source.DataSource) for item in data_sources):
|
185
|
+
return data_sources
|
186
|
+
return None
|
@@ -1,16 +1,17 @@
|
|
1
1
|
import collections
|
2
|
+
import copy
|
2
3
|
import pathlib
|
3
|
-
from typing import
|
4
|
+
from typing import List, Optional, cast
|
4
5
|
|
5
6
|
import yaml
|
6
7
|
|
8
|
+
from snowflake.ml._internal.lineage import data_source
|
7
9
|
from snowflake.ml.model import type_hints
|
8
10
|
from snowflake.ml.model._model_composer.model_manifest import model_manifest_schema
|
9
11
|
from snowflake.ml.model._model_composer.model_method import (
|
10
12
|
function_generator,
|
11
13
|
model_method,
|
12
14
|
)
|
13
|
-
from snowflake.ml.model._model_composer.model_runtime import model_runtime
|
14
15
|
from snowflake.ml.model._packager.model_meta import model_meta as model_meta_api
|
15
16
|
from snowflake.snowpark import Session
|
16
17
|
|
@@ -36,24 +37,23 @@ class ModelManifest:
|
|
36
37
|
model_meta: model_meta_api.ModelMetadata,
|
37
38
|
model_file_rel_path: pathlib.PurePosixPath,
|
38
39
|
options: Optional[type_hints.ModelSaveOption] = None,
|
40
|
+
data_sources: Optional[List[data_source.DataSource]] = None,
|
39
41
|
) -> None:
|
40
42
|
if options is None:
|
41
43
|
options = {}
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
)
|
49
|
-
]
|
44
|
+
|
45
|
+
runtime_to_use = copy.deepcopy(model_meta.runtimes["cpu"])
|
46
|
+
runtime_to_use.name = self._DEFAULT_RUNTIME_NAME
|
47
|
+
runtime_to_use.imports.append(model_file_rel_path)
|
48
|
+
runtime_dict = runtime_to_use.save(self.workspace_path)
|
49
|
+
|
50
50
|
self.function_generator = function_generator.FunctionGenerator(model_file_rel_path=model_file_rel_path)
|
51
51
|
self.methods: List[model_method.ModelMethod] = []
|
52
52
|
for target_method in model_meta.signatures.keys():
|
53
53
|
method = model_method.ModelMethod(
|
54
54
|
model_meta=model_meta,
|
55
55
|
target_method=target_method,
|
56
|
-
runtime_name=self.
|
56
|
+
runtime_name=self._DEFAULT_RUNTIME_NAME,
|
57
57
|
function_generator=self.function_generator,
|
58
58
|
options=model_method.get_model_method_options_from_options(options, target_method),
|
59
59
|
)
|
@@ -71,7 +71,16 @@ class ModelManifest:
|
|
71
71
|
|
72
72
|
manifest_dict = model_manifest_schema.ModelManifestDict(
|
73
73
|
manifest_version=model_manifest_schema.MODEL_MANIFEST_VERSION,
|
74
|
-
runtimes={
|
74
|
+
runtimes={
|
75
|
+
self._DEFAULT_RUNTIME_NAME: model_manifest_schema.ModelRuntimeDict(
|
76
|
+
language="PYTHON",
|
77
|
+
version=runtime_to_use.runtime_env.python_version,
|
78
|
+
imports=runtime_dict["imports"],
|
79
|
+
dependencies=model_manifest_schema.ModelRuntimeDependenciesDict(
|
80
|
+
conda=runtime_dict["dependencies"]["conda"]
|
81
|
+
),
|
82
|
+
)
|
83
|
+
},
|
75
84
|
methods=[
|
76
85
|
method.save(
|
77
86
|
self.workspace_path,
|
@@ -83,7 +92,9 @@ class ModelManifest:
|
|
83
92
|
],
|
84
93
|
)
|
85
94
|
|
86
|
-
|
95
|
+
lineage_sources = self._extract_lineage_info(data_sources)
|
96
|
+
if lineage_sources:
|
97
|
+
manifest_dict["lineage_sources"] = lineage_sources
|
87
98
|
|
88
99
|
with (self.workspace_path / ModelManifest.MANIFEST_FILE_REL_PATH).open("w", encoding="utf-8") as f:
|
89
100
|
# Anchors are not supported in the server, avoid that.
|
@@ -104,42 +115,18 @@ class ModelManifest:
|
|
104
115
|
|
105
116
|
return res
|
106
117
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
118
|
+
def _extract_lineage_info(
|
119
|
+
self, data_sources: Optional[List[data_source.DataSource]]
|
120
|
+
) -> List[model_manifest_schema.LineageSourceDict]:
|
121
|
+
result = []
|
122
|
+
if data_sources:
|
123
|
+
for source in data_sources:
|
124
|
+
result.append(
|
125
|
+
model_manifest_schema.LineageSourceDict(
|
126
|
+
# Currently, we only support lineage from Dataset.
|
127
|
+
type=model_manifest_schema.LineageSourceTypes.DATASET.value,
|
128
|
+
entity=source.fully_qualified_name,
|
129
|
+
version=source.version,
|
130
|
+
)
|
115
131
|
)
|
116
|
-
|
117
|
-
],
|
118
|
-
)
|
119
|
-
return {model_manifest_schema.MANIFEST_CLIENT_DATA_KEY_NAME: client_data}
|
120
|
-
|
121
|
-
@staticmethod
|
122
|
-
def parse_client_data_from_user_data(raw_user_data: Dict[str, Any]) -> model_manifest_schema.SnowparkMLDataDict:
|
123
|
-
raw_client_data = raw_user_data.get(model_manifest_schema.MANIFEST_CLIENT_DATA_KEY_NAME, {})
|
124
|
-
if not isinstance(raw_client_data, dict) or "schema_version" not in raw_client_data:
|
125
|
-
raise ValueError(f"Ill-formatted client data {raw_client_data} in user data found.")
|
126
|
-
loaded_client_data_schema_version = raw_client_data["schema_version"]
|
127
|
-
if (
|
128
|
-
not isinstance(loaded_client_data_schema_version, str)
|
129
|
-
or loaded_client_data_schema_version != model_manifest_schema.MANIFEST_CLIENT_DATA_SCHEMA_VERSION
|
130
|
-
):
|
131
|
-
raise ValueError(f"Unsupported client data schema version {loaded_client_data_schema_version} confronted.")
|
132
|
-
|
133
|
-
return_functions_info: List[model_manifest_schema.ModelFunctionInfoDict] = []
|
134
|
-
loaded_functions_info = raw_client_data.get("functions", [])
|
135
|
-
for func in loaded_functions_info:
|
136
|
-
fi = model_manifest_schema.ModelFunctionInfoDict(
|
137
|
-
name=func["name"],
|
138
|
-
target_method=func["target_method"],
|
139
|
-
signature=func["signature"],
|
140
|
-
)
|
141
|
-
return_functions_info.append(fi)
|
142
|
-
|
143
|
-
return model_manifest_schema.SnowparkMLDataDict(
|
144
|
-
schema_version=loaded_client_data_schema_version, functions=return_functions_info
|
145
|
-
)
|
132
|
+
return result
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# This files contains schema definition of what will be written into MANIFEST.yml
|
2
|
-
|
2
|
+
import enum
|
3
3
|
from typing import Any, Dict, List, Literal, TypedDict, Union
|
4
4
|
|
5
5
|
from typing_extensions import NotRequired, Required
|
@@ -12,6 +12,11 @@ MANIFEST_CLIENT_DATA_KEY_NAME = "snowpark_ml_data"
|
|
12
12
|
MANIFEST_CLIENT_DATA_SCHEMA_VERSION = "2024-02-01"
|
13
13
|
|
14
14
|
|
15
|
+
class ModelMethodFunctionTypes(enum.Enum):
|
16
|
+
FUNCTION = "FUNCTION"
|
17
|
+
TABLE_FUNCTION = "TABLE_FUNCTION"
|
18
|
+
|
19
|
+
|
15
20
|
class ModelRuntimeDependenciesDict(TypedDict):
|
16
21
|
conda: Required[str]
|
17
22
|
|
@@ -49,11 +54,13 @@ class ModelFunctionInfo(TypedDict):
|
|
49
54
|
Attributes:
|
50
55
|
name: Name of the function to be called via SQL.
|
51
56
|
target_method: actual target method name to be called.
|
57
|
+
target_method_function_type: target method function type (FUNCTION or TABLE_FUNCTION).
|
52
58
|
signature: The signature of the model method.
|
53
59
|
"""
|
54
60
|
|
55
61
|
name: Required[str]
|
56
62
|
target_method: Required[str]
|
63
|
+
target_method_function_type: Required[str]
|
57
64
|
signature: Required[model_signature.ModelSignature]
|
58
65
|
|
59
66
|
|
@@ -68,8 +75,19 @@ class SnowparkMLDataDict(TypedDict):
|
|
68
75
|
functions: Required[List[ModelFunctionInfoDict]]
|
69
76
|
|
70
77
|
|
78
|
+
class LineageSourceTypes(enum.Enum):
|
79
|
+
DATASET = "DATASET"
|
80
|
+
|
81
|
+
|
82
|
+
class LineageSourceDict(TypedDict):
|
83
|
+
type: Required[str]
|
84
|
+
entity: Required[str]
|
85
|
+
version: NotRequired[str]
|
86
|
+
|
87
|
+
|
71
88
|
class ModelManifestDict(TypedDict):
|
72
89
|
manifest_version: Required[str]
|
73
90
|
runtimes: Required[Dict[str, ModelRuntimeDict]]
|
74
91
|
methods: Required[List[ModelMethodDict]]
|
75
92
|
user_data: NotRequired[Dict[str, Any]]
|
93
|
+
lineage_sources: NotRequired[List[LineageSourceDict]]
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import collections
|
2
|
-
import enum
|
3
2
|
import pathlib
|
4
3
|
from typing import List, Optional, TypedDict, Union
|
5
4
|
|
@@ -13,11 +12,6 @@ from snowflake.ml.model._packager.model_meta import model_meta as model_meta_api
|
|
13
12
|
from snowflake.snowpark._internal import type_utils
|
14
13
|
|
15
14
|
|
16
|
-
class ModelMethodFunctionTypes(enum.Enum):
|
17
|
-
FUNCTION = "FUNCTION"
|
18
|
-
TABLE_FUNCTION = "TABLE_FUNCTION"
|
19
|
-
|
20
|
-
|
21
15
|
class ModelMethodOptions(TypedDict):
|
22
16
|
"""Options when creating model method.
|
23
17
|
|
@@ -33,9 +27,9 @@ def get_model_method_options_from_options(
|
|
33
27
|
options: type_hints.ModelSaveOption, target_method: str
|
34
28
|
) -> ModelMethodOptions:
|
35
29
|
method_option = options.get("method_options", {}).get(target_method, {})
|
36
|
-
global_function_type = options.get("function_type", ModelMethodFunctionTypes.FUNCTION.value)
|
30
|
+
global_function_type = options.get("function_type", model_manifest_schema.ModelMethodFunctionTypes.FUNCTION.value)
|
37
31
|
function_type = method_option.get("function_type", global_function_type)
|
38
|
-
if function_type not in [function_type.value for function_type in ModelMethodFunctionTypes]:
|
32
|
+
if function_type not in [function_type.value for function_type in model_manifest_schema.ModelMethodFunctionTypes]:
|
39
33
|
raise NotImplementedError
|
40
34
|
|
41
35
|
# TODO(TH): enforce minimum snowflake version
|
@@ -89,7 +83,9 @@ class ModelMethod:
|
|
89
83
|
if self.target_method not in self.model_meta.signatures.keys():
|
90
84
|
raise ValueError(f"Target method {self.target_method} is not available in the signatures of the model.")
|
91
85
|
|
92
|
-
self.function_type = self.options.get(
|
86
|
+
self.function_type = self.options.get(
|
87
|
+
"function_type", model_manifest_schema.ModelMethodFunctionTypes.FUNCTION.value
|
88
|
+
)
|
93
89
|
|
94
90
|
@staticmethod
|
95
91
|
def _get_method_arg_from_feature(
|
@@ -134,7 +130,7 @@ class ModelMethod:
|
|
134
130
|
List[model_manifest_schema.ModelMethodSignatureField],
|
135
131
|
List[model_manifest_schema.ModelMethodSignatureFieldWithName],
|
136
132
|
]
|
137
|
-
if self.function_type == ModelMethodFunctionTypes.TABLE_FUNCTION.value:
|
133
|
+
if self.function_type == model_manifest_schema.ModelMethodFunctionTypes.TABLE_FUNCTION.value:
|
138
134
|
outputs = [
|
139
135
|
ModelMethod._get_method_arg_from_feature(ft, case_sensitive=self.options.get("case_sensitive", False))
|
140
136
|
for ft in self.model_meta.signatures[self.target_method].outputs
|
@@ -284,6 +284,7 @@ class ModelEnv:
|
|
284
284
|
" This may prevent model deploying to Snowflake Warehouse."
|
285
285
|
),
|
286
286
|
category=UserWarning,
|
287
|
+
stacklevel=2,
|
287
288
|
)
|
288
289
|
if len(channel_dependencies) == 0 and channel not in self._conda_dependencies:
|
289
290
|
warnings.warn(
|
@@ -292,6 +293,7 @@ class ModelEnv:
|
|
292
293
|
" This may prevent model deploying to Snowflake Warehouse."
|
293
294
|
),
|
294
295
|
category=UserWarning,
|
296
|
+
stacklevel=2,
|
295
297
|
)
|
296
298
|
self._conda_dependencies[channel] = []
|
297
299
|
|
@@ -307,6 +309,7 @@ class ModelEnv:
|
|
307
309
|
" This may be unintentional."
|
308
310
|
),
|
309
311
|
category=UserWarning,
|
312
|
+
stacklevel=2,
|
310
313
|
)
|
311
314
|
|
312
315
|
if pip_requirements_list:
|
@@ -316,6 +319,7 @@ class ModelEnv:
|
|
316
319
|
" This may prevent model deploying to Snowflake Warehouse."
|
317
320
|
),
|
318
321
|
category=UserWarning,
|
322
|
+
stacklevel=2,
|
319
323
|
)
|
320
324
|
for pip_dependency in pip_requirements_list:
|
321
325
|
if any(
|
@@ -338,6 +342,7 @@ class ModelEnv:
|
|
338
342
|
" This may prevent model deploying to Snowflake Warehouse."
|
339
343
|
),
|
340
344
|
category=UserWarning,
|
345
|
+
stacklevel=2,
|
341
346
|
)
|
342
347
|
for pip_dependency in pip_requirements_list:
|
343
348
|
if any(
|
@@ -372,3 +377,39 @@ class ModelEnv:
|
|
372
377
|
"cuda_version": self.cuda_version,
|
373
378
|
"snowpark_ml_version": self.snowpark_ml_version,
|
374
379
|
}
|
380
|
+
|
381
|
+
def validate_with_local_env(
|
382
|
+
self, check_snowpark_ml_version: bool = False
|
383
|
+
) -> List[env_utils.IncorrectLocalEnvironmentError]:
|
384
|
+
errors = []
|
385
|
+
try:
|
386
|
+
env_utils.validate_py_runtime_version(str(self._python_version))
|
387
|
+
except env_utils.IncorrectLocalEnvironmentError as e:
|
388
|
+
errors.append(e)
|
389
|
+
|
390
|
+
for conda_reqs in self._conda_dependencies.values():
|
391
|
+
for conda_req in conda_reqs:
|
392
|
+
try:
|
393
|
+
env_utils.validate_local_installed_version_of_pip_package(
|
394
|
+
env_utils.try_convert_conda_requirement_to_pip(conda_req)
|
395
|
+
)
|
396
|
+
except env_utils.IncorrectLocalEnvironmentError as e:
|
397
|
+
errors.append(e)
|
398
|
+
|
399
|
+
for pip_req in self._pip_requirements:
|
400
|
+
try:
|
401
|
+
env_utils.validate_local_installed_version_of_pip_package(pip_req)
|
402
|
+
except env_utils.IncorrectLocalEnvironmentError as e:
|
403
|
+
errors.append(e)
|
404
|
+
|
405
|
+
if check_snowpark_ml_version:
|
406
|
+
# For Modeling model
|
407
|
+
if self._snowpark_ml_version.base_version != snowml_env.VERSION:
|
408
|
+
errors.append(
|
409
|
+
env_utils.IncorrectLocalEnvironmentError(
|
410
|
+
f"The local installed version of Snowpark ML library is {snowml_env.VERSION} "
|
411
|
+
f"which differs from required version {self.snowpark_ml_version}."
|
412
|
+
)
|
413
|
+
)
|
414
|
+
|
415
|
+
return errors
|