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,245 @@
|
|
|
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
|
+
import os
|
|
17
|
+
import logging
|
|
18
|
+
import shutil
|
|
19
|
+
import subprocess
|
|
20
|
+
import json
|
|
21
|
+
import re
|
|
22
|
+
import errno
|
|
23
|
+
|
|
24
|
+
from sagemaker.core import s3
|
|
25
|
+
from six.moves.urllib.parse import urlparse
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
logger = logging.getLogger(__name__)
|
|
29
|
+
|
|
30
|
+
STUDIO_APP_TYPES = ["KernelGateway", "CodeEditor", "JupyterLab"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def copy_directory_structure(destination_directory, relative_path):
|
|
34
|
+
"""Creates intermediate directory structure for relative_path.
|
|
35
|
+
|
|
36
|
+
Create all the intermediate directories required for relative_path to
|
|
37
|
+
exist within destination_directory. This assumes that relative_path is a
|
|
38
|
+
directory located within root_dir.
|
|
39
|
+
|
|
40
|
+
Examples:
|
|
41
|
+
destination_directory: /tmp/destination relative_path: test/unit/
|
|
42
|
+
will create: /tmp/destination/test/unit
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
destination_directory (str): root of the destination directory where the
|
|
46
|
+
directory structure will be created.
|
|
47
|
+
relative_path (str): relative path that will be created within
|
|
48
|
+
destination_directory
|
|
49
|
+
"""
|
|
50
|
+
full_path = os.path.join(destination_directory, relative_path)
|
|
51
|
+
if os.path.exists(full_path):
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
os.makedirs(destination_directory, relative_path)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def move_to_destination(source, destination, job_name, sagemaker_session, prefix=""):
|
|
58
|
+
"""Move source to destination.
|
|
59
|
+
|
|
60
|
+
Can handle uploading to S3.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
source (str): root directory to move
|
|
64
|
+
destination (str): file:// or s3:// URI that source will be moved to.
|
|
65
|
+
job_name (str): SageMaker job name.
|
|
66
|
+
sagemaker_session (sagemaker.Session): a sagemaker_session to interact
|
|
67
|
+
with S3 if needed
|
|
68
|
+
prefix (str, optional): the directory on S3 used to save files, default
|
|
69
|
+
to the root of ``destination``
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
(str): destination URI
|
|
73
|
+
"""
|
|
74
|
+
parsed_uri = urlparse(destination)
|
|
75
|
+
if parsed_uri.scheme == "file":
|
|
76
|
+
dir_path = os.path.abspath(parsed_uri.netloc + parsed_uri.path)
|
|
77
|
+
recursive_copy(source, dir_path)
|
|
78
|
+
final_uri = destination
|
|
79
|
+
elif parsed_uri.scheme == "s3":
|
|
80
|
+
bucket = parsed_uri.netloc
|
|
81
|
+
path = s3.s3_path_join(parsed_uri.path, job_name, prefix)
|
|
82
|
+
final_uri = s3.s3_path_join("s3://", bucket, path)
|
|
83
|
+
sagemaker_session.upload_data(source, bucket, path)
|
|
84
|
+
else:
|
|
85
|
+
raise ValueError("Invalid destination URI, must be s3:// or file://, got: %s" % destination)
|
|
86
|
+
|
|
87
|
+
try:
|
|
88
|
+
shutil.rmtree(source)
|
|
89
|
+
except OSError as exc:
|
|
90
|
+
# on Linux, when docker writes to any mounted volume, it uses the container's user. In most
|
|
91
|
+
# cases this is root. When the container exits and we try to delete them we can't because
|
|
92
|
+
# root owns those files. We expect this to happen, so we handle EACCESS. Any other error
|
|
93
|
+
# we will raise the exception up.
|
|
94
|
+
if exc.errno == errno.EACCES:
|
|
95
|
+
logger.warning("Failed to delete: %s Please remove it manually.", source)
|
|
96
|
+
else:
|
|
97
|
+
logger.error("Failed to delete: %s", source)
|
|
98
|
+
raise
|
|
99
|
+
|
|
100
|
+
return final_uri
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def recursive_copy(source, destination):
|
|
104
|
+
"""A wrapper around shutil.copy_tree.
|
|
105
|
+
|
|
106
|
+
This won't throw any exception when the source directory does not exist.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
source (str): source path
|
|
110
|
+
destination (str): destination path
|
|
111
|
+
"""
|
|
112
|
+
if os.path.isdir(source):
|
|
113
|
+
shutil.copytree(source, destination, dirs_exist_ok=True)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def kill_child_processes(pid):
|
|
117
|
+
"""Kill child processes
|
|
118
|
+
|
|
119
|
+
Kills all nested child process ids for a specific pid
|
|
120
|
+
|
|
121
|
+
Args:
|
|
122
|
+
pid (int): process id
|
|
123
|
+
"""
|
|
124
|
+
child_pids = get_child_process_ids(pid)
|
|
125
|
+
for child_pid in child_pids:
|
|
126
|
+
os.kill(child_pid, 15)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def get_child_process_ids(pid):
|
|
130
|
+
"""Retrieve all child pids for a certain pid
|
|
131
|
+
|
|
132
|
+
Recursively scan each childs process tree and add it to the output
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
pid (int): process id
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
(List[int]): Child process ids
|
|
139
|
+
"""
|
|
140
|
+
cmd = f"pgrep -P {pid}".split()
|
|
141
|
+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
142
|
+
output, err = process.communicate()
|
|
143
|
+
if err:
|
|
144
|
+
return []
|
|
145
|
+
pids = [int(pid) for pid in output.decode("utf-8").split()]
|
|
146
|
+
if pids:
|
|
147
|
+
for child_pid in pids:
|
|
148
|
+
return pids + get_child_process_ids(child_pid)
|
|
149
|
+
else:
|
|
150
|
+
return []
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def get_docker_host():
|
|
154
|
+
"""Discover remote docker host address (if applicable) or use "localhost"
|
|
155
|
+
|
|
156
|
+
Use "docker context inspect" to read current docker host endpoint url,
|
|
157
|
+
url must start with "tcp://"
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
docker_host (str): Docker host DNS or IP address
|
|
163
|
+
"""
|
|
164
|
+
cmd = "docker context inspect".split()
|
|
165
|
+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
166
|
+
output, err = process.communicate()
|
|
167
|
+
if err:
|
|
168
|
+
return "localhost"
|
|
169
|
+
docker_context_string = output.decode("utf-8")
|
|
170
|
+
docker_context_host_url = json.loads(docker_context_string)[0]["Endpoints"]["docker"]["Host"]
|
|
171
|
+
parsed_url = urlparse(docker_context_host_url)
|
|
172
|
+
if parsed_url.hostname and parsed_url.scheme == "tcp":
|
|
173
|
+
return parsed_url.hostname
|
|
174
|
+
return "localhost"
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def get_using_dot_notation(dictionary, keys):
|
|
178
|
+
"""Extract `keys` from dictionary where keys is a string in dot notation.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
dictionary (Dict)
|
|
182
|
+
keys (str)
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
Nested object within dictionary as defined by "keys"
|
|
186
|
+
|
|
187
|
+
Raises:
|
|
188
|
+
ValueError if the provided key does not exist in input dictionary
|
|
189
|
+
"""
|
|
190
|
+
try:
|
|
191
|
+
if keys is None:
|
|
192
|
+
return dictionary
|
|
193
|
+
split_keys = keys.split(".", 1)
|
|
194
|
+
key = split_keys[0]
|
|
195
|
+
rest = None
|
|
196
|
+
if len(split_keys) > 1:
|
|
197
|
+
rest = split_keys[1]
|
|
198
|
+
bracket_accessors = re.findall(r"\[(.+?)]", key)
|
|
199
|
+
if bracket_accessors:
|
|
200
|
+
pre_bracket_key = key.split("[", 1)[0]
|
|
201
|
+
inner_dict = dictionary[pre_bracket_key]
|
|
202
|
+
else:
|
|
203
|
+
inner_dict = dictionary[key]
|
|
204
|
+
for bracket_accessor in bracket_accessors:
|
|
205
|
+
if (
|
|
206
|
+
bracket_accessor.startswith("'")
|
|
207
|
+
and bracket_accessor.endswith("'")
|
|
208
|
+
or bracket_accessor.startswith('"')
|
|
209
|
+
and bracket_accessor.endswith('"')
|
|
210
|
+
):
|
|
211
|
+
# key accessor
|
|
212
|
+
inner_key = bracket_accessor[1:-1]
|
|
213
|
+
else:
|
|
214
|
+
# list accessor
|
|
215
|
+
inner_key = int(bracket_accessor)
|
|
216
|
+
inner_dict = inner_dict[inner_key]
|
|
217
|
+
return get_using_dot_notation(inner_dict, rest)
|
|
218
|
+
except (KeyError, IndexError, TypeError):
|
|
219
|
+
raise ValueError(f"{keys} does not exist in input dictionary.")
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def check_for_studio():
|
|
223
|
+
"""Helper function to determine if the run environment is studio.
|
|
224
|
+
|
|
225
|
+
Returns (bool): Returns True if valid Studio request.
|
|
226
|
+
|
|
227
|
+
Raises:
|
|
228
|
+
NotImplementedError:
|
|
229
|
+
if run environment = Studio and AppType not in STUDIO_APP_TYPES
|
|
230
|
+
"""
|
|
231
|
+
is_studio = False
|
|
232
|
+
if os.path.exists("/opt/ml/metadata/resource-metadata.json"):
|
|
233
|
+
with open("/opt/ml/metadata/resource-metadata.json", "r") as handle:
|
|
234
|
+
metadata = json.load(handle)
|
|
235
|
+
app_type = metadata.get("AppType")
|
|
236
|
+
if app_type:
|
|
237
|
+
# check if the execution is triggered from Studio KernelGateway App
|
|
238
|
+
if app_type in STUDIO_APP_TYPES:
|
|
239
|
+
is_studio = True
|
|
240
|
+
else:
|
|
241
|
+
raise NotImplementedError(
|
|
242
|
+
f"AppType {app_type} in Studio does not support Local Mode."
|
|
243
|
+
)
|
|
244
|
+
# if no apptype, case of classic notebooks
|
|
245
|
+
return is_studio
|
sagemaker/core/logs.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
import collections
|
|
17
|
+
import functools
|
|
18
|
+
import os
|
|
19
|
+
import sys
|
|
20
|
+
|
|
21
|
+
##############################################################################
|
|
22
|
+
#
|
|
23
|
+
# Support for reading logs
|
|
24
|
+
#
|
|
25
|
+
##############################################################################
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ColorWrap(object):
|
|
29
|
+
"""A callable that will print text in a different color depending on the instance.
|
|
30
|
+
|
|
31
|
+
Up to 6 if standard output is a terminal or a Jupyter notebook cell.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
# For what color each number represents, see
|
|
35
|
+
# https://misc.flogisoft.com/bash/tip_colors_and_formatting#colors
|
|
36
|
+
_stream_colors = [34, 35, 32, 36, 33]
|
|
37
|
+
|
|
38
|
+
def __init__(self, force=False):
|
|
39
|
+
"""Initialize the class.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
force (bool): If True, render colorizes output no matter where the
|
|
43
|
+
output is (default: False).
|
|
44
|
+
"""
|
|
45
|
+
self.colorize = force or sys.stdout.isatty() or os.environ.get("JPY_PARENT_PID", None)
|
|
46
|
+
|
|
47
|
+
def __call__(self, index, s):
|
|
48
|
+
"""Print the output, colorized or not, depending on the environment.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
index (int): The instance number.
|
|
52
|
+
s (str): The string to print.
|
|
53
|
+
"""
|
|
54
|
+
if self.colorize:
|
|
55
|
+
self._color_wrap(index, s)
|
|
56
|
+
else:
|
|
57
|
+
print(s)
|
|
58
|
+
|
|
59
|
+
def _color_wrap(self, index, s):
|
|
60
|
+
"""Placeholder docstring"""
|
|
61
|
+
print("\x1b[{}m{}\x1b[0m".format(self._stream_colors[index % len(self._stream_colors)], s))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def argmin(arr, f):
|
|
65
|
+
"""Return the index, i, in arr that minimizes f(arr[i])
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
arr:
|
|
69
|
+
f:
|
|
70
|
+
"""
|
|
71
|
+
m = None
|
|
72
|
+
i = None
|
|
73
|
+
for idx, item in enumerate(arr):
|
|
74
|
+
if item is not None:
|
|
75
|
+
if m is None or f(item) < m:
|
|
76
|
+
m = f(item)
|
|
77
|
+
i = idx
|
|
78
|
+
return i
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def some(arr):
|
|
82
|
+
"""Return True iff there is an element, a, of arr such that a is not None.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
arr:
|
|
86
|
+
"""
|
|
87
|
+
return functools.reduce(lambda x, y: x or (y is not None), arr, False)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# Position is a tuple that includes the last read timestamp and the number of items that were read
|
|
91
|
+
# at that time. This is used to figure out which event to start with on the next read.
|
|
92
|
+
Position = collections.namedtuple("Position", ["timestamp", "skip"])
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def multi_stream_iter(client, log_group, streams, positions=None):
|
|
96
|
+
"""Iterate over the available events coming from a set of log streams.
|
|
97
|
+
|
|
98
|
+
Log streams are in a single log group interleaving the events from each stream
|
|
99
|
+
so they're yielded in timestamp order.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
client (boto3 client): The boto client for logs.
|
|
103
|
+
log_group (str): The name of the log group.
|
|
104
|
+
streams (list of str): A list of the log stream names. The position of the stream in
|
|
105
|
+
this list is the stream number.
|
|
106
|
+
positions: (list of Positions): A list of pairs of (timestamp, skip) which represents
|
|
107
|
+
the last record read from each stream.
|
|
108
|
+
|
|
109
|
+
Yields:
|
|
110
|
+
A tuple of (stream number, cloudwatch log event).
|
|
111
|
+
"""
|
|
112
|
+
positions = positions or {s: Position(timestamp=0, skip=0) for s in streams}
|
|
113
|
+
event_iters = [
|
|
114
|
+
log_stream(client, log_group, s, positions[s].timestamp, positions[s].skip) for s in streams
|
|
115
|
+
]
|
|
116
|
+
events = []
|
|
117
|
+
for s in event_iters:
|
|
118
|
+
if not s:
|
|
119
|
+
events.append(None)
|
|
120
|
+
continue
|
|
121
|
+
try:
|
|
122
|
+
events.append(next(s))
|
|
123
|
+
except StopIteration:
|
|
124
|
+
events.append(None)
|
|
125
|
+
|
|
126
|
+
while some(events):
|
|
127
|
+
i = argmin(events, lambda x: x["timestamp"] if x else 9999999999)
|
|
128
|
+
yield (i, events[i])
|
|
129
|
+
try:
|
|
130
|
+
events[i] = next(event_iters[i])
|
|
131
|
+
except StopIteration:
|
|
132
|
+
events[i] = None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def log_stream(client, log_group, stream_name, start_time=0, skip=0):
|
|
136
|
+
"""A generator for log items in a single stream.
|
|
137
|
+
|
|
138
|
+
This will yield all the items that are available at the current moment.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
client (boto3.CloudWatchLogs.Client): The Boto client for CloudWatch logs.
|
|
142
|
+
log_group (str): The name of the log group.
|
|
143
|
+
stream_name (str): The name of the specific stream.
|
|
144
|
+
start_time (int): The time stamp value to start reading the logs from (default: 0).
|
|
145
|
+
skip (int): The number of log entries to skip at the start (default: 0). This is for
|
|
146
|
+
when there are multiple entries at the same timestamp.
|
|
147
|
+
|
|
148
|
+
Yields:
|
|
149
|
+
dict: A CloudWatch log event with the following key-value pairs:
|
|
150
|
+
'timestamp' (int): The time of the event.
|
|
151
|
+
'message' (str): The log event data.
|
|
152
|
+
'ingestionTime' (int): The time the event was ingested.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
next_token = None
|
|
156
|
+
|
|
157
|
+
event_count = 1
|
|
158
|
+
while event_count > 0:
|
|
159
|
+
if next_token is not None:
|
|
160
|
+
token_arg = {"nextToken": next_token}
|
|
161
|
+
else:
|
|
162
|
+
token_arg = {}
|
|
163
|
+
|
|
164
|
+
response = client.get_log_events(
|
|
165
|
+
logGroupName=log_group,
|
|
166
|
+
logStreamName=stream_name,
|
|
167
|
+
startTime=start_time,
|
|
168
|
+
startFromHead=True,
|
|
169
|
+
**token_arg,
|
|
170
|
+
)
|
|
171
|
+
next_token = response["nextForwardToken"]
|
|
172
|
+
events = response["events"]
|
|
173
|
+
event_count = len(events)
|
|
174
|
+
if event_count > skip:
|
|
175
|
+
events = events[skip:]
|
|
176
|
+
skip = 0
|
|
177
|
+
else:
|
|
178
|
+
skip = skip - event_count
|
|
179
|
+
events = []
|
|
180
|
+
for ev in events:
|
|
181
|
+
yield ev
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
|
4
|
+
# may not use this file except in compliance with the License. A copy of
|
|
5
|
+
# the License is located at
|
|
6
|
+
#
|
|
7
|
+
# http://aws.amazon.com/apache2.0/
|
|
8
|
+
#
|
|
9
|
+
# or in the "license" file accompanying this file. This file is
|
|
10
|
+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
|
11
|
+
# ANY KIND, either express or implied. See the License for the specific
|
|
12
|
+
# language governing permissions and limitations under the License.
|
|
13
|
+
"""This file contains code related to metadata properties."""
|
|
14
|
+
from __future__ import absolute_import
|
|
15
|
+
|
|
16
|
+
from typing import Optional, Union
|
|
17
|
+
|
|
18
|
+
from sagemaker.core.helper.pipeline_variable import PipelineVariable
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MetadataProperties(object):
|
|
22
|
+
"""Accepts metadata properties parameters for conversion to request dict."""
|
|
23
|
+
|
|
24
|
+
def __init__(
|
|
25
|
+
self,
|
|
26
|
+
commit_id: Optional[Union[str, PipelineVariable]] = None,
|
|
27
|
+
repository: Optional[Union[str, PipelineVariable]] = None,
|
|
28
|
+
generated_by: Optional[Union[str, PipelineVariable]] = None,
|
|
29
|
+
project_id: Optional[Union[str, PipelineVariable]] = None,
|
|
30
|
+
):
|
|
31
|
+
"""Initialize a ``MetadataProperties`` instance and turn parameters into dict.
|
|
32
|
+
|
|
33
|
+
# TODO: flesh out docstrings
|
|
34
|
+
Args:
|
|
35
|
+
commit_id (str or PipelineVariable):
|
|
36
|
+
repository (str or PipelineVariable):
|
|
37
|
+
generated_by (str or PipelineVariable):
|
|
38
|
+
project_id (str or PipelineVariable):
|
|
39
|
+
"""
|
|
40
|
+
self.commit_id = commit_id
|
|
41
|
+
self.repository = repository
|
|
42
|
+
self.generated_by = generated_by
|
|
43
|
+
self.project_id = project_id
|
|
44
|
+
|
|
45
|
+
def _to_request_dict(self):
|
|
46
|
+
"""Generates a request dictionary using the parameters provided to the class."""
|
|
47
|
+
metadata_properties_request = dict()
|
|
48
|
+
if self.commit_id:
|
|
49
|
+
metadata_properties_request["CommitId"] = self.commit_id
|
|
50
|
+
if self.repository:
|
|
51
|
+
metadata_properties_request["Repository"] = self.repository
|
|
52
|
+
if self.generated_by:
|
|
53
|
+
metadata_properties_request["GeneratedBy"] = self.generated_by
|
|
54
|
+
if self.project_id:
|
|
55
|
+
metadata_properties_request["ProjectId"] = self.project_id
|
|
56
|
+
return metadata_properties_request
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
"""Accessors to retrieve metric definition for training jobs."""
|
|
14
|
+
|
|
15
|
+
from __future__ import absolute_import
|
|
16
|
+
|
|
17
|
+
import logging
|
|
18
|
+
from typing import Dict, Optional, List
|
|
19
|
+
|
|
20
|
+
from sagemaker.core.jumpstart import utils as jumpstart_utils
|
|
21
|
+
from sagemaker.core.jumpstart import artifacts
|
|
22
|
+
from sagemaker.core.jumpstart.constants import DEFAULT_JUMPSTART_SAGEMAKER_SESSION
|
|
23
|
+
from sagemaker.core.jumpstart.enums import JumpStartModelType
|
|
24
|
+
from sagemaker.core.helper.session_helper import Session
|
|
25
|
+
|
|
26
|
+
logger = logging.getLogger(__name__)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def retrieve_default(
|
|
30
|
+
region: Optional[str] = None,
|
|
31
|
+
model_id: Optional[str] = None,
|
|
32
|
+
model_version: Optional[str] = None,
|
|
33
|
+
hub_arn: Optional[str] = None,
|
|
34
|
+
instance_type: Optional[str] = None,
|
|
35
|
+
tolerate_vulnerable_model: bool = False,
|
|
36
|
+
tolerate_deprecated_model: bool = False,
|
|
37
|
+
sagemaker_session: Session = DEFAULT_JUMPSTART_SAGEMAKER_SESSION,
|
|
38
|
+
config_name: Optional[str] = None,
|
|
39
|
+
model_type: JumpStartModelType = JumpStartModelType.OPEN_WEIGHTS,
|
|
40
|
+
) -> Optional[List[Dict[str, str]]]:
|
|
41
|
+
"""Retrieves the default training metric definitions for the model matching the given arguments.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
region (str): The AWS Region for which to retrieve the default default training metric
|
|
45
|
+
definitions. Defaults to ``None``.
|
|
46
|
+
model_id (str): The model ID of the model for which to
|
|
47
|
+
retrieve the default training metric definitions. (Default: None).
|
|
48
|
+
model_version (str): The version of the model for which to retrieve the
|
|
49
|
+
default training metric definitions. (Default: None).
|
|
50
|
+
hub_arn (str): The arn of the SageMaker Hub for which to retrieve
|
|
51
|
+
model details from. (default: None).
|
|
52
|
+
instance_type (str): An instance type to optionally supply in order to get
|
|
53
|
+
metric definitions specific for the instance type.
|
|
54
|
+
tolerate_vulnerable_model (bool): True if vulnerable versions of model
|
|
55
|
+
specifications should be tolerated (exception not raised). If False, raises an
|
|
56
|
+
exception if the script used by this version of the model has dependencies with known
|
|
57
|
+
security vulnerabilities. (Default: False).
|
|
58
|
+
tolerate_deprecated_model (bool): True if deprecated models should be tolerated
|
|
59
|
+
(exception not raised). False if these models should raise an exception.
|
|
60
|
+
(Default: False).
|
|
61
|
+
sagemaker_session (sagemaker.session.Session): A SageMaker Session
|
|
62
|
+
object, used for SageMaker interactions. If not
|
|
63
|
+
specified, one is created using the default AWS configuration
|
|
64
|
+
chain. (Default: sagemaker.jumpstart.constants.DEFAULT_JUMPSTART_SAGEMAKER_SESSION).
|
|
65
|
+
config_name (Optional[str]): Name of the JumpStart Model config to apply. (Default: None).
|
|
66
|
+
model_type (JumpStartModelType): The type of the model, can be open weights model
|
|
67
|
+
or proprietary model. (Default: JumpStartModelType.OPEN_WEIGHTS).
|
|
68
|
+
Returns:
|
|
69
|
+
list: The default metric definitions to use for the model or None.
|
|
70
|
+
|
|
71
|
+
Raises:
|
|
72
|
+
ValueError: If the combination of arguments specified is not supported.
|
|
73
|
+
"""
|
|
74
|
+
if not jumpstart_utils.is_jumpstart_model_input(model_id, model_version):
|
|
75
|
+
raise ValueError(
|
|
76
|
+
"Must specify JumpStart `model_id` and `model_version` "
|
|
77
|
+
"when retrieving default training metric definitions."
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
return artifacts._retrieve_default_training_metric_definitions(
|
|
81
|
+
model_id=model_id,
|
|
82
|
+
model_version=model_version,
|
|
83
|
+
hub_arn=hub_arn,
|
|
84
|
+
instance_type=instance_type,
|
|
85
|
+
region=region,
|
|
86
|
+
tolerate_vulnerable_model=tolerate_vulnerable_model,
|
|
87
|
+
tolerate_deprecated_model=tolerate_deprecated_model,
|
|
88
|
+
sagemaker_session=sagemaker_session,
|
|
89
|
+
config_name=config_name,
|
|
90
|
+
model_type=model_type,
|
|
91
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
"""MLflow integration module - stub.
|
|
14
|
+
|
|
15
|
+
This module provides stubs for MLflow integration functionality.
|
|
16
|
+
MLflow integration is an optional feature that requires the mlflow package.
|
|
17
|
+
|
|
18
|
+
NOTE: This is a stub module. Full MLflow integration will be implemented
|
|
19
|
+
in a future release.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import absolute_import
|
|
22
|
+
|
|
23
|
+
__all__ = ["forward_sagemaker_metrics"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def forward_sagemaker_metrics(*args, **kwargs):
|
|
27
|
+
"""Stub for MLflow metrics forwarding.
|
|
28
|
+
|
|
29
|
+
This function is not yet implemented. MLflow integration is an optional
|
|
30
|
+
feature that will be added in a future release.
|
|
31
|
+
|
|
32
|
+
Raises:
|
|
33
|
+
NotImplementedError: Always raised as this is a stub.
|
|
34
|
+
"""
|
|
35
|
+
raise NotImplementedError(
|
|
36
|
+
"MLflow integration is not yet implemented. "
|
|
37
|
+
"This feature will be added in a future release."
|
|
38
|
+
)
|
|
@@ -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
|
+
"""MLflow metrics forwarding module - stub.
|
|
14
|
+
|
|
15
|
+
This module provides stubs for forwarding SageMaker metrics to MLflow.
|
|
16
|
+
MLflow integration is an optional feature that requires the mlflow package.
|
|
17
|
+
|
|
18
|
+
NOTE: This is a stub module. Full MLflow integration will be implemented
|
|
19
|
+
in a future release.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import absolute_import
|
|
22
|
+
|
|
23
|
+
__all__ = ["log_sagemaker_job_to_mlflow"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def log_sagemaker_job_to_mlflow(job_name, *args, **kwargs):
|
|
27
|
+
"""Stub for logging SageMaker job metrics to MLflow.
|
|
28
|
+
|
|
29
|
+
This function is not yet implemented. MLflow integration is an optional
|
|
30
|
+
feature that will be added in a future release.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
job_name (str): Name of the SageMaker training job
|
|
34
|
+
*args: Additional positional arguments (ignored)
|
|
35
|
+
**kwargs: Additional keyword arguments (ignored)
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
NotImplementedError: Always raised as this is a stub.
|
|
39
|
+
"""
|
|
40
|
+
raise NotImplementedError(
|
|
41
|
+
"MLflow integration is not yet implemented. "
|
|
42
|
+
"This feature will be added in a future release. "
|
|
43
|
+
f"Cannot log job '{job_name}' to MLflow."
|
|
44
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
"""Model Card utilities for SageMaker Python SDK."""
|
|
14
|
+
from __future__ import absolute_import
|
|
15
|
+
|
|
16
|
+
# Re-export ModelCard from resources
|
|
17
|
+
from sagemaker.core.resources import ModelCard, ModelCardExportJob # noqa: F401
|
|
18
|
+
|
|
19
|
+
# Re-export from shapes
|
|
20
|
+
from sagemaker.core.shapes.model_card_shapes import ( # noqa: F401
|
|
21
|
+
ModelCardContent,
|
|
22
|
+
TrainingDetails,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Alias for backward compatibility
|
|
26
|
+
ModelPackageModelCard = ModelCardContent
|