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,793 @@
|
|
|
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
|
+
"""Placeholder docstring"""
|
|
14
|
+
from __future__ import absolute_import
|
|
15
|
+
|
|
16
|
+
from typing import Union, Optional, Dict
|
|
17
|
+
import logging
|
|
18
|
+
import time
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
from botocore import exceptions
|
|
22
|
+
from sagemaker.core.helper.session_helper import Session
|
|
23
|
+
from sagemaker.core import s3
|
|
24
|
+
from sagemaker.core._studio import _append_project_tags
|
|
25
|
+
from sagemaker.core.config import (
|
|
26
|
+
TRANSFORM_JOB_ENVIRONMENT_PATH,
|
|
27
|
+
TRANSFORM_OUTPUT_KMS_KEY_ID_PATH,
|
|
28
|
+
TRANSFORM_JOB_KMS_KEY_ID_PATH,
|
|
29
|
+
TRANSFORM_RESOURCES_VOLUME_KMS_KEY_ID_PATH,
|
|
30
|
+
SAGEMAKER,
|
|
31
|
+
TRANSFORM_JOB,
|
|
32
|
+
TAGS,
|
|
33
|
+
KMS_KEY_ID,
|
|
34
|
+
VOLUME_KMS_KEY_ID,
|
|
35
|
+
TRANSFORM_JOB_VOLUME_KMS_KEY_ID_PATH,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
from sagemaker.core.shapes import BatchDataCaptureConfig
|
|
39
|
+
from sagemaker.core.resources import TransformJob, Model
|
|
40
|
+
from sagemaker.core.helper.pipeline_variable import PipelineVariable
|
|
41
|
+
from sagemaker.core.workflow.functions import Join
|
|
42
|
+
from sagemaker.core.workflow.pipeline_context import runnable_by_pipeline, PipelineSession
|
|
43
|
+
from sagemaker.core.workflow import is_pipeline_variable
|
|
44
|
+
from sagemaker.core.workflow.execution_variables import ExecutionVariables
|
|
45
|
+
from sagemaker.core.common_utils import (
|
|
46
|
+
base_name_from_image,
|
|
47
|
+
name_from_base,
|
|
48
|
+
check_and_get_run_experiment_config,
|
|
49
|
+
resolve_value_from_config,
|
|
50
|
+
resolve_class_attribute_from_config,
|
|
51
|
+
resolve_nested_dict_value_from_config,
|
|
52
|
+
format_tags,
|
|
53
|
+
Tags,
|
|
54
|
+
_wait_until,
|
|
55
|
+
_flush_log_streams,
|
|
56
|
+
_logs_init,
|
|
57
|
+
LogState,
|
|
58
|
+
_check_job_status,
|
|
59
|
+
_get_initial_job_state,
|
|
60
|
+
)
|
|
61
|
+
from sagemaker.core.utils.utils import serialize
|
|
62
|
+
from sagemaker.core.config.config_utils import _append_sagemaker_config_tags
|
|
63
|
+
|
|
64
|
+
logger = LOGGER = logging.getLogger("sagemaker")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Transformer(object):
|
|
68
|
+
"""A class for handling creating and interacting with Amazon SageMaker transform jobs."""
|
|
69
|
+
|
|
70
|
+
JOB_CLASS_NAME = "transform-job"
|
|
71
|
+
|
|
72
|
+
def __init__(
|
|
73
|
+
self,
|
|
74
|
+
model_name: Union[str, PipelineVariable],
|
|
75
|
+
instance_count: Union[int, PipelineVariable],
|
|
76
|
+
instance_type: Union[str, PipelineVariable],
|
|
77
|
+
strategy: Optional[Union[str, PipelineVariable]] = None,
|
|
78
|
+
assemble_with: Optional[Union[str, PipelineVariable]] = None,
|
|
79
|
+
output_path: Optional[Union[str, PipelineVariable]] = None,
|
|
80
|
+
output_kms_key: Optional[Union[str, PipelineVariable]] = None,
|
|
81
|
+
accept: Optional[Union[str, PipelineVariable]] = None,
|
|
82
|
+
max_concurrent_transforms: Optional[Union[int, PipelineVariable]] = None,
|
|
83
|
+
max_payload: Optional[Union[int, PipelineVariable]] = None,
|
|
84
|
+
tags: Optional[Tags] = None,
|
|
85
|
+
env: Optional[Dict[str, Union[str, PipelineVariable]]] = None,
|
|
86
|
+
base_transform_job_name: Optional[str] = None,
|
|
87
|
+
sagemaker_session: Optional[Session] = None,
|
|
88
|
+
volume_kms_key: Optional[Union[str, PipelineVariable]] = None,
|
|
89
|
+
):
|
|
90
|
+
"""Initialize a ``Transformer``.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
model_name (str or PipelineVariable): Name of the SageMaker model being
|
|
94
|
+
used for the transform job.
|
|
95
|
+
instance_count (int or PipelineVariable): Number of EC2 instances to use.
|
|
96
|
+
instance_type (str or PipelineVariable): Type of EC2 instance to use, for example,
|
|
97
|
+
'ml.c4.xlarge'.
|
|
98
|
+
strategy (str or PipelineVariable): The strategy used to decide how to batch records
|
|
99
|
+
in a single request (default: None). Valid values: 'MultiRecord'
|
|
100
|
+
and 'SingleRecord'.
|
|
101
|
+
assemble_with (str or PipelineVariable): How the output is assembled (default: None).
|
|
102
|
+
Valid values: 'Line' or 'None'.
|
|
103
|
+
output_path (str or PipelineVariable): S3 location for saving the transform result. If
|
|
104
|
+
not specified, results are stored to a default bucket.
|
|
105
|
+
output_kms_key (str or PipelineVariable): Optional. KMS key ID for encrypting the
|
|
106
|
+
transform output (default: None).
|
|
107
|
+
accept (str or PipelineVariable): The accept header passed by the client to
|
|
108
|
+
the inference endpoint. If it is supported by the endpoint,
|
|
109
|
+
it will be the format of the batch transform output.
|
|
110
|
+
max_concurrent_transforms (int or PipelineVariable): The maximum number of HTTP requests
|
|
111
|
+
to be made to each individual transform container at one time.
|
|
112
|
+
max_payload (int or PipelineVariable): Maximum size of the payload in a single HTTP
|
|
113
|
+
request to the container in MB.
|
|
114
|
+
tags (Optional[Tags]): Tags for labeling a transform job (default: None).
|
|
115
|
+
For more, see the SageMaker API documentation for
|
|
116
|
+
`Tag <https://docs.aws.amazon.com/sagemaker/latest/dg/API_Tag.html>`_.
|
|
117
|
+
env (dict[str, str] or dict[str, PipelineVariable]): Environment variables to be set
|
|
118
|
+
for use during the transform job (default: None).
|
|
119
|
+
base_transform_job_name (str): Prefix for the transform job when the
|
|
120
|
+
:meth:`~sagemaker.transformer.Transformer.transform` method
|
|
121
|
+
launches. If not specified, a default prefix will be generated
|
|
122
|
+
based on the training image name that was used to train the
|
|
123
|
+
model associated with the transform job.
|
|
124
|
+
sagemaker_session (sagemaker.core.helper.session.Session): Session object which
|
|
125
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
126
|
+
AWS services needed.
|
|
127
|
+
volume_kms_key (str or PipelineVariable): Optional. KMS key ID for encrypting
|
|
128
|
+
the volume attached to the ML compute instance (default: None).
|
|
129
|
+
"""
|
|
130
|
+
self.model_name = model_name
|
|
131
|
+
self.strategy = strategy
|
|
132
|
+
|
|
133
|
+
self.output_path = output_path
|
|
134
|
+
self.accept = accept
|
|
135
|
+
self.assemble_with = assemble_with
|
|
136
|
+
|
|
137
|
+
self.instance_count = instance_count
|
|
138
|
+
self.instance_type = instance_type
|
|
139
|
+
|
|
140
|
+
self.max_concurrent_transforms = max_concurrent_transforms
|
|
141
|
+
self.max_payload = max_payload
|
|
142
|
+
self.tags = format_tags(tags)
|
|
143
|
+
|
|
144
|
+
self.base_transform_job_name = base_transform_job_name
|
|
145
|
+
self._current_job_name = None
|
|
146
|
+
self.latest_transform_job = None
|
|
147
|
+
self._reset_output_path = False
|
|
148
|
+
|
|
149
|
+
self.sagemaker_session = sagemaker_session or Session()
|
|
150
|
+
self.volume_kms_key = resolve_value_from_config(
|
|
151
|
+
volume_kms_key,
|
|
152
|
+
TRANSFORM_RESOURCES_VOLUME_KMS_KEY_ID_PATH,
|
|
153
|
+
sagemaker_session=self.sagemaker_session,
|
|
154
|
+
)
|
|
155
|
+
self.output_kms_key = resolve_value_from_config(
|
|
156
|
+
output_kms_key,
|
|
157
|
+
TRANSFORM_OUTPUT_KMS_KEY_ID_PATH,
|
|
158
|
+
sagemaker_session=self.sagemaker_session,
|
|
159
|
+
)
|
|
160
|
+
self.env = resolve_value_from_config(
|
|
161
|
+
env,
|
|
162
|
+
TRANSFORM_JOB_ENVIRONMENT_PATH,
|
|
163
|
+
sagemaker_session=self.sagemaker_session,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
@runnable_by_pipeline
|
|
167
|
+
def transform(
|
|
168
|
+
self,
|
|
169
|
+
data: Union[str, PipelineVariable],
|
|
170
|
+
data_type: Union[str, PipelineVariable] = "S3Prefix",
|
|
171
|
+
content_type: Optional[Union[str, PipelineVariable]] = None,
|
|
172
|
+
compression_type: Optional[Union[str, PipelineVariable]] = None,
|
|
173
|
+
split_type: Optional[Union[str, PipelineVariable]] = None,
|
|
174
|
+
job_name: Optional[str] = None,
|
|
175
|
+
input_filter: Optional[Union[str, PipelineVariable]] = None,
|
|
176
|
+
output_filter: Optional[Union[str, PipelineVariable]] = None,
|
|
177
|
+
join_source: Optional[Union[str, PipelineVariable]] = None,
|
|
178
|
+
experiment_config: Optional[Dict[str, str]] = None,
|
|
179
|
+
model_client_config: Optional[Dict[str, Union[str, PipelineVariable]]] = None,
|
|
180
|
+
batch_data_capture_config: BatchDataCaptureConfig = None,
|
|
181
|
+
wait: bool = True,
|
|
182
|
+
logs: bool = True,
|
|
183
|
+
):
|
|
184
|
+
"""Start a new transform job.
|
|
185
|
+
|
|
186
|
+
Args:
|
|
187
|
+
data (str or PipelineVariable): Input data location in S3.
|
|
188
|
+
data_type (str or PipelineVariable): What the S3 location defines (default: 'S3Prefix').
|
|
189
|
+
Valid values:
|
|
190
|
+
|
|
191
|
+
* 'S3Prefix' - the S3 URI defines a key name prefix. All objects with this prefix
|
|
192
|
+
will be used as inputs for the transform job.
|
|
193
|
+
|
|
194
|
+
* 'ManifestFile' - the S3 URI points to a single manifest file listing each S3
|
|
195
|
+
object to use as an input for the transform job.
|
|
196
|
+
|
|
197
|
+
content_type (str or PipelineVariable): MIME type of the input data (default: None).
|
|
198
|
+
compression_type (str or PipelineVariable): Compression type of the input data, if
|
|
199
|
+
compressed (default: None). Valid values: 'Gzip', None.
|
|
200
|
+
split_type (str or PipelineVariable): The record delimiter for the input object
|
|
201
|
+
(default: 'None'). Valid values: 'None', 'Line', 'RecordIO', and
|
|
202
|
+
'TFRecord'.
|
|
203
|
+
job_name (str): job name (default: None). If not specified, one will
|
|
204
|
+
be generated.
|
|
205
|
+
input_filter (str or PipelineVariable): A JSONPath to select a portion of the input to
|
|
206
|
+
pass to the algorithm container for inference. If you omit the
|
|
207
|
+
field, it gets the value '$', representing the entire input.
|
|
208
|
+
For CSV data, each row is taken as a JSON array,
|
|
209
|
+
so only index-based JSONPaths can be applied, e.g. $[0], $[1:].
|
|
210
|
+
CSV data should follow the `RFC format <https://tools.ietf.org/html/rfc4180>`_.
|
|
211
|
+
See `Supported JSONPath Operators
|
|
212
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/batch-transform-data-processing.html#data-processing-operators>`_
|
|
213
|
+
for a table of supported JSONPath operators.
|
|
214
|
+
For more information, see the SageMaker API documentation for
|
|
215
|
+
`CreateTransformJob
|
|
216
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTransformJob.html>`_.
|
|
217
|
+
Some examples: "$[1:]", "$.features" (default: None).
|
|
218
|
+
output_filter (str or PipelineVariable): A JSONPath to select a portion of the
|
|
219
|
+
joined/original output to return as the output.
|
|
220
|
+
For more information, see the SageMaker API documentation for
|
|
221
|
+
`CreateTransformJob
|
|
222
|
+
<https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateTransformJob.html>`_.
|
|
223
|
+
Some examples: "$[1:]", "$.prediction" (default: None).
|
|
224
|
+
join_source (str or PipelineVariable): The source of data to be joined to the transform
|
|
225
|
+
output. It can be set to 'Input' meaning the entire input record
|
|
226
|
+
will be joined to the inference result. You can use OutputFilter
|
|
227
|
+
to select the useful portion before uploading to S3. (default:
|
|
228
|
+
None). Valid values: Input, None.
|
|
229
|
+
experiment_config (dict[str, str]): Experiment management configuration.
|
|
230
|
+
Optionally, the dict can contain three keys:
|
|
231
|
+
'ExperimentName', 'TrialName', and 'TrialComponentDisplayName'.
|
|
232
|
+
The behavior of setting these keys is as follows:
|
|
233
|
+
* If `ExperimentName` is supplied but `TrialName` is not a Trial will be
|
|
234
|
+
automatically created and the job's Trial Component associated with the Trial.
|
|
235
|
+
* If `TrialName` is supplied and the Trial already exists the job's Trial Component
|
|
236
|
+
will be associated with the Trial.
|
|
237
|
+
* If both `ExperimentName` and `TrialName` are not supplied the trial component
|
|
238
|
+
will be unassociated.
|
|
239
|
+
* `TrialComponentDisplayName` is used for display in Studio.
|
|
240
|
+
* Both `ExperimentName` and `TrialName` will be ignored if the Transformer instance
|
|
241
|
+
is built with :class:`~sagemaker.workflow.pipeline_context.PipelineSession`.
|
|
242
|
+
However, the value of `TrialComponentDisplayName` is honored for display in Studio.
|
|
243
|
+
model_client_config (dict[str, str] or dict[str, PipelineVariable]): Model
|
|
244
|
+
configuration. Dictionary contains two optional keys,
|
|
245
|
+
'InvocationsTimeoutInSeconds', and 'InvocationsMaxRetries'.
|
|
246
|
+
(default: ``None``).
|
|
247
|
+
batch_data_capture_config (BatchDataCaptureConfig): Configuration object which
|
|
248
|
+
specifies the configurations related to the batch data capture for the transform job
|
|
249
|
+
(default: ``None``).
|
|
250
|
+
batch_data_capture_config (BatchDataCaptureConfig): Configuration object which
|
|
251
|
+
specifies the configurations related to the batch data capture for the transform job
|
|
252
|
+
(default: ``None``).
|
|
253
|
+
wait (bool): Whether the call should wait until the job completes
|
|
254
|
+
(default: ``True``).
|
|
255
|
+
logs (bool): Whether to show the logs produced by the job.
|
|
256
|
+
Only meaningful when wait is ``True`` (default: ``True``).
|
|
257
|
+
Returns:
|
|
258
|
+
None or pipeline step arguments in case the Transformer instance is built with
|
|
259
|
+
:class:`~sagemaker.workflow.pipeline_context.PipelineSession`
|
|
260
|
+
"""
|
|
261
|
+
from sagemaker.core.workflow.utilities import _pipeline_config
|
|
262
|
+
|
|
263
|
+
local_mode = self.sagemaker_session.local_mode
|
|
264
|
+
if not local_mode and not is_pipeline_variable(data) and not data.startswith("s3://"):
|
|
265
|
+
raise ValueError("Invalid S3 URI: {}".format(data))
|
|
266
|
+
|
|
267
|
+
if job_name is not None:
|
|
268
|
+
self._current_job_name = job_name
|
|
269
|
+
else:
|
|
270
|
+
base_name = self.base_transform_job_name
|
|
271
|
+
|
|
272
|
+
if base_name is None:
|
|
273
|
+
base_name = (
|
|
274
|
+
"transform-job"
|
|
275
|
+
if is_pipeline_variable(self.model_name)
|
|
276
|
+
else self._retrieve_base_name()
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
self._current_job_name = name_from_base(base_name)
|
|
280
|
+
|
|
281
|
+
if self.output_path is None or self._reset_output_path is True:
|
|
282
|
+
if _pipeline_config:
|
|
283
|
+
self.output_path = Join(
|
|
284
|
+
on="/",
|
|
285
|
+
values=[
|
|
286
|
+
"s3:/",
|
|
287
|
+
self.sagemaker_session.default_bucket(),
|
|
288
|
+
*(
|
|
289
|
+
# don't include default_bucket_prefix if it is None or ""
|
|
290
|
+
[self.sagemaker_session.default_bucket_prefix]
|
|
291
|
+
if self.sagemaker_session.default_bucket_prefix
|
|
292
|
+
else []
|
|
293
|
+
),
|
|
294
|
+
_pipeline_config.pipeline_name,
|
|
295
|
+
ExecutionVariables.PIPELINE_EXECUTION_ID,
|
|
296
|
+
_pipeline_config.step_name,
|
|
297
|
+
],
|
|
298
|
+
)
|
|
299
|
+
else:
|
|
300
|
+
self.output_path = s3.s3_path_join(
|
|
301
|
+
"s3://",
|
|
302
|
+
self.sagemaker_session.default_bucket(),
|
|
303
|
+
self.sagemaker_session.default_bucket_prefix,
|
|
304
|
+
self._current_job_name,
|
|
305
|
+
)
|
|
306
|
+
self._reset_output_path = True
|
|
307
|
+
|
|
308
|
+
experiment_config = check_and_get_run_experiment_config(experiment_config)
|
|
309
|
+
|
|
310
|
+
batch_data_capture_config = resolve_class_attribute_from_config(
|
|
311
|
+
None,
|
|
312
|
+
batch_data_capture_config,
|
|
313
|
+
"kms_key_id",
|
|
314
|
+
TRANSFORM_JOB_KMS_KEY_ID_PATH,
|
|
315
|
+
sagemaker_session=self.sagemaker_session,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
transform_args = self._get_transform_args(
|
|
319
|
+
data,
|
|
320
|
+
data_type,
|
|
321
|
+
content_type,
|
|
322
|
+
compression_type,
|
|
323
|
+
split_type,
|
|
324
|
+
input_filter,
|
|
325
|
+
output_filter,
|
|
326
|
+
join_source,
|
|
327
|
+
experiment_config,
|
|
328
|
+
model_client_config,
|
|
329
|
+
batch_data_capture_config,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
# Apply config resolution and create transform job
|
|
333
|
+
tags = _append_project_tags(format_tags(transform_args["tags"]))
|
|
334
|
+
tags = _append_sagemaker_config_tags(
|
|
335
|
+
self.sagemaker_session, tags, "{}.{}.{}".format(SAGEMAKER, TRANSFORM_JOB, TAGS)
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
batch_data_capture_config = resolve_class_attribute_from_config(
|
|
339
|
+
None,
|
|
340
|
+
transform_args["batch_data_capture_config"],
|
|
341
|
+
"kms_key_id",
|
|
342
|
+
TRANSFORM_JOB_KMS_KEY_ID_PATH,
|
|
343
|
+
sagemaker_session=self.sagemaker_session,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
output_config = resolve_nested_dict_value_from_config(
|
|
347
|
+
transform_args["output_config"],
|
|
348
|
+
[KMS_KEY_ID],
|
|
349
|
+
TRANSFORM_OUTPUT_KMS_KEY_ID_PATH,
|
|
350
|
+
sagemaker_session=self.sagemaker_session,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
resource_config = resolve_nested_dict_value_from_config(
|
|
354
|
+
transform_args["resource_config"],
|
|
355
|
+
[VOLUME_KMS_KEY_ID],
|
|
356
|
+
TRANSFORM_JOB_VOLUME_KMS_KEY_ID_PATH,
|
|
357
|
+
sagemaker_session=self.sagemaker_session,
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
env = resolve_value_from_config(
|
|
361
|
+
direct_input=transform_args["env"],
|
|
362
|
+
config_path=TRANSFORM_JOB_ENVIRONMENT_PATH,
|
|
363
|
+
default_value=None,
|
|
364
|
+
sagemaker_session=self.sagemaker_session,
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
transform_request = self._get_transform_request(
|
|
368
|
+
job_name=transform_args["job_name"],
|
|
369
|
+
model_name=transform_args["model_name"],
|
|
370
|
+
strategy=transform_args["strategy"],
|
|
371
|
+
max_concurrent_transforms=transform_args["max_concurrent_transforms"],
|
|
372
|
+
max_payload=transform_args["max_payload"],
|
|
373
|
+
env=env,
|
|
374
|
+
input_config=transform_args["input_config"],
|
|
375
|
+
output_config=output_config,
|
|
376
|
+
resource_config=resource_config,
|
|
377
|
+
experiment_config=transform_args["experiment_config"],
|
|
378
|
+
tags=tags,
|
|
379
|
+
data_processing=transform_args["data_processing"],
|
|
380
|
+
model_client_config=transform_args["model_client_config"],
|
|
381
|
+
batch_data_capture_config=batch_data_capture_config,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
# convert Unassigned() type in sagemaker-core to None
|
|
385
|
+
serialized_request = serialize(transform_request)
|
|
386
|
+
|
|
387
|
+
if isinstance(self.sagemaker_session, PipelineSession):
|
|
388
|
+
self.sagemaker_session._intercept_create_request(serialized_request, None, "transform")
|
|
389
|
+
return
|
|
390
|
+
|
|
391
|
+
def submit(request):
|
|
392
|
+
logger.info("Creating transform job with name: %s", transform_args["job_name"])
|
|
393
|
+
logger.debug("Transform request: %s", json.dumps(request, indent=4))
|
|
394
|
+
self.sagemaker_session.sagemaker_client.create_transform_job(**request)
|
|
395
|
+
|
|
396
|
+
self.sagemaker_session._intercept_create_request(serialized_request, submit, "transform")
|
|
397
|
+
|
|
398
|
+
from sagemaker.core.utils.code_injection.codec import transform as transform_util
|
|
399
|
+
|
|
400
|
+
transformed = transform_util(serialized_request, "CreateTransformJobRequest")
|
|
401
|
+
self.latest_transform_job = TransformJob(**transformed)
|
|
402
|
+
|
|
403
|
+
if wait:
|
|
404
|
+
self.latest_transform_job.wait(logs=logs)
|
|
405
|
+
|
|
406
|
+
def delete_model(self):
|
|
407
|
+
"""Delete the corresponding SageMaker model for this Transformer."""
|
|
408
|
+
model = Model.get(model_name=self.model_name, session=self.sagemaker_session.boto_session)
|
|
409
|
+
if model:
|
|
410
|
+
model.delete()
|
|
411
|
+
|
|
412
|
+
def _retrieve_base_name(self):
|
|
413
|
+
"""Placeholder docstring"""
|
|
414
|
+
image_uri = self._retrieve_image_uri()
|
|
415
|
+
|
|
416
|
+
if image_uri:
|
|
417
|
+
return base_name_from_image(image_uri, default_base_name=Transformer.JOB_CLASS_NAME)
|
|
418
|
+
|
|
419
|
+
return self.model_name
|
|
420
|
+
|
|
421
|
+
def _retrieve_image_uri(self):
|
|
422
|
+
"""Placeholder docstring"""
|
|
423
|
+
try:
|
|
424
|
+
model = Model.get(
|
|
425
|
+
model_name=self.model_name,
|
|
426
|
+
session=self.sagemaker_session.boto_session,
|
|
427
|
+
region=self.sagemaker_session.boto_region_name,
|
|
428
|
+
)
|
|
429
|
+
if not model:
|
|
430
|
+
return None
|
|
431
|
+
model_desc = model.__dict__
|
|
432
|
+
|
|
433
|
+
primary_container = getattr(model_desc, "primary_container", None)
|
|
434
|
+
if primary_container:
|
|
435
|
+
return getattr(primary_container, "image", None)
|
|
436
|
+
|
|
437
|
+
containers = getattr(model_desc, "containers", None)
|
|
438
|
+
if containers:
|
|
439
|
+
return getattr(containers[0], "image", None)
|
|
440
|
+
|
|
441
|
+
return None
|
|
442
|
+
|
|
443
|
+
except exceptions.ClientError:
|
|
444
|
+
raise ValueError(
|
|
445
|
+
"Failed to fetch model information for %s. "
|
|
446
|
+
"Please ensure that the model exists. "
|
|
447
|
+
"Local instance types require locally created models." % self.model_name
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
def wait(self, logs=True):
|
|
451
|
+
"""Placeholder docstring"""
|
|
452
|
+
self._ensure_last_transform_job()
|
|
453
|
+
self.latest_transform_job.wait(logs=logs)
|
|
454
|
+
|
|
455
|
+
def stop_transform_job(self, wait=True):
|
|
456
|
+
"""Stop latest running batch transform job."""
|
|
457
|
+
self._ensure_last_transform_job()
|
|
458
|
+
self.latest_transform_job.stop()
|
|
459
|
+
if wait:
|
|
460
|
+
self.latest_transform_job.wait()
|
|
461
|
+
|
|
462
|
+
def _ensure_last_transform_job(self):
|
|
463
|
+
"""Placeholder docstring"""
|
|
464
|
+
if self.latest_transform_job is None:
|
|
465
|
+
raise ValueError("No transform job available")
|
|
466
|
+
|
|
467
|
+
@classmethod
|
|
468
|
+
def attach(cls, transform_job_name, sagemaker_session=None):
|
|
469
|
+
"""Attach an existing transform job to a new Transformer instance
|
|
470
|
+
|
|
471
|
+
Args:
|
|
472
|
+
transform_job_name (str): Name for the transform job to be attached.
|
|
473
|
+
sagemaker_session (sagemaker.core.helper.session.Session): Session object which
|
|
474
|
+
manages interactions with Amazon SageMaker APIs and any other
|
|
475
|
+
AWS services needed. If not specified, one will be created using
|
|
476
|
+
the default AWS configuration chain.
|
|
477
|
+
|
|
478
|
+
Returns:
|
|
479
|
+
sagemaker.transformer.Transformer: The Transformer instance with the
|
|
480
|
+
specified transform job attached.
|
|
481
|
+
"""
|
|
482
|
+
sagemaker_session = sagemaker_session or Session()
|
|
483
|
+
|
|
484
|
+
transform_job = TransformJob.get(
|
|
485
|
+
transform_job_name=transform_job_name, session=sagemaker_session
|
|
486
|
+
)
|
|
487
|
+
if not transform_job:
|
|
488
|
+
raise ValueError(f"Transform job {transform_job_name} not found")
|
|
489
|
+
job_details = transform_job.__dict__
|
|
490
|
+
init_params = cls._prepare_init_params_from_job_description(job_details)
|
|
491
|
+
transformer = cls(sagemaker_session=sagemaker_session, **init_params)
|
|
492
|
+
transformer.latest_transform_job = TransformJob.get(
|
|
493
|
+
transform_job_name=init_params["base_transform_job_name"], session=sagemaker_session
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
return transformer
|
|
497
|
+
|
|
498
|
+
@classmethod
|
|
499
|
+
def _prepare_init_params_from_job_description(cls, job_details):
|
|
500
|
+
"""Convert the transform job description to init params.
|
|
501
|
+
|
|
502
|
+
It can be handled by the class constructor.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
job_details (dict): the returned job details from a
|
|
506
|
+
describe_transform_job API call.
|
|
507
|
+
|
|
508
|
+
Returns:
|
|
509
|
+
dict: The transformed init_params
|
|
510
|
+
"""
|
|
511
|
+
init_params = dict()
|
|
512
|
+
|
|
513
|
+
init_params["model_name"] = job_details.get("model_name")
|
|
514
|
+
if job_details.get("transform_resources"):
|
|
515
|
+
init_params["instance_count"] = job_details["transform_resources"].instance_count
|
|
516
|
+
init_params["instance_type"] = job_details["transform_resources"].instance_type
|
|
517
|
+
init_params["volume_kms_key"] = getattr(
|
|
518
|
+
job_details["transform_resources"], "volume_kms_key_id", None
|
|
519
|
+
)
|
|
520
|
+
init_params["strategy"] = job_details.get("batch_strategy")
|
|
521
|
+
if job_details.get("transform_output"):
|
|
522
|
+
init_params["assemble_with"] = getattr(
|
|
523
|
+
job_details["transform_output"], "assemble_with", None
|
|
524
|
+
)
|
|
525
|
+
init_params["output_path"] = job_details["transform_output"].s3_output_path
|
|
526
|
+
init_params["output_kms_key"] = getattr(
|
|
527
|
+
job_details["transform_output"], "kms_key_id", None
|
|
528
|
+
)
|
|
529
|
+
init_params["accept"] = getattr(job_details["transform_output"], "accept", None)
|
|
530
|
+
init_params["max_concurrent_transforms"] = job_details.get("max_concurrent_transforms")
|
|
531
|
+
init_params["max_payload"] = job_details.get("max_payload_in_mb")
|
|
532
|
+
init_params["base_transform_job_name"] = job_details.get("transform_job_name")
|
|
533
|
+
|
|
534
|
+
return init_params
|
|
535
|
+
|
|
536
|
+
def _get_transform_args(
|
|
537
|
+
self,
|
|
538
|
+
data,
|
|
539
|
+
data_type,
|
|
540
|
+
content_type,
|
|
541
|
+
compression_type,
|
|
542
|
+
split_type,
|
|
543
|
+
input_filter,
|
|
544
|
+
output_filter,
|
|
545
|
+
join_source,
|
|
546
|
+
experiment_config,
|
|
547
|
+
model_client_config,
|
|
548
|
+
batch_data_capture_config,
|
|
549
|
+
):
|
|
550
|
+
"""Get transform job arguments."""
|
|
551
|
+
config = self._load_config(data, data_type, content_type, compression_type, split_type)
|
|
552
|
+
data_processing = self._prepare_data_processing(input_filter, output_filter, join_source)
|
|
553
|
+
|
|
554
|
+
transform_args = config.copy()
|
|
555
|
+
transform_args.update(
|
|
556
|
+
{
|
|
557
|
+
"job_name": self._current_job_name,
|
|
558
|
+
"model_name": self.model_name,
|
|
559
|
+
"strategy": self.strategy,
|
|
560
|
+
"max_concurrent_transforms": self.max_concurrent_transforms,
|
|
561
|
+
"max_payload": self.max_payload,
|
|
562
|
+
"env": self.env,
|
|
563
|
+
"experiment_config": experiment_config,
|
|
564
|
+
"model_client_config": model_client_config,
|
|
565
|
+
"tags": self.tags,
|
|
566
|
+
"data_processing": data_processing,
|
|
567
|
+
"batch_data_capture_config": batch_data_capture_config,
|
|
568
|
+
}
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
return transform_args
|
|
572
|
+
|
|
573
|
+
def _load_config(self, data, data_type, content_type, compression_type, split_type):
|
|
574
|
+
"""Load configuration for transform job."""
|
|
575
|
+
input_config = self._format_inputs_to_input_config(
|
|
576
|
+
data, data_type, content_type, compression_type, split_type
|
|
577
|
+
)
|
|
578
|
+
|
|
579
|
+
output_config = self._prepare_output_config(
|
|
580
|
+
self.output_path,
|
|
581
|
+
self.output_kms_key,
|
|
582
|
+
self.assemble_with,
|
|
583
|
+
self.accept,
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
resource_config = self._prepare_resource_config(
|
|
587
|
+
self.instance_count, self.instance_type, self.volume_kms_key
|
|
588
|
+
)
|
|
589
|
+
|
|
590
|
+
return {
|
|
591
|
+
"input_config": input_config,
|
|
592
|
+
"output_config": output_config,
|
|
593
|
+
"resource_config": resource_config,
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
def _format_inputs_to_input_config(
|
|
597
|
+
self, data, data_type, content_type, compression_type, split_type
|
|
598
|
+
):
|
|
599
|
+
"""Format inputs to input config."""
|
|
600
|
+
from sagemaker.core.shapes import TransformDataSource, TransformS3DataSource
|
|
601
|
+
|
|
602
|
+
config = {
|
|
603
|
+
"data_source": TransformDataSource(
|
|
604
|
+
s3_data_source=TransformS3DataSource(s3_data_type=data_type, s3_uri=data)
|
|
605
|
+
)
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if content_type is not None:
|
|
609
|
+
config["content_type"] = content_type
|
|
610
|
+
|
|
611
|
+
if compression_type is not None:
|
|
612
|
+
config["compression_type"] = compression_type
|
|
613
|
+
|
|
614
|
+
if split_type is not None:
|
|
615
|
+
config["split_type"] = split_type
|
|
616
|
+
|
|
617
|
+
return config
|
|
618
|
+
|
|
619
|
+
def _prepare_output_config(self, s3_path, kms_key_id, assemble_with, accept):
|
|
620
|
+
"""Prepare output config."""
|
|
621
|
+
config = {"s3_output_path": s3_path}
|
|
622
|
+
|
|
623
|
+
if kms_key_id is not None:
|
|
624
|
+
config["kms_key_id"] = kms_key_id
|
|
625
|
+
|
|
626
|
+
if assemble_with is not None:
|
|
627
|
+
config["assemble_with"] = assemble_with
|
|
628
|
+
|
|
629
|
+
if accept is not None:
|
|
630
|
+
config["accept"] = accept
|
|
631
|
+
|
|
632
|
+
return config
|
|
633
|
+
|
|
634
|
+
def _prepare_resource_config(self, instance_count, instance_type, volume_kms_key):
|
|
635
|
+
"""Prepare resource config."""
|
|
636
|
+
config = {"instance_count": instance_count, "instance_type": instance_type}
|
|
637
|
+
|
|
638
|
+
if volume_kms_key is not None:
|
|
639
|
+
config["volume_kms_key_id"] = volume_kms_key
|
|
640
|
+
|
|
641
|
+
return config
|
|
642
|
+
|
|
643
|
+
def _prepare_data_processing(self, input_filter, output_filter, join_source):
|
|
644
|
+
"""Prepare data processing config."""
|
|
645
|
+
from sagemaker.core.shapes import DataProcessing
|
|
646
|
+
|
|
647
|
+
if input_filter is None and output_filter is None and join_source is None:
|
|
648
|
+
return None
|
|
649
|
+
|
|
650
|
+
return DataProcessing(
|
|
651
|
+
input_filter=input_filter, output_filter=output_filter, join_source=join_source
|
|
652
|
+
)
|
|
653
|
+
|
|
654
|
+
def _get_transform_request(
|
|
655
|
+
self,
|
|
656
|
+
job_name,
|
|
657
|
+
model_name,
|
|
658
|
+
strategy,
|
|
659
|
+
max_concurrent_transforms,
|
|
660
|
+
max_payload,
|
|
661
|
+
env,
|
|
662
|
+
input_config,
|
|
663
|
+
output_config,
|
|
664
|
+
resource_config,
|
|
665
|
+
experiment_config,
|
|
666
|
+
tags,
|
|
667
|
+
data_processing,
|
|
668
|
+
model_client_config=None,
|
|
669
|
+
batch_data_capture_config: BatchDataCaptureConfig = None,
|
|
670
|
+
):
|
|
671
|
+
"""Construct a dict for creating an Amazon SageMaker transform job."""
|
|
672
|
+
from sagemaker.core.shapes import TransformInput, TransformOutput, TransformResources
|
|
673
|
+
|
|
674
|
+
transform_request = {
|
|
675
|
+
"TransformJobName": job_name,
|
|
676
|
+
"ModelName": model_name,
|
|
677
|
+
"TransformInput": TransformInput(**input_config),
|
|
678
|
+
"TransformOutput": TransformOutput(**output_config),
|
|
679
|
+
"TransformResources": TransformResources(**resource_config),
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if strategy is not None:
|
|
683
|
+
transform_request["BatchStrategy"] = strategy
|
|
684
|
+
|
|
685
|
+
if max_concurrent_transforms is not None:
|
|
686
|
+
transform_request["MaxConcurrentTransforms"] = max_concurrent_transforms
|
|
687
|
+
|
|
688
|
+
if max_payload is not None:
|
|
689
|
+
transform_request["MaxPayloadInMB"] = max_payload
|
|
690
|
+
|
|
691
|
+
if env is not None:
|
|
692
|
+
transform_request["Environment"] = env
|
|
693
|
+
|
|
694
|
+
if tags is not None:
|
|
695
|
+
transform_request["Tags"] = tags
|
|
696
|
+
|
|
697
|
+
if data_processing is not None:
|
|
698
|
+
transform_request["DataProcessing"] = data_processing
|
|
699
|
+
|
|
700
|
+
if experiment_config and len(experiment_config) > 0:
|
|
701
|
+
transform_request["ExperimentConfig"] = experiment_config
|
|
702
|
+
|
|
703
|
+
if model_client_config and len(model_client_config) > 0:
|
|
704
|
+
transform_request["ModelClientConfig"] = model_client_config
|
|
705
|
+
|
|
706
|
+
if batch_data_capture_config is not None:
|
|
707
|
+
transform_request["DataCaptureConfig"] = batch_data_capture_config
|
|
708
|
+
|
|
709
|
+
return transform_request
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def logs_for_transform_job(sagemaker_session, job_name, wait=False, poll=10):
|
|
713
|
+
"""Display logs for a given training job, optionally tailing them until job is complete.
|
|
714
|
+
|
|
715
|
+
If the output is a tty or a Jupyter cell, it will be color-coded
|
|
716
|
+
based on which instance the log entry is from.
|
|
717
|
+
|
|
718
|
+
Args:
|
|
719
|
+
job_name (str): Name of the transform job to display the logs for.
|
|
720
|
+
wait (bool): Whether to keep looking for new log entries until the job completes
|
|
721
|
+
(default: False).
|
|
722
|
+
poll (int): The interval in seconds between polling for new log entries and job
|
|
723
|
+
completion (default: 5).
|
|
724
|
+
|
|
725
|
+
Raises:
|
|
726
|
+
ValueError: If the transform job fails.
|
|
727
|
+
"""
|
|
728
|
+
|
|
729
|
+
description = _wait_until(
|
|
730
|
+
lambda: TransformJob.get(transform_job_name=job_name, session=sagemaker_session).__dict__,
|
|
731
|
+
poll,
|
|
732
|
+
)
|
|
733
|
+
|
|
734
|
+
instance_count, stream_names, positions, client, log_group, dot, color_wrap = _logs_init(
|
|
735
|
+
sagemaker_session.boto_session, description, job="Transform"
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
state = _get_initial_job_state(description, "TransformJobStatus", wait)
|
|
739
|
+
|
|
740
|
+
# The loop below implements a state machine that alternates between checking the job status
|
|
741
|
+
# and reading whatever is available in the logs at this point. Note, that if we were
|
|
742
|
+
# called with wait == False, we never check the job status.
|
|
743
|
+
#
|
|
744
|
+
# If wait == TRUE and job is not completed, the initial state is TAILING
|
|
745
|
+
# If wait == FALSE, the initial state is COMPLETE (doesn't matter if the job really is
|
|
746
|
+
# complete).
|
|
747
|
+
#
|
|
748
|
+
# The state table:
|
|
749
|
+
#
|
|
750
|
+
# STATE ACTIONS CONDITION NEW STATE
|
|
751
|
+
# ---------------- ---------------- ----------------- ----------------
|
|
752
|
+
# TAILING Read logs, Pause, Get status Job complete JOB_COMPLETE
|
|
753
|
+
# Else TAILING
|
|
754
|
+
# JOB_COMPLETE Read logs, Pause Any COMPLETE
|
|
755
|
+
# COMPLETE Read logs, Exit N/A
|
|
756
|
+
#
|
|
757
|
+
# Notes:
|
|
758
|
+
# - The JOB_COMPLETE state forces us to do an extra pause and read any items that got to
|
|
759
|
+
# Cloudwatch after the job was marked complete.
|
|
760
|
+
last_describe_job_call = time.time()
|
|
761
|
+
while True:
|
|
762
|
+
_flush_log_streams(
|
|
763
|
+
stream_names,
|
|
764
|
+
instance_count,
|
|
765
|
+
client,
|
|
766
|
+
log_group,
|
|
767
|
+
job_name,
|
|
768
|
+
positions,
|
|
769
|
+
dot,
|
|
770
|
+
color_wrap,
|
|
771
|
+
)
|
|
772
|
+
if state == LogState.COMPLETE:
|
|
773
|
+
break
|
|
774
|
+
|
|
775
|
+
time.sleep(poll)
|
|
776
|
+
|
|
777
|
+
if state == LogState.JOB_COMPLETE:
|
|
778
|
+
state = LogState.COMPLETE
|
|
779
|
+
elif time.time() - last_describe_job_call >= 30:
|
|
780
|
+
transform_job = TransformJob.get(transform_job_name=job_name, session=sagemaker_session)
|
|
781
|
+
description = transform_job.__dict__ if transform_job else None
|
|
782
|
+
last_describe_job_call = time.time()
|
|
783
|
+
|
|
784
|
+
status = description["TransformJobStatus"]
|
|
785
|
+
|
|
786
|
+
if status in ("Completed", "Failed", "Stopped"):
|
|
787
|
+
print()
|
|
788
|
+
state = LogState.JOB_COMPLETE
|
|
789
|
+
|
|
790
|
+
if wait:
|
|
791
|
+
_check_job_status(job_name, description, "TransformJobStatus")
|
|
792
|
+
if dot:
|
|
793
|
+
print()
|