sagemaker-core 1.0.62__py3-none-any.whl → 2.3.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/__init__.py +2 -0
- 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 +2399 -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 +408 -3
- 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 +247 -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 +1220 -0
- sagemaker/core/git_utils.py +415 -0
- sagemaker/core/helper/pipeline_variable.py +82 -0
- sagemaker/core/helper/session_helper.py +2977 -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 +509 -0
- sagemaker/core/image_retriever/test.py +7 -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 +770 -0
- sagemaker/core/image_uri_config/huggingface-llm.json +1267 -0
- sagemaker/core/image_uri_config/huggingface-neuron.json +52 -0
- sagemaker/core/image_uri_config/huggingface-neuronx.json +686 -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-vllm-neuronx.json +38 -0
- sagemaker/core/image_uri_config/huggingface.json +2287 -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 +252 -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 +494 -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 +972 -0
- sagemaker/core/image_uris.py +816 -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 +197 -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/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 +501 -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 +171 -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 +423 -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 +246 -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 +1497 -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 +239 -0
- sagemaker/core/modules/constants.py +37 -0
- sagemaker/core/modules/distributed.py +182 -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 +205 -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 +1599 -0
- sagemaker/core/remote_function/__init__.py +19 -0
- sagemaker/core/remote_function/checkpoint_location.py +47 -0
- sagemaker/core/remote_function/client.py +1310 -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 +347 -0
- sagemaker/core/remote_function/core/serialization.py +410 -0
- sagemaker/core/remote_function/core/stored_function.py +223 -0
- sagemaker/core/remote_function/custom_file_filter.py +128 -0
- sagemaker/core/remote_function/errors.py +102 -0
- sagemaker/core/remote_function/invoke_function.py +167 -0
- sagemaker/core/remote_function/job.py +2121 -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 +19098 -10895
- 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 +5810 -1806
- 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 +82 -0
- sagemaker/core/telemetry/telemetry_logging.py +285 -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 +345 -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 +5979 -176
- {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 +27 -22
- 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 +514 -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.62.dist-info → sagemaker_core-2.3.1.dist-info}/METADATA +28 -9
- sagemaker_core-2.3.1.dist-info/RECORD +351 -0
- sagemaker_core-2.3.1.dist-info/top_level.txt +1 -0
- 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.62.dist-info/RECORD +0 -35
- sagemaker_core-1.0.62.dist-info/top_level.txt +0 -1
- {sagemaker_core → sagemaker/core/helper}/__init__.py +0 -0
- {sagemaker_core/helper → sagemaker/core/jumpstart/factory}/__init__.py +0 -0
- {sagemaker_core/main → sagemaker/core/jumpstart/hub}/__init__.py +0 -0
- {sagemaker_core/main/code_injection → sagemaker/core/modules/local_core}/__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.62.dist-info → sagemaker_core-2.3.1.dist-info}/WHEEL +0 -0
- {sagemaker_core-1.0.62.dist-info → sagemaker_core-2.3.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
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
|
+
"""Imports the classes in this module to simplify customer imports"""
|
|
14
|
+
|
|
15
|
+
from __future__ import absolute_import
|
|
16
|
+
|
|
17
|
+
from sagemaker.core.explainer.explainer_config import ExplainerConfig # noqa: F401
|
|
18
|
+
from sagemaker.core.explainer.clarify_explainer_config import ( # noqa: F401
|
|
19
|
+
ClarifyExplainerConfig,
|
|
20
|
+
ClarifyInferenceConfig,
|
|
21
|
+
ClarifyShapConfig,
|
|
22
|
+
ClarifyShapBaselineConfig,
|
|
23
|
+
ClarifyTextConfig,
|
|
24
|
+
)
|
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
"""A member of :class:`~sagemaker.explainer.explainer_config.ExplainerConfig` that contains configuration parameters for the SageMaker Clarify explainer.""" # noqa E501 # pylint: disable=line-too-long
|
|
14
|
+
|
|
15
|
+
from __future__ import print_function, absolute_import
|
|
16
|
+
from typing import List, Optional
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ClarifyTextConfig(object):
|
|
20
|
+
"""A parameter used to configure the SageMaker Clarify explainer to treat text features as text so that explanations are provided for individual units of text. Required only for NLP explainability.""" # noqa E501 # pylint: disable=line-too-long
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
language: str,
|
|
25
|
+
granularity: str,
|
|
26
|
+
):
|
|
27
|
+
"""Initialize a config object for text explainability.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
language (str): Specifies the language of the text features in `ISO 639-1
|
|
31
|
+
<https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes>`__ or `ISO 639-3
|
|
32
|
+
<https://en.wikipedia.org/wiki/ISO_639-3>`__ code of a supported
|
|
33
|
+
language. See valid values `here
|
|
34
|
+
<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ClarifyTextConfig.html#sagemaker-Type-ClarifyTextConfig-Language>`__.
|
|
35
|
+
granularity (str): The unit of granularity for the analysis of text features. For
|
|
36
|
+
example, if the unit is ``"token"``, then each token (like a word in English) of the
|
|
37
|
+
text is treated as a feature. SHAP values are computed for each unit/feature.
|
|
38
|
+
Accepted values are ``"token"``, ``"sentence"``, or ``"paragraph"``.
|
|
39
|
+
""" # noqa E501 # pylint: disable=line-too-long
|
|
40
|
+
self.language = language
|
|
41
|
+
self.granularity = granularity
|
|
42
|
+
|
|
43
|
+
def _to_request_dict(self):
|
|
44
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
45
|
+
request_dict = {"Language": self.language, "Granularity": self.granularity}
|
|
46
|
+
return request_dict
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class ClarifyShapBaselineConfig(object):
|
|
50
|
+
"""Configuration for the SHAP baseline of the Kernal SHAP algorithm."""
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
mime_type: Optional[str] = "text/csv",
|
|
55
|
+
shap_baseline: Optional[str] = None,
|
|
56
|
+
shap_baseline_uri: Optional[str] = None,
|
|
57
|
+
):
|
|
58
|
+
"""Initialize a config object for SHAP baseline.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
mime_type (str): Optional. The MIME type of the baseline data. Choose
|
|
62
|
+
from ``"text/csv"`` or ``"application/jsonlines"``. (Default: ``"text/csv"``)
|
|
63
|
+
shap_baseline (str): Optional. The inline SHAP baseline data in string format.
|
|
64
|
+
ShapBaseline can have one or multiple records to be used as the baseline dataset.
|
|
65
|
+
The format of the SHAP baseline file should be the same format as the training
|
|
66
|
+
dataset. For example, if the training dataset is in CSV format and each record
|
|
67
|
+
contains four features, and all features are numerical, then the format of the
|
|
68
|
+
baseline data should also share these characteristics. For NLP of text columns, the
|
|
69
|
+
baseline value should be the value used to replace the unit of text specified by
|
|
70
|
+
the ``granularity`` of the
|
|
71
|
+
:class:`~sagemaker.explainer.clarify_explainer_config.ClarifyTextConfig`
|
|
72
|
+
parameter. The size limit for ``shap_baseline`` is 4 KB. Use the
|
|
73
|
+
``shap_baseline_uri`` parameter if you want to provide more than 4 KB of baseline
|
|
74
|
+
data.
|
|
75
|
+
shap_baseline_uri (str): Optional. The S3 URI where the SHAP baseline file is stored.
|
|
76
|
+
The format of the SHAP baseline file should be the same format as the format of
|
|
77
|
+
the training dataset. For example, if the training dataset is in CSV format,
|
|
78
|
+
and each record in the training dataset has four features, and all features are
|
|
79
|
+
numerical, then the baseline file should also have this same format. Each record
|
|
80
|
+
should contain only the features. If you are using a virtual private cloud (VPC),
|
|
81
|
+
the ``shap_baseline_uri`` should be accessible to the VPC.
|
|
82
|
+
"""
|
|
83
|
+
self.mime_type = mime_type
|
|
84
|
+
self.shap_baseline = shap_baseline
|
|
85
|
+
self.shap_baseline_uri = shap_baseline_uri
|
|
86
|
+
|
|
87
|
+
def _to_request_dict(self):
|
|
88
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
89
|
+
request_dict = {"MimeType": self.mime_type}
|
|
90
|
+
if self.shap_baseline is not None:
|
|
91
|
+
request_dict["ShapBaseline"] = self.shap_baseline
|
|
92
|
+
if self.shap_baseline_uri is not None:
|
|
93
|
+
request_dict["ShapBaselineUri"] = self.shap_baseline_uri
|
|
94
|
+
|
|
95
|
+
return request_dict
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class ClarifyShapConfig(object):
|
|
99
|
+
"""Configuration for SHAP analysis using SageMaker Clarify Explainer."""
|
|
100
|
+
|
|
101
|
+
def __init__(
|
|
102
|
+
self,
|
|
103
|
+
shap_baseline_config: ClarifyShapBaselineConfig,
|
|
104
|
+
number_of_samples: Optional[int] = None,
|
|
105
|
+
seed: Optional[int] = None,
|
|
106
|
+
use_logit: Optional[bool] = False,
|
|
107
|
+
text_config: Optional[ClarifyTextConfig] = None,
|
|
108
|
+
):
|
|
109
|
+
"""Initialize a config object for SHAP analysis.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
shap_baseline_config (:class:`~sagemaker.explainer.clarify_explainer_config.ClarifyShapBaselineConfig`):
|
|
113
|
+
The configuration for the SHAP baseline of the Kernal SHAP algorithm.
|
|
114
|
+
number_of_samples (int): Optional. The number of samples to be used for analysis by the
|
|
115
|
+
Kernal SHAP algorithm. The number of samples determines the size of the synthetic
|
|
116
|
+
dataset, which has an impact on latency of explainability requests. For more
|
|
117
|
+
information, see the `Synthetic data` of `Configure and create an endpoint
|
|
118
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-online-explainability-create-endpoint.html>`__.
|
|
119
|
+
seed (int): Optional. The starting value used to initialize the random number generator
|
|
120
|
+
in the explainer. Provide a value for this parameter to obtain a deterministic SHAP
|
|
121
|
+
result.
|
|
122
|
+
use_logit (bool): Optional. A Boolean toggle to indicate if you want to use the logit
|
|
123
|
+
function (true) or log-odds units (false) for model predictions. (Default: false)
|
|
124
|
+
text_config (:class:`~sagemaker.explainer.clarify_explainer_config.ClarifyTextConfig`):
|
|
125
|
+
Optional. A parameter that indicates if text features are treated as text and
|
|
126
|
+
explanations are provided for individual units of text. Required for NLP
|
|
127
|
+
explainability only.
|
|
128
|
+
""" # noqa E501 # pylint: disable=line-too-long
|
|
129
|
+
self.number_of_samples = number_of_samples
|
|
130
|
+
self.seed = seed
|
|
131
|
+
self.shap_baseline_config = shap_baseline_config
|
|
132
|
+
self.text_config = text_config
|
|
133
|
+
self.use_logit = use_logit
|
|
134
|
+
|
|
135
|
+
def _to_request_dict(self):
|
|
136
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
137
|
+
request_dict = {
|
|
138
|
+
"ShapBaselineConfig": self.shap_baseline_config._to_request_dict(),
|
|
139
|
+
"UseLogit": self.use_logit,
|
|
140
|
+
}
|
|
141
|
+
if self.number_of_samples is not None:
|
|
142
|
+
request_dict["NumberOfSamples"] = self.number_of_samples
|
|
143
|
+
|
|
144
|
+
if self.seed is not None:
|
|
145
|
+
request_dict["Seed"] = self.seed
|
|
146
|
+
|
|
147
|
+
if self.text_config is not None:
|
|
148
|
+
request_dict["TextConfig"] = self.text_config._to_request_dict()
|
|
149
|
+
|
|
150
|
+
return request_dict
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
class ClarifyInferenceConfig(object):
|
|
154
|
+
"""The inference configuration parameter for the model container."""
|
|
155
|
+
|
|
156
|
+
def __init__(
|
|
157
|
+
self,
|
|
158
|
+
feature_headers: Optional[List[str]] = None,
|
|
159
|
+
feature_types: Optional[List[str]] = None,
|
|
160
|
+
features_attribute: Optional[str] = None,
|
|
161
|
+
probability_index: Optional[int] = None,
|
|
162
|
+
probability_attribute: Optional[str] = None,
|
|
163
|
+
label_index: Optional[int] = None,
|
|
164
|
+
label_attribute: Optional[str] = None,
|
|
165
|
+
label_headers: Optional[List[str]] = None,
|
|
166
|
+
max_payload_in_mb: Optional[int] = 6,
|
|
167
|
+
max_record_count: Optional[int] = None,
|
|
168
|
+
content_template: Optional[str] = None,
|
|
169
|
+
):
|
|
170
|
+
"""Initialize a config object for model container.
|
|
171
|
+
|
|
172
|
+
Args:
|
|
173
|
+
feature_headers (list[str]): Optional. The names of the features. If provided, these are
|
|
174
|
+
included in the endpoint response payload to help readability of the
|
|
175
|
+
``InvokeEndpoint`` output.
|
|
176
|
+
feature_types (list[str]): Optional. A list of data types of the features. Applicable
|
|
177
|
+
only to NLP explainability. If provided, ``feature_types`` must have at least one
|
|
178
|
+
``'text'`` string (for example, ``['text']``). If ``feature_types`` is not provided,
|
|
179
|
+
the explainer infers the feature types based on the baseline data. The feature
|
|
180
|
+
types are included in the endpoint response payload.
|
|
181
|
+
features_attribute (str): Optional. Provides the JMESPath expression to extract the
|
|
182
|
+
features from a model container input in JSON Lines format. For example,
|
|
183
|
+
if ``features_attribute`` is the JMESPath expression ``'myfeatures'``, it extracts a
|
|
184
|
+
list of features ``[1,2,3]`` from request data ``'{"myfeatures":[1,2,3]}'``.
|
|
185
|
+
probability_index (int): Optional. A zero-based index used to extract a probability
|
|
186
|
+
value (score) or list from model container output in CSV format. If this value is
|
|
187
|
+
not provided, the entire model container output will be treated as a probability
|
|
188
|
+
value (score) or list. See examples `here
|
|
189
|
+
<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ClarifyInferenceConfig.html#sagemaker-Type-ClarifyInferenceConfig-ProbabilityIndex>`__.
|
|
190
|
+
probability_attribute (str): Optional. A JMESPath expression used to extract the
|
|
191
|
+
probability (or score) from the model container output if the model container
|
|
192
|
+
is in JSON Lines format. See examples `here
|
|
193
|
+
<https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_ClarifyInferenceConfig.html#sagemaker-Type-ClarifyInferenceConfig-ProbabilityAttribute>`__.
|
|
194
|
+
label_index (int): Optional. A zero-based index used to extract a label header or list
|
|
195
|
+
of label headers from model container output in CSV format.
|
|
196
|
+
label_attribute (str): Optional. A JMESPath expression used to locate the list of label
|
|
197
|
+
headers in the model container output.
|
|
198
|
+
label_headers (list[str]): Optional. For multiclass classification problems, the label
|
|
199
|
+
headers are the names of the classes. Otherwise, the label header is the name of
|
|
200
|
+
the predicted label. These are used to help readability for the output of the
|
|
201
|
+
``InvokeEndpoint`` API.
|
|
202
|
+
max_payload_in_mb (int): Optional. The maximum payload size (MB) allowed of a request
|
|
203
|
+
from the explainer to the model container. (Default: 6)
|
|
204
|
+
max_record_count (int): Optional. The maximum number of records in a request that the
|
|
205
|
+
model container can process when querying the model container for the predictions
|
|
206
|
+
of a `synthetic dataset
|
|
207
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-online-explainability-create-endpoint.html#clarify-online-explainability-create-endpoint-synthetic>`__.
|
|
208
|
+
A record is a unit of input data that inference can be made on, for example, a
|
|
209
|
+
single line in CSV data. If ``max_record_count`` is ``1``, the model container
|
|
210
|
+
expects one record per request. A value of 2 or greater means that the model expects
|
|
211
|
+
batch requests, which can reduce overhead and speed up the inferencing process. If
|
|
212
|
+
this parameter is not provided, the explainer will tune the record count per request
|
|
213
|
+
according to the model container's capacity at runtime.
|
|
214
|
+
content_template (str): Optional. A template string used to format a JSON record into an
|
|
215
|
+
acceptable model container input. For example, a ``ContentTemplate`` string ``'{
|
|
216
|
+
"myfeatures":$features}'`` will format a list of features ``[1,2,3]`` into the
|
|
217
|
+
record string ``'{"myfeatures":[1,2,3]}'``. Required only when the model
|
|
218
|
+
container input is in JSON Lines format.
|
|
219
|
+
""" # noqa E501 # pylint: disable=line-too-long
|
|
220
|
+
self.feature_headers = feature_headers
|
|
221
|
+
self.feature_types = feature_types
|
|
222
|
+
self.features_attribute = features_attribute
|
|
223
|
+
self.probability_index = probability_index
|
|
224
|
+
self.probability_attribute = probability_attribute
|
|
225
|
+
self.label_index = label_index
|
|
226
|
+
self.label_attribute = label_attribute
|
|
227
|
+
self.label_headers = label_headers
|
|
228
|
+
self.max_payload_in_mb = max_payload_in_mb
|
|
229
|
+
self.max_record_count = max_record_count
|
|
230
|
+
self.content_template = content_template
|
|
231
|
+
|
|
232
|
+
def _to_request_dict(self):
|
|
233
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
234
|
+
request_dict = {}
|
|
235
|
+
|
|
236
|
+
if self.feature_headers is not None and self.feature_headers:
|
|
237
|
+
request_dict["FeatureHeaders"] = self.feature_headers
|
|
238
|
+
if self.feature_types is not None:
|
|
239
|
+
request_dict["FeatureTypes"] = self.feature_types
|
|
240
|
+
if self.features_attribute is not None:
|
|
241
|
+
request_dict["FeaturesAttribute"] = self.features_attribute
|
|
242
|
+
if self.probability_index is not None:
|
|
243
|
+
request_dict["ProbabilityIndex"] = self.probability_index
|
|
244
|
+
if self.probability_attribute is not None:
|
|
245
|
+
request_dict["ProbabilityAttribute"] = self.probability_attribute
|
|
246
|
+
if self.label_index is not None:
|
|
247
|
+
request_dict["LabelIndex"] = self.label_index
|
|
248
|
+
if self.label_attribute is not None:
|
|
249
|
+
request_dict["LabelAttribute"] = self.label_attribute
|
|
250
|
+
if self.label_headers is not None:
|
|
251
|
+
request_dict["LabelHeaders"] = self.label_headers
|
|
252
|
+
if self.max_payload_in_mb is not None:
|
|
253
|
+
request_dict["MaxPayloadInMB"] = self.max_payload_in_mb
|
|
254
|
+
if self.max_record_count is not None:
|
|
255
|
+
request_dict["MaxRecordCount"] = self.max_record_count
|
|
256
|
+
if self.content_template is not None:
|
|
257
|
+
request_dict["ContentTemplate"] = self.content_template
|
|
258
|
+
return request_dict
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class ClarifyExplainerConfig(object):
|
|
262
|
+
"""The configuration parameters for the SageMaker Clarify explainer."""
|
|
263
|
+
|
|
264
|
+
def __init__(
|
|
265
|
+
self,
|
|
266
|
+
shap_config: ClarifyShapConfig,
|
|
267
|
+
enable_explanations: Optional[str] = None,
|
|
268
|
+
inference_config: Optional[ClarifyInferenceConfig] = None,
|
|
269
|
+
):
|
|
270
|
+
"""Initialize a config object for online explainability with AWS SageMaker Clarify.
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
shap_config (:class:`~sagemaker.explainer.clarify_explainer_config.ClarifyShapConfig`):
|
|
274
|
+
The configuration for SHAP analysis.
|
|
275
|
+
enable_explanations (str): Optional. A `JMESPath boolean expression
|
|
276
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/clarify-online-explainability-create-endpoint.html#clarify-online-explainability-create-endpoint-enable>`__
|
|
277
|
+
used to filter which records to explain (Default: None). If not specified,
|
|
278
|
+
explanations are activated by default.
|
|
279
|
+
inference_config (:class:`~sagemaker.explainer.clarify_explainer_config.ClarifyInferenceConfig`):
|
|
280
|
+
Optional. The inference configuration parameter for the model container. (Default: None)
|
|
281
|
+
""" # noqa E501 # pylint: disable=line-too-long
|
|
282
|
+
self.enable_explanations = enable_explanations
|
|
283
|
+
self.shap_config = shap_config
|
|
284
|
+
self.inference_config = inference_config
|
|
285
|
+
|
|
286
|
+
def _to_request_dict(self):
|
|
287
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
288
|
+
request_dict = {
|
|
289
|
+
"ShapConfig": self.shap_config._to_request_dict(),
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if self.enable_explanations is not None:
|
|
293
|
+
request_dict["EnableExplanations"] = self.enable_explanations
|
|
294
|
+
|
|
295
|
+
if self.inference_config is not None:
|
|
296
|
+
request_dict["InferenceConfig"] = self.inference_config._to_request_dict()
|
|
297
|
+
|
|
298
|
+
return request_dict
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
"""A member of ``CreateEndpointConfig`` that enables explainers."""
|
|
14
|
+
|
|
15
|
+
from __future__ import print_function, absolute_import
|
|
16
|
+
from typing import Optional
|
|
17
|
+
from sagemaker.core.explainer.clarify_explainer_config import ClarifyExplainerConfig
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ExplainerConfig(object):
|
|
21
|
+
"""A parameter to activate explainers."""
|
|
22
|
+
|
|
23
|
+
def __init__(
|
|
24
|
+
self,
|
|
25
|
+
clarify_explainer_config: Optional[ClarifyExplainerConfig] = None,
|
|
26
|
+
):
|
|
27
|
+
"""Initializes a config object to activate explainer.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
clarify_explainer_config (:class:`~sagemaker.explainer.explainer_config.ClarifyExplainerConfig`):
|
|
31
|
+
Optional. A config contains parameters for the SageMaker Clarify explainer. (Default: None)
|
|
32
|
+
""" # noqa E501 # pylint: disable=line-too-long
|
|
33
|
+
self.clarify_explainer_config = clarify_explainer_config
|
|
34
|
+
|
|
35
|
+
def _to_request_dict(self):
|
|
36
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
37
|
+
request_dict = {}
|
|
38
|
+
|
|
39
|
+
if self.clarify_explainer_config:
|
|
40
|
+
request_dict["ClarifyExplainerConfig"] = (
|
|
41
|
+
self.clarify_explainer_config._to_request_dict()
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
return request_dict
|