sagemaker-core 1.0.47__py3-none-any.whl → 2.1.1__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.
- sagemaker/core/__init__.py +16 -0
- sagemaker/core/_studio.py +116 -0
- sagemaker/core/_version.py +11 -0
- sagemaker/core/accept_types.py +131 -0
- sagemaker/core/analytics.py +744 -0
- sagemaker/core/apiutils/__init__.py +13 -0
- sagemaker/core/apiutils/_base_types.py +228 -0
- sagemaker/core/apiutils/_boto_functions.py +130 -0
- sagemaker/core/apiutils/_utils.py +34 -0
- sagemaker/core/base_deserializers.py +35 -0
- sagemaker/core/base_serializers.py +35 -0
- sagemaker/core/clarify/__init__.py +2898 -0
- sagemaker/core/collection.py +467 -0
- sagemaker/core/common_utils.py +2281 -0
- sagemaker/core/compute_resource_requirements/__init__.py +18 -0
- sagemaker/core/compute_resource_requirements/resource_requirements.py +94 -0
- sagemaker/core/config/__init__.py +181 -0
- sagemaker/core/config/config.py +238 -0
- sagemaker/core/config/config_manager.py +595 -0
- sagemaker/core/config/config_schema.py +1220 -0
- sagemaker/core/config/config_utils.py +297 -0
- {sagemaker_core/main → sagemaker/core}/config_schema.py +410 -4
- sagemaker/core/constants.py +73 -0
- sagemaker/core/content_types.py +137 -0
- sagemaker/core/debugger/__init__.py +39 -0
- sagemaker/core/debugger/debugger.py +945 -0
- sagemaker/core/debugger/framework_profile.py +292 -0
- sagemaker/core/debugger/metrics_config.py +468 -0
- sagemaker/core/debugger/profiler.py +42 -0
- sagemaker/core/debugger/profiler_config.py +190 -0
- sagemaker/core/debugger/profiler_constants.py +40 -0
- sagemaker/core/debugger/utils.py +148 -0
- sagemaker/core/deprecations.py +254 -0
- sagemaker/core/deserializers/__init__.py +10 -0
- sagemaker/core/deserializers/base.py +424 -0
- sagemaker/core/deserializers/implementations.py +157 -0
- sagemaker/core/drift_check_baselines.py +106 -0
- sagemaker/core/enums.py +51 -0
- sagemaker/core/environment_variables.py +101 -0
- sagemaker/core/exceptions.py +108 -0
- sagemaker/core/experiments/__init__.py +53 -0
- sagemaker/core/experiments/_api_types.py +251 -0
- sagemaker/core/experiments/_environment.py +124 -0
- sagemaker/core/experiments/_helper.py +294 -0
- sagemaker/core/experiments/_metrics.py +333 -0
- sagemaker/core/experiments/_run_context.py +58 -0
- sagemaker/core/experiments/_utils.py +216 -0
- sagemaker/core/experiments/experiment.py +244 -0
- sagemaker/core/experiments/run.py +970 -0
- sagemaker/core/experiments/trial.py +296 -0
- sagemaker/core/experiments/trial_component.py +387 -0
- sagemaker/core/explainer/__init__.py +24 -0
- sagemaker/core/explainer/clarify_explainer_config.py +298 -0
- sagemaker/core/explainer/explainer_config.py +44 -0
- sagemaker/core/fw_utils.py +1176 -0
- sagemaker/core/git_utils.py +349 -0
- sagemaker/core/helper/pipeline_variable.py +82 -0
- sagemaker/core/helper/session_helper.py +2965 -0
- sagemaker/core/huggingface/__init__.py +29 -0
- sagemaker/core/huggingface/llm_utils.py +150 -0
- sagemaker/core/huggingface/processing.py +139 -0
- sagemaker/core/huggingface/training_compiler/config.py +167 -0
- sagemaker/core/hyperparameters.py +172 -0
- sagemaker/core/image_retriever/__init__.py +3 -0
- sagemaker/core/image_retriever/image_retriever.py +640 -0
- sagemaker/core/image_retriever/image_retriever_utils.py +511 -0
- sagemaker/core/image_retriever/test.py +7 -0
- sagemaker/core/image_uri_config/__init__.py +13 -0
- sagemaker/core/image_uri_config/autogluon.json +1335 -0
- sagemaker/core/image_uri_config/blazingtext.json +50 -0
- sagemaker/core/image_uri_config/chainer.json +104 -0
- sagemaker/core/image_uri_config/clarify.json +39 -0
- sagemaker/core/image_uri_config/coach-mxnet.json +70 -0
- sagemaker/core/image_uri_config/coach-tensorflow.json +186 -0
- sagemaker/core/image_uri_config/data-wrangler.json +91 -0
- sagemaker/core/image_uri_config/debugger.json +34 -0
- sagemaker/core/image_uri_config/detailed-profiler.json +18 -0
- sagemaker/core/image_uri_config/djl-deepspeed.json +385 -0
- sagemaker/core/image_uri_config/djl-fastertransformer.json +167 -0
- sagemaker/core/image_uri_config/djl-lmi.json +136 -0
- sagemaker/core/image_uri_config/djl-neuronx.json +258 -0
- sagemaker/core/image_uri_config/djl-tensorrtllm.json +262 -0
- sagemaker/core/image_uri_config/factorization-machines.json +50 -0
- sagemaker/core/image_uri_config/forecasting-deepar.json +50 -0
- sagemaker/core/image_uri_config/huggingface-llm-neuronx.json +660 -0
- sagemaker/core/image_uri_config/huggingface-llm.json +1158 -0
- sagemaker/core/image_uri_config/huggingface-neuron.json +52 -0
- sagemaker/core/image_uri_config/huggingface-neuronx.json +510 -0
- sagemaker/core/image_uri_config/huggingface-tei-cpu.json +298 -0
- sagemaker/core/image_uri_config/huggingface-tei.json +298 -0
- sagemaker/core/image_uri_config/huggingface-training-compiler.json +195 -0
- sagemaker/core/image_uri_config/huggingface.json +2138 -0
- sagemaker/core/image_uri_config/hyperpod-recipes-neuron.json +52 -0
- sagemaker/core/image_uri_config/image-classification-neo.json +43 -0
- sagemaker/core/image_uri_config/image-classification.json +50 -0
- sagemaker/core/image_uri_config/inferentia-mxnet.json +88 -0
- sagemaker/core/image_uri_config/inferentia-pytorch.json +127 -0
- sagemaker/core/image_uri_config/inferentia-tensorflow.json +88 -0
- sagemaker/core/image_uri_config/instance_gpu_info.json +782 -0
- sagemaker/core/image_uri_config/ipinsights.json +50 -0
- sagemaker/core/image_uri_config/kmeans.json +50 -0
- sagemaker/core/image_uri_config/knn.json +50 -0
- sagemaker/core/image_uri_config/lda.json +26 -0
- sagemaker/core/image_uri_config/linear-learner.json +50 -0
- sagemaker/core/image_uri_config/model-monitor.json +42 -0
- sagemaker/core/image_uri_config/mxnet.json +1154 -0
- sagemaker/core/image_uri_config/neo-mxnet.json +64 -0
- sagemaker/core/image_uri_config/neo-pytorch.json +341 -0
- sagemaker/core/image_uri_config/neo-tensorflow.json +109 -0
- sagemaker/core/image_uri_config/ntm.json +50 -0
- sagemaker/core/image_uri_config/object-detection.json +50 -0
- sagemaker/core/image_uri_config/object2vec.json +50 -0
- sagemaker/core/image_uri_config/pca.json +50 -0
- sagemaker/core/image_uri_config/pytorch-neuron.json +43 -0
- sagemaker/core/image_uri_config/pytorch-smp.json +218 -0
- sagemaker/core/image_uri_config/pytorch-training-compiler.json +80 -0
- sagemaker/core/image_uri_config/pytorch.json +3101 -0
- sagemaker/core/image_uri_config/randomcutforest.json +50 -0
- sagemaker/core/image_uri_config/ray-pytorch.json +46 -0
- sagemaker/core/image_uri_config/ray-tensorflow.json +194 -0
- sagemaker/core/image_uri_config/sagemaker-base-python.json +46 -0
- sagemaker/core/image_uri_config/sagemaker-distribution.json +37 -0
- sagemaker/core/image_uri_config/sagemaker-geospatial.json +13 -0
- sagemaker/core/image_uri_config/sagemaker-tritonserver.json +212 -0
- sagemaker/core/image_uri_config/semantic-segmentation.json +50 -0
- sagemaker/core/image_uri_config/seq2seq.json +50 -0
- sagemaker/core/image_uri_config/sklearn.json +446 -0
- sagemaker/core/image_uri_config/spark.json +280 -0
- sagemaker/core/image_uri_config/sparkml-serving.json +97 -0
- sagemaker/core/image_uri_config/stabilityai.json +53 -0
- sagemaker/core/image_uri_config/tensorflow.json +5086 -0
- sagemaker/core/image_uri_config/vw.json +25 -0
- sagemaker/core/image_uri_config/xgboost-neo.json +43 -0
- sagemaker/core/image_uri_config/xgboost.json +888 -0
- sagemaker/core/image_uris.py +810 -0
- sagemaker/core/inference_config.py +144 -0
- sagemaker/core/inference_recommender/__init__.py +18 -0
- sagemaker/core/inference_recommender/inference_recommender_mixin.py +622 -0
- sagemaker/core/inputs.py +366 -0
- sagemaker/core/instance_group.py +61 -0
- sagemaker/core/instance_types.py +164 -0
- sagemaker/core/instance_types_gpu_info.py +43 -0
- sagemaker/core/interactive_apps/__init__.py +41 -0
- sagemaker/core/interactive_apps/base_interactive_app.py +204 -0
- sagemaker/core/interactive_apps/detail_profiler_app.py +139 -0
- sagemaker/core/interactive_apps/tensorboard.py +149 -0
- sagemaker/core/iterators.py +186 -0
- sagemaker/core/job.py +380 -0
- sagemaker/core/jumpstart/__init__.py +156 -0
- sagemaker/core/jumpstart/accessors.py +390 -0
- sagemaker/core/jumpstart/artifacts/__init__.py +69 -0
- sagemaker/core/jumpstart/artifacts/environment_variables.py +252 -0
- sagemaker/core/jumpstart/artifacts/hyperparameters.py +120 -0
- sagemaker/core/jumpstart/artifacts/image_uris.py +139 -0
- sagemaker/core/jumpstart/artifacts/incremental_training.py +87 -0
- sagemaker/core/jumpstart/artifacts/instance_types.py +223 -0
- sagemaker/core/jumpstart/artifacts/kwargs.py +289 -0
- sagemaker/core/jumpstart/artifacts/metric_definitions.py +117 -0
- sagemaker/core/jumpstart/artifacts/model_packages.py +202 -0
- sagemaker/core/jumpstart/artifacts/model_uris.py +252 -0
- sagemaker/core/jumpstart/artifacts/payloads.py +96 -0
- sagemaker/core/jumpstart/artifacts/predictors.py +540 -0
- sagemaker/core/jumpstart/artifacts/resource_names.py +86 -0
- sagemaker/core/jumpstart/artifacts/resource_requirements.py +162 -0
- sagemaker/core/jumpstart/artifacts/script_uris.py +172 -0
- sagemaker/core/jumpstart/cache.py +663 -0
- sagemaker/core/jumpstart/configs.py +50 -0
- sagemaker/core/jumpstart/constants.py +198 -0
- sagemaker/core/jumpstart/deserializers.py +81 -0
- sagemaker/core/jumpstart/document.py +76 -0
- sagemaker/core/jumpstart/enums.py +168 -0
- sagemaker/core/jumpstart/exceptions.py +236 -0
- sagemaker/core/jumpstart/factory/utils.py +833 -0
- sagemaker/core/jumpstart/filters.py +597 -0
- sagemaker/core/jumpstart/hub/__init__.py +0 -0
- sagemaker/core/jumpstart/hub/constants.py +16 -0
- sagemaker/core/jumpstart/hub/hub.py +291 -0
- sagemaker/core/jumpstart/hub/interfaces.py +936 -0
- sagemaker/core/jumpstart/hub/parser_utils.py +70 -0
- sagemaker/core/jumpstart/hub/parsers.py +288 -0
- sagemaker/core/jumpstart/hub/types.py +35 -0
- sagemaker/core/jumpstart/hub/utils.py +260 -0
- sagemaker/core/jumpstart/models.py +499 -0
- sagemaker/core/jumpstart/notebook_utils.py +575 -0
- sagemaker/core/jumpstart/parameters.py +20 -0
- sagemaker/core/jumpstart/payload_utils.py +239 -0
- sagemaker/core/jumpstart/region_config.json +163 -0
- sagemaker/core/jumpstart/search.py +171 -0
- sagemaker/core/jumpstart/serializers.py +81 -0
- sagemaker/core/jumpstart/session_utils.py +234 -0
- sagemaker/core/jumpstart/types.py +3044 -0
- sagemaker/core/jumpstart/utils.py +1731 -0
- sagemaker/core/jumpstart/validators.py +257 -0
- sagemaker/core/lambda_helper.py +312 -0
- sagemaker/core/lineage/__init__.py +42 -0
- sagemaker/core/lineage/_api_types.py +239 -0
- sagemaker/core/lineage/_utils.py +49 -0
- sagemaker/core/lineage/action.py +345 -0
- sagemaker/core/lineage/artifact.py +646 -0
- sagemaker/core/lineage/association.py +190 -0
- sagemaker/core/lineage/context.py +505 -0
- sagemaker/core/lineage/lineage_trial_component.py +191 -0
- sagemaker/core/lineage/query.py +732 -0
- sagemaker/core/lineage/visualizer.py +346 -0
- sagemaker/core/local/__init__.py +18 -0
- sagemaker/core/local/data.py +413 -0
- sagemaker/core/local/entities.py +678 -0
- sagemaker/core/local/exceptions.py +17 -0
- sagemaker/core/local/image.py +1243 -0
- sagemaker/core/local/local_session.py +739 -0
- sagemaker/core/local/utils.py +245 -0
- sagemaker/core/logs.py +181 -0
- sagemaker/core/metadata_properties.py +56 -0
- sagemaker/core/metric_definitions.py +91 -0
- sagemaker/core/mlflow/__init__.py +38 -0
- sagemaker/core/mlflow/forward_sagemaker_metrics.py +44 -0
- sagemaker/core/model_card/__init__.py +26 -0
- sagemaker/core/model_life_cycle.py +51 -0
- sagemaker/core/model_metrics.py +160 -0
- sagemaker/core/model_monitor/__init__.py +66 -0
- sagemaker/core/model_monitor/clarify_model_monitoring.py +1495 -0
- sagemaker/core/model_monitor/cron_expression_generator.py +82 -0
- sagemaker/core/model_monitor/data_capture_config.py +115 -0
- sagemaker/core/model_monitor/data_quality_monitoring_config.py +66 -0
- sagemaker/core/model_monitor/dataset_format.py +102 -0
- sagemaker/core/model_monitor/model_monitoring.py +4266 -0
- sagemaker/core/model_monitor/monitoring_alert.py +76 -0
- sagemaker/core/model_monitor/monitoring_files.py +506 -0
- sagemaker/core/model_monitor/utils.py +793 -0
- sagemaker/core/model_registry.py +480 -0
- sagemaker/core/model_uris.py +97 -0
- sagemaker/core/modules/__init__.py +19 -0
- sagemaker/core/modules/configs.py +226 -0
- sagemaker/core/modules/constants.py +37 -0
- sagemaker/core/modules/distributed.py +182 -0
- sagemaker/core/modules/local_core/__init__.py +0 -0
- sagemaker/core/modules/local_core/local_container.py +605 -0
- sagemaker/core/modules/templates.py +83 -0
- sagemaker/core/modules/train/__init__.py +14 -0
- sagemaker/core/modules/train/container_drivers/__init__.py +14 -0
- sagemaker/core/modules/train/container_drivers/common/__init__.py +14 -0
- sagemaker/core/modules/train/container_drivers/common/utils.py +213 -0
- sagemaker/core/modules/train/container_drivers/distributed_drivers/__init__.py +14 -0
- sagemaker/core/modules/train/container_drivers/distributed_drivers/basic_script_driver.py +81 -0
- sagemaker/core/modules/train/container_drivers/distributed_drivers/mpi_driver.py +123 -0
- sagemaker/core/modules/train/container_drivers/distributed_drivers/mpi_utils.py +302 -0
- sagemaker/core/modules/train/container_drivers/distributed_drivers/torchrun_driver.py +129 -0
- sagemaker/core/modules/train/container_drivers/scripts/__init__.py +14 -0
- sagemaker/core/modules/train/container_drivers/scripts/environment.py +305 -0
- sagemaker/core/modules/train/sm_recipes/__init__.py +0 -0
- sagemaker/core/modules/train/sm_recipes/utils.py +330 -0
- sagemaker/core/modules/types.py +19 -0
- sagemaker/core/modules/utils.py +194 -0
- sagemaker/core/network.py +185 -0
- sagemaker/core/parameter.py +173 -0
- sagemaker/core/payloads.py +185 -0
- sagemaker/core/processing.py +1597 -0
- sagemaker/core/remote_function/__init__.py +19 -0
- sagemaker/core/remote_function/checkpoint_location.py +47 -0
- sagemaker/core/remote_function/client.py +1285 -0
- sagemaker/core/remote_function/core/__init__.py +0 -0
- sagemaker/core/remote_function/core/_custom_dispatch_table.py +72 -0
- sagemaker/core/remote_function/core/pipeline_variables.py +353 -0
- sagemaker/core/remote_function/core/serialization.py +422 -0
- sagemaker/core/remote_function/core/stored_function.py +226 -0
- sagemaker/core/remote_function/custom_file_filter.py +128 -0
- sagemaker/core/remote_function/errors.py +104 -0
- sagemaker/core/remote_function/invoke_function.py +172 -0
- sagemaker/core/remote_function/job.py +2140 -0
- sagemaker/core/remote_function/logging_config.py +38 -0
- sagemaker/core/remote_function/runtime_environment/__init__.py +14 -0
- sagemaker/core/remote_function/runtime_environment/bootstrap_runtime_environment.py +605 -0
- sagemaker/core/remote_function/runtime_environment/mpi_utils_remote.py +252 -0
- sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py +554 -0
- sagemaker/core/remote_function/runtime_environment/spark_app.py +18 -0
- sagemaker/core/remote_function/spark_config.py +149 -0
- sagemaker/core/resource_requirements.py +168 -0
- {sagemaker_core/main → sagemaker/core}/resources.py +20121 -11728
- sagemaker/core/s3/__init__.py +41 -0
- sagemaker/core/s3/client.py +367 -0
- sagemaker/core/s3/utils.py +175 -0
- sagemaker/core/script_uris.py +93 -0
- sagemaker/core/serializers/__init__.py +11 -0
- sagemaker/core/serializers/base.py +510 -0
- sagemaker/core/serializers/implementations.py +159 -0
- sagemaker/core/serializers/utils.py +223 -0
- sagemaker/core/serverless_inference_config.py +63 -0
- sagemaker/core/session_settings.py +55 -0
- sagemaker/core/shapes/__init__.py +3 -0
- sagemaker/core/shapes/model_card_shapes.py +159 -0
- {sagemaker_core/main → sagemaker/core/shapes}/shapes.py +6384 -1865
- sagemaker/core/spark/__init__.py +16 -0
- sagemaker/core/spark/defaults.py +16 -0
- sagemaker/core/spark/processing.py +1380 -0
- sagemaker/core/telemetry/__init__.py +23 -0
- sagemaker/core/telemetry/constants.py +84 -0
- sagemaker/core/telemetry/telemetry_logging.py +284 -0
- sagemaker/core/tools/__init__.py +1 -0
- {sagemaker_core → sagemaker/core}/tools/codegen.py +4 -4
- {sagemaker_core → sagemaker/core}/tools/constants.py +23 -15
- {sagemaker_core → sagemaker/core}/tools/data_extractor.py +1 -1
- {sagemaker_core → sagemaker/core}/tools/method.py +1 -1
- sagemaker/core/tools/model_card/generate_model_card_from_schema.py +562 -0
- {sagemaker_core → sagemaker/core}/tools/resources_codegen.py +165 -98
- {sagemaker_core → sagemaker/core}/tools/resources_extractor.py +5 -13
- {sagemaker_core → sagemaker/core}/tools/shapes_codegen.py +16 -17
- {sagemaker_core → sagemaker/core}/tools/shapes_extractor.py +29 -67
- {sagemaker_core → sagemaker/core}/tools/templates.py +39 -17
- sagemaker/core/training/__init__.py +14 -0
- sagemaker/core/training/configs.py +333 -0
- sagemaker/core/training/constants.py +37 -0
- sagemaker/core/training/utils.py +77 -0
- sagemaker/core/training_compiler/__init__.py +16 -0
- sagemaker/core/training_compiler/config.py +197 -0
- sagemaker/core/training_compiler_config.py +197 -0
- sagemaker/core/transformer.py +793 -0
- sagemaker/core/user_agent.py +76 -0
- sagemaker/core/utilities/__init__.py +24 -0
- sagemaker/core/utilities/cache.py +169 -0
- sagemaker/core/utilities/search_expression.py +133 -0
- sagemaker/core/utils/__init__.py +48 -0
- sagemaker/core/utils/code_injection/__init__.py +0 -0
- {sagemaker_core/main → sagemaker/core/utils}/code_injection/codec.py +2 -2
- {sagemaker_core/main → sagemaker/core/utils}/code_injection/shape_dag.py +6479 -136
- {sagemaker_core/main → sagemaker/core/utils}/exceptions.py +8 -8
- sagemaker_core/main/default_configs_helper.py → sagemaker/core/utils/intelligent_defaults_helper.py +5 -6
- {sagemaker_core/main → sagemaker/core/utils}/logs.py +1 -2
- {sagemaker_core/main → sagemaker/core/utils}/utils.py +25 -20
- sagemaker/core/workflow/__init__.py +152 -0
- sagemaker/core/workflow/conditions.py +313 -0
- sagemaker/core/workflow/entities.py +58 -0
- sagemaker/core/workflow/execution_variables.py +89 -0
- sagemaker/core/workflow/functions.py +193 -0
- sagemaker/core/workflow/parameters.py +222 -0
- sagemaker/core/workflow/pipeline_context.py +394 -0
- sagemaker/core/workflow/pipeline_definition_config.py +31 -0
- sagemaker/core/workflow/properties.py +285 -0
- sagemaker/core/workflow/step_outputs.py +65 -0
- sagemaker/core/workflow/utilities.py +507 -0
- sagemaker/lineage/__init__.py +33 -0
- sagemaker/lineage/action.py +28 -0
- sagemaker/lineage/artifact.py +28 -0
- sagemaker/lineage/context.py +28 -0
- sagemaker/lineage/lineage_trial_component.py +28 -0
- {sagemaker_core-1.0.47.dist-info → sagemaker_core-2.1.1.dist-info}/METADATA +28 -9
- sagemaker_core-2.1.1.dist-info/RECORD +355 -0
- sagemaker_core-2.1.1.dist-info/top_level.txt +1 -0
- sagemaker_core/__init__.py +0 -4
- sagemaker_core/_version.py +0 -3
- sagemaker_core/helper/session_helper.py +0 -769
- sagemaker_core/resources/__init__.py +0 -1
- sagemaker_core/shapes/__init__.py +0 -1
- sagemaker_core/tools/__init__.py +0 -1
- sagemaker_core-1.0.47.dist-info/RECORD +0 -35
- sagemaker_core-1.0.47.dist-info/top_level.txt +0 -1
- {sagemaker_core → sagemaker/core}/helper/__init__.py +0 -0
- {sagemaker_core/main → sagemaker/core/huggingface/training_compiler}/__init__.py +0 -0
- {sagemaker_core/main/code_injection → sagemaker/core/jumpstart/factory}/__init__.py +0 -0
- {sagemaker_core/main → sagemaker/core/utils}/code_injection/base.py +0 -0
- {sagemaker_core/main → sagemaker/core/utils}/code_injection/constants.py +0 -0
- {sagemaker_core/main → sagemaker/core/utils}/user_agent.py +0 -0
- {sagemaker_core-1.0.47.dist-info → sagemaker_core-2.1.1.dist-info}/WHEEL +0 -0
- {sagemaker_core-1.0.47.dist-info → sagemaker_core-2.1.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
"""This module contains code to create and manage SageMaker ``Artifact``."""
|
|
14
|
+
from __future__ import absolute_import
|
|
15
|
+
|
|
16
|
+
from typing import Optional, Iterator
|
|
17
|
+
from datetime import datetime
|
|
18
|
+
import logging
|
|
19
|
+
|
|
20
|
+
from sagemaker.core.apiutils import _base_types
|
|
21
|
+
from sagemaker.core.lineage import _api_types
|
|
22
|
+
from sagemaker.core.lineage._api_types import AssociationSummary
|
|
23
|
+
from sagemaker.core.common_utils import format_tags
|
|
24
|
+
|
|
25
|
+
logger = logging.getLogger(__name__)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class Association(_base_types.Record):
|
|
29
|
+
"""An Amazon SageMaker artifact, which is part of a SageMaker lineage.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
.. code-block:: python
|
|
33
|
+
|
|
34
|
+
from sagemaker.lineage import association
|
|
35
|
+
|
|
36
|
+
my_association = association.Association.create(
|
|
37
|
+
source_arn=artifact_arn,
|
|
38
|
+
destination_arn=trial_component_arn,
|
|
39
|
+
association_type='ContributedTo')
|
|
40
|
+
|
|
41
|
+
for assoctn in association.Association.list():
|
|
42
|
+
print(assoctn)
|
|
43
|
+
|
|
44
|
+
my_association.delete()
|
|
45
|
+
|
|
46
|
+
Attributes:
|
|
47
|
+
source_arn (str): The ARN of the source entity.
|
|
48
|
+
source_type (str): The type of the source entity.
|
|
49
|
+
destination_arn (str): The ARN of the destination entity.
|
|
50
|
+
destination_type (str): The type of the destination entity.
|
|
51
|
+
association_type (str): the type of the association.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
source_arn: str = None
|
|
55
|
+
destination_arn: str = None
|
|
56
|
+
|
|
57
|
+
_boto_create_method: str = "add_association"
|
|
58
|
+
_boto_delete_method: str = "delete_association"
|
|
59
|
+
|
|
60
|
+
_custom_boto_types: dict = {}
|
|
61
|
+
|
|
62
|
+
_boto_delete_members = [
|
|
63
|
+
"source_arn",
|
|
64
|
+
"destination_arn",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
def delete(self):
|
|
68
|
+
"""Delete this Association from SageMaker."""
|
|
69
|
+
self._invoke_api(self._boto_delete_method, self._boto_delete_members)
|
|
70
|
+
|
|
71
|
+
def set_tag(self, tag=None):
|
|
72
|
+
"""Add a tag to the object.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
tag (obj): Key value pair to set tag.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
list({str:str}): a list of key value pairs
|
|
79
|
+
"""
|
|
80
|
+
logger.warning(
|
|
81
|
+
"set_tag on Association is deprecated. Use set_tag on the source or destination\
|
|
82
|
+
entity instead."
|
|
83
|
+
)
|
|
84
|
+
return self._set_tags(resource_arn=self.source_arn, tags=[tag])
|
|
85
|
+
|
|
86
|
+
def set_tags(self, tags=None):
|
|
87
|
+
"""Add tags to the object.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
tags ([{key:value}]): list of key value pairs.
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
list({str:str}): a list of key value pairs
|
|
94
|
+
"""
|
|
95
|
+
logger.warning(
|
|
96
|
+
"set_tags on Association is deprecated. Use set_tags on the source or destination\
|
|
97
|
+
entity instead."
|
|
98
|
+
)
|
|
99
|
+
return self._set_tags(resource_arn=self.source_arn, tags=format_tags(tags))
|
|
100
|
+
|
|
101
|
+
@classmethod
|
|
102
|
+
def create(
|
|
103
|
+
cls,
|
|
104
|
+
source_arn: str,
|
|
105
|
+
destination_arn: str,
|
|
106
|
+
association_type: str = None,
|
|
107
|
+
sagemaker_session=None,
|
|
108
|
+
) -> "Association":
|
|
109
|
+
"""Add an association and return an ``Association`` object representing it.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
source_arn (str): The ARN of the source.
|
|
113
|
+
destination_arn (str): The ARN of the destination.
|
|
114
|
+
association_type (str): The type of the association. ContributedTo, AssociatedWith,
|
|
115
|
+
DerivedFrom, or Produced.
|
|
116
|
+
sagemaker_session (sagemaker.session.Session): Session object which
|
|
117
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
118
|
+
AWS services needed. If not specified, one is created using the
|
|
119
|
+
default AWS configuration chain.
|
|
120
|
+
|
|
121
|
+
Returns:
|
|
122
|
+
association: A SageMaker ``Association`` object.
|
|
123
|
+
"""
|
|
124
|
+
return super(Association, cls)._construct(
|
|
125
|
+
cls._boto_create_method,
|
|
126
|
+
source_arn=source_arn,
|
|
127
|
+
destination_arn=destination_arn,
|
|
128
|
+
association_type=association_type,
|
|
129
|
+
sagemaker_session=sagemaker_session,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def list(
|
|
134
|
+
cls,
|
|
135
|
+
source_arn: str = None,
|
|
136
|
+
destination_arn: str = None,
|
|
137
|
+
source_type: str = None,
|
|
138
|
+
destination_type: str = None,
|
|
139
|
+
association_type: str = None,
|
|
140
|
+
created_after: Optional[datetime] = None,
|
|
141
|
+
created_before: Optional[datetime] = None,
|
|
142
|
+
sort_by: Optional[str] = None,
|
|
143
|
+
sort_order: Optional[str] = None,
|
|
144
|
+
max_results: Optional[int] = None,
|
|
145
|
+
next_token: Optional[str] = None,
|
|
146
|
+
sagemaker_session=None,
|
|
147
|
+
) -> Iterator[AssociationSummary]:
|
|
148
|
+
"""Return a list of context summaries.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
source_arn (str): The ARN of the source entity.
|
|
152
|
+
destination_arn (str): The ARN of the destination entity.
|
|
153
|
+
source_type (str): The type of the source entity.
|
|
154
|
+
destination_type (str): The type of the destination entity.
|
|
155
|
+
association_type (str): The type of the association.
|
|
156
|
+
created_after (datetime.datetime, optional): Return contexts created after this
|
|
157
|
+
instant.
|
|
158
|
+
created_before (datetime.datetime, optional): Return contexts created before this
|
|
159
|
+
instant.
|
|
160
|
+
sort_by (str, optional): Which property to sort results by.
|
|
161
|
+
One of 'SourceArn', 'CreatedBefore', 'CreatedAfter'
|
|
162
|
+
sort_order (str, optional): One of 'Ascending', or 'Descending'.
|
|
163
|
+
max_results (int, optional): maximum number of contexts to retrieve
|
|
164
|
+
next_token (str, optional): token for next page of results
|
|
165
|
+
sagemaker_session (sagemaker.session.Session): Session object which
|
|
166
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
167
|
+
AWS services needed. If not specified, one is created using the
|
|
168
|
+
default AWS configuration chain.
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
collections.Iterator[AssociationSummary]: An iterator
|
|
172
|
+
over ``AssociationSummary`` objects.
|
|
173
|
+
"""
|
|
174
|
+
return super(Association, cls)._list(
|
|
175
|
+
"list_associations",
|
|
176
|
+
_api_types.AssociationSummary.from_boto,
|
|
177
|
+
"AssociationSummaries",
|
|
178
|
+
source_arn=source_arn,
|
|
179
|
+
destination_arn=destination_arn,
|
|
180
|
+
source_type=source_type,
|
|
181
|
+
destination_type=destination_type,
|
|
182
|
+
association_type=association_type,
|
|
183
|
+
created_after=created_after,
|
|
184
|
+
created_before=created_before,
|
|
185
|
+
sort_by=sort_by,
|
|
186
|
+
sort_order=sort_order,
|
|
187
|
+
max_results=max_results,
|
|
188
|
+
next_token=next_token,
|
|
189
|
+
sagemaker_session=sagemaker_session,
|
|
190
|
+
)
|
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
"""This module contains code to create and manage SageMaker ``Context``."""
|
|
14
|
+
from __future__ import absolute_import
|
|
15
|
+
|
|
16
|
+
from datetime import datetime
|
|
17
|
+
from typing import Iterator, Optional, List
|
|
18
|
+
|
|
19
|
+
from sagemaker.core.apiutils import _base_types
|
|
20
|
+
from sagemaker.core.lineage import (
|
|
21
|
+
_api_types,
|
|
22
|
+
_utils,
|
|
23
|
+
association,
|
|
24
|
+
)
|
|
25
|
+
from sagemaker.core.lineage._api_types import ContextSummary
|
|
26
|
+
from sagemaker.core.lineage.query import (
|
|
27
|
+
LineageQuery,
|
|
28
|
+
LineageFilter,
|
|
29
|
+
LineageSourceEnum,
|
|
30
|
+
LineageEntityEnum,
|
|
31
|
+
LineageQueryDirectionEnum,
|
|
32
|
+
)
|
|
33
|
+
from sagemaker.core.lineage.artifact import Artifact
|
|
34
|
+
from sagemaker.core.lineage.action import Action
|
|
35
|
+
from sagemaker.core.lineage.lineage_trial_component import LineageTrialComponent
|
|
36
|
+
from sagemaker.core.common_utils import format_tags
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Context(_base_types.Record):
|
|
40
|
+
"""An Amazon SageMaker context, which is part of a SageMaker lineage.
|
|
41
|
+
|
|
42
|
+
Attributes:
|
|
43
|
+
context_arn (str): The ARN of the context.
|
|
44
|
+
context_name (str): The name of the context.
|
|
45
|
+
context_type (str): The type of the context.
|
|
46
|
+
description (str): A description of the context.
|
|
47
|
+
source (obj): The source of the context with a URI and type.
|
|
48
|
+
properties (dict): Dictionary of properties.
|
|
49
|
+
tags (List[dict[str, str]]): A list of tags to associate with the context.
|
|
50
|
+
creation_time (datetime): When the context was created.
|
|
51
|
+
created_by (obj): Contextual info on which account created the context.
|
|
52
|
+
last_modified_time (datetime): When the context was last modified.
|
|
53
|
+
last_modified_by (obj): Contextual info on which account created the context.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
context_arn: str = None
|
|
57
|
+
context_name: str = None
|
|
58
|
+
context_type: str = None
|
|
59
|
+
properties: dict = None
|
|
60
|
+
tags: list = None
|
|
61
|
+
creation_time: datetime = None
|
|
62
|
+
created_by: str = None
|
|
63
|
+
last_modified_time: datetime = None
|
|
64
|
+
last_modified_by: str = None
|
|
65
|
+
|
|
66
|
+
_boto_load_method: str = "describe_context"
|
|
67
|
+
_boto_create_method: str = "create_context"
|
|
68
|
+
_boto_update_method: str = "update_context"
|
|
69
|
+
_boto_delete_method: str = "delete_context"
|
|
70
|
+
|
|
71
|
+
_custom_boto_types = {
|
|
72
|
+
"source": (_api_types.ContextSource, False),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_boto_update_members = [
|
|
76
|
+
"context_name",
|
|
77
|
+
"description",
|
|
78
|
+
"properties",
|
|
79
|
+
"properties_to_remove",
|
|
80
|
+
]
|
|
81
|
+
_boto_delete_members = ["context_name"]
|
|
82
|
+
|
|
83
|
+
def save(self) -> "Context":
|
|
84
|
+
"""Save the state of this Context to SageMaker.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
obj: boto API response.
|
|
88
|
+
"""
|
|
89
|
+
return self._invoke_api(self._boto_update_method, self._boto_update_members)
|
|
90
|
+
|
|
91
|
+
def delete(self, disassociate: bool = False):
|
|
92
|
+
"""Delete the context object.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
disassociate (bool): When set to true, disassociate incoming and outgoing association.
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
obj: boto API response.
|
|
99
|
+
"""
|
|
100
|
+
if disassociate:
|
|
101
|
+
_utils._disassociate(
|
|
102
|
+
source_arn=self.context_arn, sagemaker_session=self.sagemaker_session
|
|
103
|
+
)
|
|
104
|
+
_utils._disassociate(
|
|
105
|
+
destination_arn=self.context_arn,
|
|
106
|
+
sagemaker_session=self.sagemaker_session,
|
|
107
|
+
)
|
|
108
|
+
return self._invoke_api(self._boto_delete_method, self._boto_delete_members)
|
|
109
|
+
|
|
110
|
+
def set_tag(self, tag=None):
|
|
111
|
+
"""Add a tag to the object.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
tag (obj): Key value pair to set tag.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
list({str:str}): a list of key value pairs
|
|
118
|
+
"""
|
|
119
|
+
return self._set_tags(resource_arn=self.context_arn, tags=[tag])
|
|
120
|
+
|
|
121
|
+
def set_tags(self, tags=None):
|
|
122
|
+
"""Add tags to the object.
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
tags ([{key:value}]): list of key value pairs.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
list({str:str}): a list of key value pairs
|
|
129
|
+
"""
|
|
130
|
+
return self._set_tags(resource_arn=self.context_arn, tags=format_tags(tags))
|
|
131
|
+
|
|
132
|
+
@classmethod
|
|
133
|
+
def load(cls, context_name: str, sagemaker_session=None) -> "Context":
|
|
134
|
+
"""Load an existing context and return an ``Context`` object representing it.
|
|
135
|
+
|
|
136
|
+
Examples:
|
|
137
|
+
.. code-block:: python
|
|
138
|
+
|
|
139
|
+
from sagemaker.lineage import context
|
|
140
|
+
|
|
141
|
+
my_context = context.Context.create(
|
|
142
|
+
context_name='MyContext',
|
|
143
|
+
context_type='Endpoint',
|
|
144
|
+
source_uri='arn:aws:...')
|
|
145
|
+
|
|
146
|
+
my_context.properties["added"] = "property"
|
|
147
|
+
my_context.save()
|
|
148
|
+
|
|
149
|
+
for ctx in context.Context.list():
|
|
150
|
+
print(ctx)
|
|
151
|
+
|
|
152
|
+
my_context.delete()
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
context_name (str): Name of the context
|
|
156
|
+
sagemaker_session (sagemaker.session.Session): Session object which
|
|
157
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
158
|
+
AWS services needed. If not specified, one is created using the
|
|
159
|
+
default AWS configuration chain.
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
Context: A SageMaker ``Context`` object
|
|
163
|
+
"""
|
|
164
|
+
context = cls._construct(
|
|
165
|
+
cls._boto_load_method,
|
|
166
|
+
context_name=context_name,
|
|
167
|
+
sagemaker_session=sagemaker_session,
|
|
168
|
+
)
|
|
169
|
+
return context
|
|
170
|
+
|
|
171
|
+
@classmethod
|
|
172
|
+
def create(
|
|
173
|
+
cls,
|
|
174
|
+
context_name: str = None,
|
|
175
|
+
source_uri: str = None,
|
|
176
|
+
source_type: str = None,
|
|
177
|
+
context_type: str = None,
|
|
178
|
+
description: str = None,
|
|
179
|
+
properties: dict = None,
|
|
180
|
+
tags: dict = None,
|
|
181
|
+
sagemaker_session=None,
|
|
182
|
+
) -> "Context":
|
|
183
|
+
"""Create a context and return a ``Context`` object representing it.
|
|
184
|
+
|
|
185
|
+
Args:
|
|
186
|
+
context_name (str): The name of the context.
|
|
187
|
+
source_uri (str): The source URI of the context.
|
|
188
|
+
source_type (str): The type of the source.
|
|
189
|
+
context_type (str): The type of the context.
|
|
190
|
+
description (str): Description of the context.
|
|
191
|
+
properties (dict): Metadata associated with the context.
|
|
192
|
+
tags (dict): Tags to add to the context.
|
|
193
|
+
sagemaker_session (sagemaker.session.Session): Session object which
|
|
194
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
195
|
+
AWS services needed. If not specified, one is created using the
|
|
196
|
+
default AWS configuration chain.
|
|
197
|
+
|
|
198
|
+
Returns:
|
|
199
|
+
Context: A SageMaker ``Context`` object.
|
|
200
|
+
"""
|
|
201
|
+
return super(Context, cls)._construct(
|
|
202
|
+
cls._boto_create_method,
|
|
203
|
+
context_name=context_name,
|
|
204
|
+
source=_api_types.ContextSource(source_uri=source_uri, source_type=source_type),
|
|
205
|
+
context_type=context_type,
|
|
206
|
+
description=description,
|
|
207
|
+
properties=properties,
|
|
208
|
+
tags=tags,
|
|
209
|
+
sagemaker_session=sagemaker_session,
|
|
210
|
+
)
|
|
211
|
+
|
|
212
|
+
@classmethod
|
|
213
|
+
def list(
|
|
214
|
+
cls,
|
|
215
|
+
source_uri: Optional[str] = None,
|
|
216
|
+
context_type: Optional[str] = None,
|
|
217
|
+
created_after: Optional[datetime] = None,
|
|
218
|
+
created_before: Optional[datetime] = None,
|
|
219
|
+
sort_by: Optional[str] = None,
|
|
220
|
+
sort_order: Optional[str] = None,
|
|
221
|
+
max_results: Optional[int] = None,
|
|
222
|
+
next_token: Optional[str] = None,
|
|
223
|
+
sagemaker_session=None,
|
|
224
|
+
) -> Iterator[ContextSummary]:
|
|
225
|
+
"""Return a list of context summaries.
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
source_uri (str, optional): A source URI.
|
|
229
|
+
context_type (str, optional): An context type.
|
|
230
|
+
created_before (datetime.datetime, optional): Return contexts created before this
|
|
231
|
+
instant.
|
|
232
|
+
created_after (datetime.datetime, optional): Return contexts created after this instant.
|
|
233
|
+
sort_by (str, optional): Which property to sort results by.
|
|
234
|
+
One of 'SourceArn', 'CreatedBefore', 'CreatedAfter'
|
|
235
|
+
sort_order (str, optional): One of 'Ascending', or 'Descending'.
|
|
236
|
+
max_results (int, optional): maximum number of contexts to retrieve
|
|
237
|
+
next_token (str, optional): token for next page of results
|
|
238
|
+
sagemaker_session (sagemaker.session.Session): Session object which
|
|
239
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
240
|
+
AWS services needed. If not specified, one is created using the
|
|
241
|
+
default AWS configuration chain.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
collections.Iterator[ContextSummary]: An iterator
|
|
245
|
+
over ``ContextSummary`` objects.
|
|
246
|
+
"""
|
|
247
|
+
return super(Context, cls)._list(
|
|
248
|
+
"list_contexts",
|
|
249
|
+
_api_types.ContextSummary.from_boto,
|
|
250
|
+
"ContextSummaries",
|
|
251
|
+
source_uri=source_uri,
|
|
252
|
+
context_type=context_type,
|
|
253
|
+
created_before=created_before,
|
|
254
|
+
created_after=created_after,
|
|
255
|
+
sort_by=sort_by,
|
|
256
|
+
sort_order=sort_order,
|
|
257
|
+
max_results=max_results,
|
|
258
|
+
next_token=next_token,
|
|
259
|
+
sagemaker_session=sagemaker_session,
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
def actions(self, direction: LineageQueryDirectionEnum) -> List[Action]:
|
|
263
|
+
"""Use the lineage query to retrieve actions that use this context.
|
|
264
|
+
|
|
265
|
+
Args:
|
|
266
|
+
direction (LineageQueryDirectionEnum): The query direction.
|
|
267
|
+
|
|
268
|
+
Returns:
|
|
269
|
+
list of Actions: Actions.
|
|
270
|
+
"""
|
|
271
|
+
query_filter = LineageFilter(entities=[LineageEntityEnum.ACTION])
|
|
272
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
273
|
+
start_arns=[self.context_arn],
|
|
274
|
+
query_filter=query_filter,
|
|
275
|
+
direction=direction,
|
|
276
|
+
include_edges=False,
|
|
277
|
+
)
|
|
278
|
+
return [vertex.to_lineage_object() for vertex in query_result.vertices]
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
class EndpointContext(Context):
|
|
282
|
+
"""An Amazon SageMaker endpoint context, which is part of a SageMaker lineage."""
|
|
283
|
+
|
|
284
|
+
def models(self) -> List[association.Association]:
|
|
285
|
+
"""Use Lineage API to get all models deployed by this endpoint.
|
|
286
|
+
|
|
287
|
+
Returns:
|
|
288
|
+
list of Associations: Associations that destination represents an endpoint's model.
|
|
289
|
+
"""
|
|
290
|
+
endpoint_actions: Iterator = association.Association.list(
|
|
291
|
+
sagemaker_session=self.sagemaker_session,
|
|
292
|
+
source_arn=self.context_arn,
|
|
293
|
+
destination_type="ModelDeployment",
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
model_list: list = [
|
|
297
|
+
model
|
|
298
|
+
for endpoint_action in endpoint_actions
|
|
299
|
+
for model in association.Association.list(
|
|
300
|
+
source_arn=endpoint_action.destination_arn,
|
|
301
|
+
destination_type="Model",
|
|
302
|
+
sagemaker_session=self.sagemaker_session,
|
|
303
|
+
)
|
|
304
|
+
]
|
|
305
|
+
return model_list
|
|
306
|
+
|
|
307
|
+
def models_v2(
|
|
308
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.DESCENDANTS
|
|
309
|
+
) -> List[Artifact]:
|
|
310
|
+
"""Use the lineage query to retrieve downstream model artifacts that use this endpoint.
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
list of Artifacts: Artifacts representing a model.
|
|
317
|
+
"""
|
|
318
|
+
# Firstly query out the model_deployment vertices
|
|
319
|
+
query_filter = LineageFilter(
|
|
320
|
+
entities=[LineageEntityEnum.ACTION], sources=[LineageSourceEnum.MODEL_DEPLOYMENT]
|
|
321
|
+
)
|
|
322
|
+
model_deployment_query_result = LineageQuery(self.sagemaker_session).query(
|
|
323
|
+
start_arns=[self.context_arn],
|
|
324
|
+
query_filter=query_filter,
|
|
325
|
+
direction=direction,
|
|
326
|
+
include_edges=False,
|
|
327
|
+
)
|
|
328
|
+
if not model_deployment_query_result:
|
|
329
|
+
return []
|
|
330
|
+
|
|
331
|
+
model_deployment_vertices: [] = model_deployment_query_result.vertices
|
|
332
|
+
|
|
333
|
+
# Secondary query model based on model deployment
|
|
334
|
+
model_vertices = []
|
|
335
|
+
for vertex in model_deployment_vertices:
|
|
336
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
337
|
+
start_arns=[vertex.arn],
|
|
338
|
+
query_filter=LineageFilter(
|
|
339
|
+
entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.MODEL]
|
|
340
|
+
),
|
|
341
|
+
direction=LineageQueryDirectionEnum.DESCENDANTS,
|
|
342
|
+
include_edges=False,
|
|
343
|
+
)
|
|
344
|
+
model_vertices.extend(query_result.vertices)
|
|
345
|
+
|
|
346
|
+
if not model_vertices:
|
|
347
|
+
return []
|
|
348
|
+
|
|
349
|
+
model_artifacts = []
|
|
350
|
+
for vertex in model_vertices:
|
|
351
|
+
lineage_object = vertex.to_lineage_object()
|
|
352
|
+
model_artifacts.append(lineage_object)
|
|
353
|
+
|
|
354
|
+
return model_artifacts
|
|
355
|
+
|
|
356
|
+
def dataset_artifacts(
|
|
357
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
358
|
+
) -> List[Artifact]:
|
|
359
|
+
"""Use the lineage query to retrieve datasets that use this endpoint.
|
|
360
|
+
|
|
361
|
+
Args:
|
|
362
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
363
|
+
|
|
364
|
+
Returns:
|
|
365
|
+
list of Artifacts: Artifacts representing a dataset.
|
|
366
|
+
"""
|
|
367
|
+
query_filter = LineageFilter(
|
|
368
|
+
entities=[LineageEntityEnum.ARTIFACT], sources=[LineageSourceEnum.DATASET]
|
|
369
|
+
)
|
|
370
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
371
|
+
start_arns=[self.context_arn],
|
|
372
|
+
query_filter=query_filter,
|
|
373
|
+
direction=direction,
|
|
374
|
+
include_edges=False,
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
return [vertex.to_lineage_object() for vertex in query_result.vertices]
|
|
378
|
+
|
|
379
|
+
def training_job_arns(
|
|
380
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
381
|
+
) -> List[str]:
|
|
382
|
+
"""Get ARNs for all training jobs that appear in the endpoint's lineage.
|
|
383
|
+
|
|
384
|
+
Args:
|
|
385
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
386
|
+
|
|
387
|
+
Returns:
|
|
388
|
+
list of str: Training job ARNs.
|
|
389
|
+
"""
|
|
390
|
+
query_filter = LineageFilter(
|
|
391
|
+
entities=[LineageEntityEnum.TRIAL_COMPONENT], sources=[LineageSourceEnum.TRAINING_JOB]
|
|
392
|
+
)
|
|
393
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
394
|
+
start_arns=[self.context_arn],
|
|
395
|
+
query_filter=query_filter,
|
|
396
|
+
direction=direction,
|
|
397
|
+
include_edges=False,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
training_job_arns = []
|
|
401
|
+
for vertex in query_result.vertices:
|
|
402
|
+
trial_component_name = _utils.get_resource_name_from_arn(vertex.arn)
|
|
403
|
+
trial_component = self.sagemaker_session.sagemaker_client.describe_trial_component(
|
|
404
|
+
TrialComponentName=trial_component_name
|
|
405
|
+
)
|
|
406
|
+
training_job_arns.append(trial_component["Source"]["SourceArn"])
|
|
407
|
+
return training_job_arns
|
|
408
|
+
|
|
409
|
+
def processing_jobs(
|
|
410
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
411
|
+
) -> List[LineageTrialComponent]:
|
|
412
|
+
"""Use the lineage query to retrieve processing jobs that use this endpoint.
|
|
413
|
+
|
|
414
|
+
Args:
|
|
415
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
416
|
+
|
|
417
|
+
Returns:
|
|
418
|
+
list of LineageTrialComponent: Lineage trial component that represent Processing jobs.
|
|
419
|
+
"""
|
|
420
|
+
query_filter = LineageFilter(
|
|
421
|
+
entities=[LineageEntityEnum.TRIAL_COMPONENT], sources=[LineageSourceEnum.PROCESSING_JOB]
|
|
422
|
+
)
|
|
423
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
424
|
+
start_arns=[self.context_arn],
|
|
425
|
+
query_filter=query_filter,
|
|
426
|
+
direction=direction,
|
|
427
|
+
include_edges=False,
|
|
428
|
+
)
|
|
429
|
+
return [vertex.to_lineage_object() for vertex in query_result.vertices]
|
|
430
|
+
|
|
431
|
+
def transform_jobs(
|
|
432
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
433
|
+
) -> List[LineageTrialComponent]:
|
|
434
|
+
"""Use the lineage query to retrieve transform jobs that use this endpoint.
|
|
435
|
+
|
|
436
|
+
Args:
|
|
437
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
438
|
+
|
|
439
|
+
Returns:
|
|
440
|
+
list of LineageTrialComponent: Lineage trial component that represent Transform jobs.
|
|
441
|
+
"""
|
|
442
|
+
query_filter = LineageFilter(
|
|
443
|
+
entities=[LineageEntityEnum.TRIAL_COMPONENT], sources=[LineageSourceEnum.TRANSFORM_JOB]
|
|
444
|
+
)
|
|
445
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
446
|
+
start_arns=[self.context_arn],
|
|
447
|
+
query_filter=query_filter,
|
|
448
|
+
direction=direction,
|
|
449
|
+
include_edges=False,
|
|
450
|
+
)
|
|
451
|
+
return [vertex.to_lineage_object() for vertex in query_result.vertices]
|
|
452
|
+
|
|
453
|
+
def trial_components(
|
|
454
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
455
|
+
) -> List[LineageTrialComponent]:
|
|
456
|
+
"""Use the lineage query to retrieve trial components that use this endpoint.
|
|
457
|
+
|
|
458
|
+
Args:
|
|
459
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
460
|
+
|
|
461
|
+
Returns:
|
|
462
|
+
list of LineageTrialComponent: Lineage trial component.
|
|
463
|
+
"""
|
|
464
|
+
query_filter = LineageFilter(entities=[LineageEntityEnum.TRIAL_COMPONENT])
|
|
465
|
+
query_result = LineageQuery(self.sagemaker_session).query(
|
|
466
|
+
start_arns=[self.context_arn],
|
|
467
|
+
query_filter=query_filter,
|
|
468
|
+
direction=direction,
|
|
469
|
+
include_edges=False,
|
|
470
|
+
)
|
|
471
|
+
return [vertex.to_lineage_object() for vertex in query_result.vertices]
|
|
472
|
+
|
|
473
|
+
def pipeline_execution_arn(
|
|
474
|
+
self, direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS
|
|
475
|
+
) -> str:
|
|
476
|
+
"""Get the ARN for the pipeline execution associated with this endpoint (if any).
|
|
477
|
+
|
|
478
|
+
Args:
|
|
479
|
+
direction (LineageQueryDirectionEnum, optional): The query direction.
|
|
480
|
+
|
|
481
|
+
Returns:
|
|
482
|
+
str: A pipeline execution ARN.
|
|
483
|
+
"""
|
|
484
|
+
training_job_arns = self.training_job_arns(direction=direction)
|
|
485
|
+
for training_job_arn in training_job_arns:
|
|
486
|
+
tags = self.sagemaker_session.sagemaker_client.list_tags(ResourceArn=training_job_arn)[
|
|
487
|
+
"Tags"
|
|
488
|
+
]
|
|
489
|
+
for tag in tags:
|
|
490
|
+
if tag["Key"] == "sagemaker:pipeline-execution-arn":
|
|
491
|
+
return tag["Value"]
|
|
492
|
+
|
|
493
|
+
return None
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
class ModelPackageGroup(Context):
|
|
497
|
+
"""An Amazon SageMaker model package group context, which is part of a SageMaker lineage."""
|
|
498
|
+
|
|
499
|
+
def pipeline_execution_arn(self) -> str:
|
|
500
|
+
"""Get the ARN for the pipeline execution associated with this model package group (if any).
|
|
501
|
+
|
|
502
|
+
Returns:
|
|
503
|
+
str: A pipeline execution ARN.
|
|
504
|
+
"""
|
|
505
|
+
return self.properties.get("PipelineExecutionArn")
|