sagemaker-core 1.0.62__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.
Files changed (362) hide show
  1. sagemaker/core/__init__.py +16 -0
  2. sagemaker/core/_studio.py +116 -0
  3. sagemaker/core/_version.py +11 -0
  4. sagemaker/core/accept_types.py +131 -0
  5. sagemaker/core/analytics.py +744 -0
  6. sagemaker/core/apiutils/__init__.py +13 -0
  7. sagemaker/core/apiutils/_base_types.py +228 -0
  8. sagemaker/core/apiutils/_boto_functions.py +130 -0
  9. sagemaker/core/apiutils/_utils.py +34 -0
  10. sagemaker/core/base_deserializers.py +35 -0
  11. sagemaker/core/base_serializers.py +35 -0
  12. sagemaker/core/clarify/__init__.py +2898 -0
  13. sagemaker/core/collection.py +467 -0
  14. sagemaker/core/common_utils.py +2281 -0
  15. sagemaker/core/compute_resource_requirements/__init__.py +18 -0
  16. sagemaker/core/compute_resource_requirements/resource_requirements.py +94 -0
  17. sagemaker/core/config/__init__.py +181 -0
  18. sagemaker/core/config/config.py +238 -0
  19. sagemaker/core/config/config_manager.py +595 -0
  20. sagemaker/core/config/config_schema.py +1220 -0
  21. sagemaker/core/config/config_utils.py +297 -0
  22. {sagemaker_core/main → sagemaker/core}/config_schema.py +408 -3
  23. sagemaker/core/constants.py +73 -0
  24. sagemaker/core/content_types.py +137 -0
  25. sagemaker/core/debugger/__init__.py +39 -0
  26. sagemaker/core/debugger/debugger.py +945 -0
  27. sagemaker/core/debugger/framework_profile.py +292 -0
  28. sagemaker/core/debugger/metrics_config.py +468 -0
  29. sagemaker/core/debugger/profiler.py +42 -0
  30. sagemaker/core/debugger/profiler_config.py +190 -0
  31. sagemaker/core/debugger/profiler_constants.py +40 -0
  32. sagemaker/core/debugger/utils.py +148 -0
  33. sagemaker/core/deprecations.py +254 -0
  34. sagemaker/core/deserializers/__init__.py +10 -0
  35. sagemaker/core/deserializers/base.py +424 -0
  36. sagemaker/core/deserializers/implementations.py +157 -0
  37. sagemaker/core/drift_check_baselines.py +106 -0
  38. sagemaker/core/enums.py +51 -0
  39. sagemaker/core/environment_variables.py +101 -0
  40. sagemaker/core/exceptions.py +108 -0
  41. sagemaker/core/experiments/__init__.py +53 -0
  42. sagemaker/core/experiments/_api_types.py +251 -0
  43. sagemaker/core/experiments/_environment.py +124 -0
  44. sagemaker/core/experiments/_helper.py +294 -0
  45. sagemaker/core/experiments/_metrics.py +333 -0
  46. sagemaker/core/experiments/_run_context.py +58 -0
  47. sagemaker/core/experiments/_utils.py +216 -0
  48. sagemaker/core/experiments/experiment.py +244 -0
  49. sagemaker/core/experiments/run.py +970 -0
  50. sagemaker/core/experiments/trial.py +296 -0
  51. sagemaker/core/experiments/trial_component.py +387 -0
  52. sagemaker/core/explainer/__init__.py +24 -0
  53. sagemaker/core/explainer/clarify_explainer_config.py +298 -0
  54. sagemaker/core/explainer/explainer_config.py +44 -0
  55. sagemaker/core/fw_utils.py +1176 -0
  56. sagemaker/core/git_utils.py +349 -0
  57. sagemaker/core/helper/pipeline_variable.py +82 -0
  58. sagemaker/core/helper/session_helper.py +2965 -0
  59. sagemaker/core/huggingface/__init__.py +29 -0
  60. sagemaker/core/huggingface/llm_utils.py +150 -0
  61. sagemaker/core/huggingface/processing.py +139 -0
  62. sagemaker/core/huggingface/training_compiler/config.py +167 -0
  63. sagemaker/core/hyperparameters.py +172 -0
  64. sagemaker/core/image_retriever/__init__.py +3 -0
  65. sagemaker/core/image_retriever/image_retriever.py +640 -0
  66. sagemaker/core/image_retriever/image_retriever_utils.py +511 -0
  67. sagemaker/core/image_retriever/test.py +7 -0
  68. sagemaker/core/image_uri_config/__init__.py +13 -0
  69. sagemaker/core/image_uri_config/autogluon.json +1335 -0
  70. sagemaker/core/image_uri_config/blazingtext.json +50 -0
  71. sagemaker/core/image_uri_config/chainer.json +104 -0
  72. sagemaker/core/image_uri_config/clarify.json +39 -0
  73. sagemaker/core/image_uri_config/coach-mxnet.json +70 -0
  74. sagemaker/core/image_uri_config/coach-tensorflow.json +186 -0
  75. sagemaker/core/image_uri_config/data-wrangler.json +91 -0
  76. sagemaker/core/image_uri_config/debugger.json +34 -0
  77. sagemaker/core/image_uri_config/detailed-profiler.json +18 -0
  78. sagemaker/core/image_uri_config/djl-deepspeed.json +385 -0
  79. sagemaker/core/image_uri_config/djl-fastertransformer.json +167 -0
  80. sagemaker/core/image_uri_config/djl-lmi.json +136 -0
  81. sagemaker/core/image_uri_config/djl-neuronx.json +258 -0
  82. sagemaker/core/image_uri_config/djl-tensorrtllm.json +262 -0
  83. sagemaker/core/image_uri_config/factorization-machines.json +50 -0
  84. sagemaker/core/image_uri_config/forecasting-deepar.json +50 -0
  85. sagemaker/core/image_uri_config/huggingface-llm-neuronx.json +660 -0
  86. sagemaker/core/image_uri_config/huggingface-llm.json +1158 -0
  87. sagemaker/core/image_uri_config/huggingface-neuron.json +52 -0
  88. sagemaker/core/image_uri_config/huggingface-neuronx.json +510 -0
  89. sagemaker/core/image_uri_config/huggingface-tei-cpu.json +298 -0
  90. sagemaker/core/image_uri_config/huggingface-tei.json +298 -0
  91. sagemaker/core/image_uri_config/huggingface-training-compiler.json +195 -0
  92. sagemaker/core/image_uri_config/huggingface.json +2138 -0
  93. sagemaker/core/image_uri_config/hyperpod-recipes-neuron.json +52 -0
  94. sagemaker/core/image_uri_config/image-classification-neo.json +43 -0
  95. sagemaker/core/image_uri_config/image-classification.json +50 -0
  96. sagemaker/core/image_uri_config/inferentia-mxnet.json +88 -0
  97. sagemaker/core/image_uri_config/inferentia-pytorch.json +127 -0
  98. sagemaker/core/image_uri_config/inferentia-tensorflow.json +88 -0
  99. sagemaker/core/image_uri_config/instance_gpu_info.json +782 -0
  100. sagemaker/core/image_uri_config/ipinsights.json +50 -0
  101. sagemaker/core/image_uri_config/kmeans.json +50 -0
  102. sagemaker/core/image_uri_config/knn.json +50 -0
  103. sagemaker/core/image_uri_config/lda.json +26 -0
  104. sagemaker/core/image_uri_config/linear-learner.json +50 -0
  105. sagemaker/core/image_uri_config/model-monitor.json +42 -0
  106. sagemaker/core/image_uri_config/mxnet.json +1154 -0
  107. sagemaker/core/image_uri_config/neo-mxnet.json +64 -0
  108. sagemaker/core/image_uri_config/neo-pytorch.json +341 -0
  109. sagemaker/core/image_uri_config/neo-tensorflow.json +109 -0
  110. sagemaker/core/image_uri_config/ntm.json +50 -0
  111. sagemaker/core/image_uri_config/object-detection.json +50 -0
  112. sagemaker/core/image_uri_config/object2vec.json +50 -0
  113. sagemaker/core/image_uri_config/pca.json +50 -0
  114. sagemaker/core/image_uri_config/pytorch-neuron.json +43 -0
  115. sagemaker/core/image_uri_config/pytorch-smp.json +218 -0
  116. sagemaker/core/image_uri_config/pytorch-training-compiler.json +80 -0
  117. sagemaker/core/image_uri_config/pytorch.json +3101 -0
  118. sagemaker/core/image_uri_config/randomcutforest.json +50 -0
  119. sagemaker/core/image_uri_config/ray-pytorch.json +46 -0
  120. sagemaker/core/image_uri_config/ray-tensorflow.json +194 -0
  121. sagemaker/core/image_uri_config/sagemaker-base-python.json +46 -0
  122. sagemaker/core/image_uri_config/sagemaker-distribution.json +37 -0
  123. sagemaker/core/image_uri_config/sagemaker-geospatial.json +13 -0
  124. sagemaker/core/image_uri_config/sagemaker-tritonserver.json +212 -0
  125. sagemaker/core/image_uri_config/semantic-segmentation.json +50 -0
  126. sagemaker/core/image_uri_config/seq2seq.json +50 -0
  127. sagemaker/core/image_uri_config/sklearn.json +446 -0
  128. sagemaker/core/image_uri_config/spark.json +280 -0
  129. sagemaker/core/image_uri_config/sparkml-serving.json +97 -0
  130. sagemaker/core/image_uri_config/stabilityai.json +53 -0
  131. sagemaker/core/image_uri_config/tensorflow.json +5086 -0
  132. sagemaker/core/image_uri_config/vw.json +25 -0
  133. sagemaker/core/image_uri_config/xgboost-neo.json +43 -0
  134. sagemaker/core/image_uri_config/xgboost.json +888 -0
  135. sagemaker/core/image_uris.py +810 -0
  136. sagemaker/core/inference_config.py +144 -0
  137. sagemaker/core/inference_recommender/__init__.py +18 -0
  138. sagemaker/core/inference_recommender/inference_recommender_mixin.py +622 -0
  139. sagemaker/core/inputs.py +366 -0
  140. sagemaker/core/instance_group.py +61 -0
  141. sagemaker/core/instance_types.py +164 -0
  142. sagemaker/core/instance_types_gpu_info.py +43 -0
  143. sagemaker/core/interactive_apps/__init__.py +41 -0
  144. sagemaker/core/interactive_apps/base_interactive_app.py +204 -0
  145. sagemaker/core/interactive_apps/detail_profiler_app.py +139 -0
  146. sagemaker/core/interactive_apps/tensorboard.py +149 -0
  147. sagemaker/core/iterators.py +186 -0
  148. sagemaker/core/job.py +380 -0
  149. sagemaker/core/jumpstart/__init__.py +156 -0
  150. sagemaker/core/jumpstart/accessors.py +390 -0
  151. sagemaker/core/jumpstart/artifacts/__init__.py +69 -0
  152. sagemaker/core/jumpstart/artifacts/environment_variables.py +252 -0
  153. sagemaker/core/jumpstart/artifacts/hyperparameters.py +120 -0
  154. sagemaker/core/jumpstart/artifacts/image_uris.py +139 -0
  155. sagemaker/core/jumpstart/artifacts/incremental_training.py +87 -0
  156. sagemaker/core/jumpstart/artifacts/instance_types.py +223 -0
  157. sagemaker/core/jumpstart/artifacts/kwargs.py +289 -0
  158. sagemaker/core/jumpstart/artifacts/metric_definitions.py +117 -0
  159. sagemaker/core/jumpstart/artifacts/model_packages.py +202 -0
  160. sagemaker/core/jumpstart/artifacts/model_uris.py +252 -0
  161. sagemaker/core/jumpstart/artifacts/payloads.py +96 -0
  162. sagemaker/core/jumpstart/artifacts/predictors.py +540 -0
  163. sagemaker/core/jumpstart/artifacts/resource_names.py +86 -0
  164. sagemaker/core/jumpstart/artifacts/resource_requirements.py +162 -0
  165. sagemaker/core/jumpstart/artifacts/script_uris.py +172 -0
  166. sagemaker/core/jumpstart/cache.py +663 -0
  167. sagemaker/core/jumpstart/configs.py +50 -0
  168. sagemaker/core/jumpstart/constants.py +198 -0
  169. sagemaker/core/jumpstart/deserializers.py +81 -0
  170. sagemaker/core/jumpstart/document.py +76 -0
  171. sagemaker/core/jumpstart/enums.py +168 -0
  172. sagemaker/core/jumpstart/exceptions.py +236 -0
  173. sagemaker/core/jumpstart/factory/utils.py +833 -0
  174. sagemaker/core/jumpstart/filters.py +597 -0
  175. sagemaker/core/jumpstart/hub/constants.py +16 -0
  176. sagemaker/core/jumpstart/hub/hub.py +291 -0
  177. sagemaker/core/jumpstart/hub/interfaces.py +936 -0
  178. sagemaker/core/jumpstart/hub/parser_utils.py +70 -0
  179. sagemaker/core/jumpstart/hub/parsers.py +288 -0
  180. sagemaker/core/jumpstart/hub/types.py +35 -0
  181. sagemaker/core/jumpstart/hub/utils.py +260 -0
  182. sagemaker/core/jumpstart/models.py +499 -0
  183. sagemaker/core/jumpstart/notebook_utils.py +575 -0
  184. sagemaker/core/jumpstart/parameters.py +20 -0
  185. sagemaker/core/jumpstart/payload_utils.py +239 -0
  186. sagemaker/core/jumpstart/region_config.json +163 -0
  187. sagemaker/core/jumpstart/search.py +171 -0
  188. sagemaker/core/jumpstart/serializers.py +81 -0
  189. sagemaker/core/jumpstart/session_utils.py +234 -0
  190. sagemaker/core/jumpstart/types.py +3044 -0
  191. sagemaker/core/jumpstart/utils.py +1731 -0
  192. sagemaker/core/jumpstart/validators.py +257 -0
  193. sagemaker/core/lambda_helper.py +312 -0
  194. sagemaker/core/lineage/__init__.py +42 -0
  195. sagemaker/core/lineage/_api_types.py +239 -0
  196. sagemaker/core/lineage/_utils.py +49 -0
  197. sagemaker/core/lineage/action.py +345 -0
  198. sagemaker/core/lineage/artifact.py +646 -0
  199. sagemaker/core/lineage/association.py +190 -0
  200. sagemaker/core/lineage/context.py +505 -0
  201. sagemaker/core/lineage/lineage_trial_component.py +191 -0
  202. sagemaker/core/lineage/query.py +732 -0
  203. sagemaker/core/lineage/visualizer.py +346 -0
  204. sagemaker/core/local/__init__.py +18 -0
  205. sagemaker/core/local/data.py +413 -0
  206. sagemaker/core/local/entities.py +678 -0
  207. sagemaker/core/local/exceptions.py +17 -0
  208. sagemaker/core/local/image.py +1243 -0
  209. sagemaker/core/local/local_session.py +739 -0
  210. sagemaker/core/local/utils.py +245 -0
  211. sagemaker/core/logs.py +181 -0
  212. sagemaker/core/metadata_properties.py +56 -0
  213. sagemaker/core/metric_definitions.py +91 -0
  214. sagemaker/core/mlflow/__init__.py +38 -0
  215. sagemaker/core/mlflow/forward_sagemaker_metrics.py +44 -0
  216. sagemaker/core/model_card/__init__.py +26 -0
  217. sagemaker/core/model_life_cycle.py +51 -0
  218. sagemaker/core/model_metrics.py +160 -0
  219. sagemaker/core/model_monitor/__init__.py +66 -0
  220. sagemaker/core/model_monitor/clarify_model_monitoring.py +1495 -0
  221. sagemaker/core/model_monitor/cron_expression_generator.py +82 -0
  222. sagemaker/core/model_monitor/data_capture_config.py +115 -0
  223. sagemaker/core/model_monitor/data_quality_monitoring_config.py +66 -0
  224. sagemaker/core/model_monitor/dataset_format.py +102 -0
  225. sagemaker/core/model_monitor/model_monitoring.py +4266 -0
  226. sagemaker/core/model_monitor/monitoring_alert.py +76 -0
  227. sagemaker/core/model_monitor/monitoring_files.py +506 -0
  228. sagemaker/core/model_monitor/utils.py +793 -0
  229. sagemaker/core/model_registry.py +480 -0
  230. sagemaker/core/model_uris.py +97 -0
  231. sagemaker/core/modules/__init__.py +19 -0
  232. sagemaker/core/modules/configs.py +226 -0
  233. sagemaker/core/modules/constants.py +37 -0
  234. sagemaker/core/modules/distributed.py +182 -0
  235. sagemaker/core/modules/local_core/__init__.py +0 -0
  236. sagemaker/core/modules/local_core/local_container.py +605 -0
  237. sagemaker/core/modules/templates.py +83 -0
  238. sagemaker/core/modules/train/__init__.py +14 -0
  239. sagemaker/core/modules/train/container_drivers/__init__.py +14 -0
  240. sagemaker/core/modules/train/container_drivers/common/__init__.py +14 -0
  241. sagemaker/core/modules/train/container_drivers/common/utils.py +213 -0
  242. sagemaker/core/modules/train/container_drivers/distributed_drivers/__init__.py +14 -0
  243. sagemaker/core/modules/train/container_drivers/distributed_drivers/basic_script_driver.py +81 -0
  244. sagemaker/core/modules/train/container_drivers/distributed_drivers/mpi_driver.py +123 -0
  245. sagemaker/core/modules/train/container_drivers/distributed_drivers/mpi_utils.py +302 -0
  246. sagemaker/core/modules/train/container_drivers/distributed_drivers/torchrun_driver.py +129 -0
  247. sagemaker/core/modules/train/container_drivers/scripts/__init__.py +14 -0
  248. sagemaker/core/modules/train/container_drivers/scripts/environment.py +305 -0
  249. sagemaker/core/modules/train/sm_recipes/__init__.py +0 -0
  250. sagemaker/core/modules/train/sm_recipes/utils.py +330 -0
  251. sagemaker/core/modules/types.py +19 -0
  252. sagemaker/core/modules/utils.py +194 -0
  253. sagemaker/core/network.py +185 -0
  254. sagemaker/core/parameter.py +173 -0
  255. sagemaker/core/payloads.py +185 -0
  256. sagemaker/core/processing.py +1597 -0
  257. sagemaker/core/remote_function/__init__.py +19 -0
  258. sagemaker/core/remote_function/checkpoint_location.py +47 -0
  259. sagemaker/core/remote_function/client.py +1285 -0
  260. sagemaker/core/remote_function/core/__init__.py +0 -0
  261. sagemaker/core/remote_function/core/_custom_dispatch_table.py +72 -0
  262. sagemaker/core/remote_function/core/pipeline_variables.py +353 -0
  263. sagemaker/core/remote_function/core/serialization.py +422 -0
  264. sagemaker/core/remote_function/core/stored_function.py +226 -0
  265. sagemaker/core/remote_function/custom_file_filter.py +128 -0
  266. sagemaker/core/remote_function/errors.py +104 -0
  267. sagemaker/core/remote_function/invoke_function.py +172 -0
  268. sagemaker/core/remote_function/job.py +2140 -0
  269. sagemaker/core/remote_function/logging_config.py +38 -0
  270. sagemaker/core/remote_function/runtime_environment/__init__.py +14 -0
  271. sagemaker/core/remote_function/runtime_environment/bootstrap_runtime_environment.py +605 -0
  272. sagemaker/core/remote_function/runtime_environment/mpi_utils_remote.py +252 -0
  273. sagemaker/core/remote_function/runtime_environment/runtime_environment_manager.py +554 -0
  274. sagemaker/core/remote_function/runtime_environment/spark_app.py +18 -0
  275. sagemaker/core/remote_function/spark_config.py +149 -0
  276. sagemaker/core/resource_requirements.py +168 -0
  277. {sagemaker_core/main → sagemaker/core}/resources.py +19098 -10895
  278. sagemaker/core/s3/__init__.py +41 -0
  279. sagemaker/core/s3/client.py +367 -0
  280. sagemaker/core/s3/utils.py +175 -0
  281. sagemaker/core/script_uris.py +93 -0
  282. sagemaker/core/serializers/__init__.py +11 -0
  283. sagemaker/core/serializers/base.py +510 -0
  284. sagemaker/core/serializers/implementations.py +159 -0
  285. sagemaker/core/serializers/utils.py +223 -0
  286. sagemaker/core/serverless_inference_config.py +63 -0
  287. sagemaker/core/session_settings.py +55 -0
  288. sagemaker/core/shapes/__init__.py +3 -0
  289. sagemaker/core/shapes/model_card_shapes.py +159 -0
  290. {sagemaker_core/main → sagemaker/core/shapes}/shapes.py +5810 -1806
  291. sagemaker/core/spark/__init__.py +16 -0
  292. sagemaker/core/spark/defaults.py +16 -0
  293. sagemaker/core/spark/processing.py +1380 -0
  294. sagemaker/core/telemetry/__init__.py +23 -0
  295. sagemaker/core/telemetry/constants.py +84 -0
  296. sagemaker/core/telemetry/telemetry_logging.py +284 -0
  297. sagemaker/core/tools/__init__.py +1 -0
  298. {sagemaker_core → sagemaker/core}/tools/codegen.py +4 -4
  299. {sagemaker_core → sagemaker/core}/tools/constants.py +23 -15
  300. {sagemaker_core → sagemaker/core}/tools/data_extractor.py +1 -1
  301. {sagemaker_core → sagemaker/core}/tools/method.py +1 -1
  302. sagemaker/core/tools/model_card/generate_model_card_from_schema.py +562 -0
  303. {sagemaker_core → sagemaker/core}/tools/resources_codegen.py +165 -98
  304. {sagemaker_core → sagemaker/core}/tools/resources_extractor.py +5 -13
  305. {sagemaker_core → sagemaker/core}/tools/shapes_codegen.py +16 -17
  306. {sagemaker_core → sagemaker/core}/tools/shapes_extractor.py +29 -67
  307. {sagemaker_core → sagemaker/core}/tools/templates.py +39 -17
  308. sagemaker/core/training/__init__.py +14 -0
  309. sagemaker/core/training/configs.py +333 -0
  310. sagemaker/core/training/constants.py +37 -0
  311. sagemaker/core/training/utils.py +77 -0
  312. sagemaker/core/training_compiler/__init__.py +16 -0
  313. sagemaker/core/training_compiler/config.py +197 -0
  314. sagemaker/core/training_compiler_config.py +197 -0
  315. sagemaker/core/transformer.py +793 -0
  316. sagemaker/core/user_agent.py +76 -0
  317. sagemaker/core/utilities/__init__.py +24 -0
  318. sagemaker/core/utilities/cache.py +169 -0
  319. sagemaker/core/utilities/search_expression.py +133 -0
  320. sagemaker/core/utils/__init__.py +48 -0
  321. sagemaker/core/utils/code_injection/__init__.py +0 -0
  322. {sagemaker_core/main → sagemaker/core/utils}/code_injection/codec.py +2 -2
  323. {sagemaker_core/main → sagemaker/core/utils}/code_injection/shape_dag.py +5979 -176
  324. {sagemaker_core/main → sagemaker/core/utils}/exceptions.py +8 -8
  325. sagemaker_core/main/default_configs_helper.py → sagemaker/core/utils/intelligent_defaults_helper.py +5 -6
  326. {sagemaker_core/main → sagemaker/core/utils}/logs.py +1 -2
  327. {sagemaker_core/main → sagemaker/core/utils}/utils.py +27 -22
  328. sagemaker/core/workflow/__init__.py +152 -0
  329. sagemaker/core/workflow/conditions.py +313 -0
  330. sagemaker/core/workflow/entities.py +58 -0
  331. sagemaker/core/workflow/execution_variables.py +89 -0
  332. sagemaker/core/workflow/functions.py +193 -0
  333. sagemaker/core/workflow/parameters.py +222 -0
  334. sagemaker/core/workflow/pipeline_context.py +394 -0
  335. sagemaker/core/workflow/pipeline_definition_config.py +31 -0
  336. sagemaker/core/workflow/properties.py +285 -0
  337. sagemaker/core/workflow/step_outputs.py +65 -0
  338. sagemaker/core/workflow/utilities.py +507 -0
  339. sagemaker/lineage/__init__.py +33 -0
  340. sagemaker/lineage/action.py +28 -0
  341. sagemaker/lineage/artifact.py +28 -0
  342. sagemaker/lineage/context.py +28 -0
  343. sagemaker/lineage/lineage_trial_component.py +28 -0
  344. {sagemaker_core-1.0.62.dist-info → sagemaker_core-2.1.1.dist-info}/METADATA +28 -9
  345. sagemaker_core-2.1.1.dist-info/RECORD +355 -0
  346. sagemaker_core-2.1.1.dist-info/top_level.txt +1 -0
  347. sagemaker_core/_version.py +0 -3
  348. sagemaker_core/helper/session_helper.py +0 -769
  349. sagemaker_core/resources/__init__.py +0 -1
  350. sagemaker_core/shapes/__init__.py +0 -1
  351. sagemaker_core/tools/__init__.py +0 -1
  352. sagemaker_core-1.0.62.dist-info/RECORD +0 -35
  353. sagemaker_core-1.0.62.dist-info/top_level.txt +0 -1
  354. {sagemaker_core → sagemaker/core/helper}/__init__.py +0 -0
  355. {sagemaker_core/helper → sagemaker/core/huggingface/training_compiler}/__init__.py +0 -0
  356. {sagemaker_core/main → sagemaker/core/jumpstart/factory}/__init__.py +0 -0
  357. {sagemaker_core/main/code_injection → sagemaker/core/jumpstart/hub}/__init__.py +0 -0
  358. {sagemaker_core/main → sagemaker/core/utils}/code_injection/base.py +0 -0
  359. {sagemaker_core/main → sagemaker/core/utils}/code_injection/constants.py +0 -0
  360. {sagemaker_core/main → sagemaker/core/utils}/user_agent.py +0 -0
  361. {sagemaker_core-1.0.62.dist-info → sagemaker_core-2.1.1.dist-info}/WHEEL +0 -0
  362. {sagemaker_core-1.0.62.dist-info → sagemaker_core-2.1.1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,18 @@
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 athis 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
+ """Compute Resource Requirements needed to deploy a model"""
14
+ from __future__ import absolute_import
15
+
16
+ from sagemaker.core.compute_resource_requirements.resource_requirements import ( # noqa: F401
17
+ ResourceRequirements,
18
+ )
@@ -0,0 +1,94 @@
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
+ """Defines the ResourceRequirements class that configures the compute resources for the Model."""
14
+
15
+ from __future__ import absolute_import
16
+
17
+ import logging
18
+ from typing import Optional, Dict
19
+
20
+ from sagemaker.core.common_utils import stringify_object
21
+
22
+ LOGGER = logging.getLogger("sagemaker")
23
+
24
+
25
+ class ResourceRequirements(object):
26
+ """Configures the compute resources for a Model."""
27
+
28
+ def __init__(
29
+ self,
30
+ requests: Optional[Dict[str, int]] = None,
31
+ limits: Optional[Dict[str, int]] = None,
32
+ ):
33
+ """Initializes a ResourceRequirements object for an Amazon SageMaker inference component.
34
+
35
+ Args:
36
+ requests (dict): Basic resource to be requested, including num_cpus, memory (in MB),
37
+ accelerator_memory (in MB), copies.
38
+ limits (dict): Max resource limit to be requested, including memory (in MB).
39
+
40
+ Example:
41
+ requests = {
42
+ num_cpus: 1,
43
+ memory: 1024,
44
+ copies: 5
45
+ },
46
+ limits = {
47
+ memory: 2048
48
+ }
49
+ """
50
+ self.requests = requests
51
+ self.limits = limits
52
+ self.num_accelerators: Optional[int] = None
53
+ self.num_cpus: Optional[int] = None
54
+ self.min_memory: Optional[int] = None
55
+ self.max_memory: Optional[int] = None
56
+ self.copy_count = 1
57
+
58
+ if requests:
59
+ if "num_accelerators" in requests:
60
+ self.num_accelerators = requests["num_accelerators"]
61
+ if "num_cpus" in requests:
62
+ self.num_cpus = requests["num_cpus"]
63
+ if "memory" in requests:
64
+ self.min_memory = requests["memory"]
65
+ if "copies" in requests:
66
+ self.copy_count = requests["copies"]
67
+ if limits:
68
+ if "memory" in limits:
69
+ self.max_memory = limits["memory"]
70
+
71
+ def __str__(self) -> str:
72
+ """Overriding str(*) method to make more human-readable."""
73
+ return stringify_object(self)
74
+
75
+ def __eq__(self, other) -> bool:
76
+ """Implement equal method for easy unit testing."""
77
+ return self.requests == other.requests and self.limits == other.limits
78
+
79
+ def get_compute_resource_requirements(self) -> dict:
80
+ """Returns a dict of resource requirements."""
81
+ resource_requirements = {
82
+ "MinMemoryRequiredInMb": self.min_memory,
83
+ }
84
+
85
+ if self.max_memory:
86
+ resource_requirements.update({"MaxMemoryRequiredInMb": self.max_memory})
87
+ if self.num_cpus:
88
+ resource_requirements.update({"NumberOfCpuCoresRequired": self.num_cpus})
89
+ if self.num_accelerators:
90
+ resource_requirements.update(
91
+ {"NumberOfAcceleratorDevicesRequired": self.num_accelerators}
92
+ )
93
+
94
+ return resource_requirements
@@ -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 athis file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+ """This module configures the default values for SageMaker Python SDK."""
14
+
15
+ from __future__ import absolute_import
16
+ from sagemaker.core.config.config import ( # noqa: F401
17
+ load_local_mode_config,
18
+ load_sagemaker_config,
19
+ validate_sagemaker_config,
20
+ )
21
+ from sagemaker.core.config.config_schema import ( # noqa: F401
22
+ KEY,
23
+ TRAINING_JOB,
24
+ TRAINING_JOB_INTER_CONTAINER_ENCRYPTION_PATH,
25
+ TRAINING_JOB_ROLE_ARN_PATH,
26
+ TRAINING_JOB_ENABLE_NETWORK_ISOLATION_PATH,
27
+ TRAINING_JOB_ENVIRONMENT_PATH,
28
+ TRAINING_JOB_VPC_CONFIG_PATH,
29
+ TRAINING_JOB_OUTPUT_DATA_CONFIG_PATH,
30
+ TRAINING_JOB_RESOURCE_CONFIG_PATH,
31
+ TRAINING_JOB_PROFILE_CONFIG_PATH,
32
+ TRAINING_JOB_DISABLE_PROFILER_PATH,
33
+ PROCESSING_JOB_INPUTS_PATH,
34
+ PROCESSING_JOB,
35
+ PROCESSING_JOB_ENVIRONMENT_PATH,
36
+ PROCESSING_JOB_INTER_CONTAINER_ENCRYPTION_PATH,
37
+ PROCESSING_JOB_ROLE_ARN_PATH,
38
+ PROCESSING_JOB_NETWORK_CONFIG_PATH,
39
+ PROCESSING_OUTPUT_CONFIG_PATH,
40
+ PROCESSING_JOB_PROCESSING_RESOURCES_PATH,
41
+ MONITORING_JOB_ENVIRONMENT_PATH,
42
+ MONITORING_JOB_ROLE_ARN_PATH,
43
+ MONITORING_JOB_VOLUME_KMS_KEY_ID_PATH,
44
+ MONITORING_JOB_NETWORK_CONFIG_PATH,
45
+ MONITORING_JOB_OUTPUT_KMS_KEY_ID_PATH,
46
+ MONITORING_SCHEDULE,
47
+ MONITORING_SCHEDULE_INTER_CONTAINER_ENCRYPTION_PATH,
48
+ AUTO_ML_ROLE_ARN_PATH,
49
+ AUTO_ML_V2_ROLE_ARN_PATH,
50
+ AUTO_ML_OUTPUT_CONFIG_PATH,
51
+ AUTO_ML_V2_OUTPUT_CONFIG_PATH,
52
+ AUTO_ML_JOB_CONFIG_PATH,
53
+ AUTO_ML_JOB,
54
+ AUTO_ML_JOB_V2,
55
+ COMPILATION_JOB_ROLE_ARN_PATH,
56
+ COMPILATION_JOB_OUTPUT_CONFIG_PATH,
57
+ COMPILATION_JOB_VPC_CONFIG_PATH,
58
+ COMPILATION_JOB,
59
+ EDGE_PACKAGING_ROLE_ARN_PATH,
60
+ EDGE_PACKAGING_RESOURCE_KEY_PATH,
61
+ EDGE_PACKAGING_OUTPUT_CONFIG_PATH,
62
+ EDGE_PACKAGING_JOB,
63
+ TRANSFORM_JOB,
64
+ TRANSFORM_JOB_KMS_KEY_ID_PATH,
65
+ TRANSFORM_OUTPUT_KMS_KEY_ID_PATH,
66
+ VOLUME_KMS_KEY_ID,
67
+ TRANSFORM_JOB_VOLUME_KMS_KEY_ID_PATH,
68
+ MODEL,
69
+ MODEL_CONTAINERS_PATH,
70
+ MODEL_EXECUTION_ROLE_ARN_PATH,
71
+ MODEL_ENABLE_NETWORK_ISOLATION_PATH,
72
+ MODEL_VPC_CONFIG_PATH,
73
+ MODEL_PACKAGE_VALIDATION_ROLE_PATH,
74
+ VALIDATION_ROLE,
75
+ VALIDATION_PROFILES,
76
+ MODEL_PACKAGE_INFERENCE_SPECIFICATION_CONTAINERS_PATH,
77
+ MODEL_PACKAGE_VALIDATION_PROFILES_PATH,
78
+ MODEL_PRIMARY_CONTAINER_PATH,
79
+ MODEL_PRIMARY_CONTAINER_ENVIRONMENT_PATH,
80
+ ENDPOINT_CONFIG_PRODUCTION_VARIANTS_PATH,
81
+ KMS_KEY_ID,
82
+ RESOURCE_KEY,
83
+ ENDPOINT_CONFIG_KMS_KEY_ID_PATH,
84
+ ENDPOINT_CONFIG,
85
+ ENDPOINT_CONFIG_DATA_CAPTURE_PATH,
86
+ ENDPOINT_CONFIG_ASYNC_INFERENCE_PATH,
87
+ ENDPOINT_CONFIG_EXECUTION_ROLE_ARN_PATH,
88
+ ENDPOINT_CONFIG_ENABLE_NETWORK_ISOLATION_PATH,
89
+ ENDPOINT_CONFIG_VPC_CONFIG_PATH,
90
+ ENDPOINT,
91
+ INFERENCE_COMPONENT,
92
+ ENDPOINT_TAGS_PATH,
93
+ SAGEMAKER,
94
+ FEATURE_GROUP,
95
+ TAGS,
96
+ FEATURE_GROUP_ROLE_ARN_PATH,
97
+ FEATURE_GROUP_ONLINE_STORE_CONFIG_PATH,
98
+ FEATURE_GROUP_OFFLINE_STORE_CONFIG_PATH,
99
+ PIPELINE_ROLE_ARN_PATH,
100
+ TRANSFORM_RESOURCES_VOLUME_KMS_KEY_ID_PATH,
101
+ EDGE_PACKAGING_KMS_KEY_ID_PATH,
102
+ ENDPOINT_CONFIG_ASYNC_KMS_KEY_ID_PATH,
103
+ PROCESSING_JOB_KMS_KEY_ID_PATH,
104
+ PROCESSING_JOB_SECURITY_GROUP_IDS_PATH,
105
+ PROCESSING_JOB_SUBNETS_PATH,
106
+ PROCESSING_JOB_ENABLE_NETWORK_ISOLATION_PATH,
107
+ PROCESSING_JOB_VOLUME_KMS_KEY_ID_PATH,
108
+ PIPELINE_TAGS_PATH,
109
+ TRAINING_JOB_VOLUME_KMS_KEY_ID_PATH,
110
+ TRAINING_JOB_SECURITY_GROUP_IDS_PATH,
111
+ TRAINING_JOB_SUBNETS_PATH,
112
+ TRAINING_JOB_KMS_KEY_ID_PATH,
113
+ FEATURE_GROUP_OFFLINE_STORE_KMS_KEY_ID_PATH,
114
+ FEATURE_GROUP_ONLINE_STORE_KMS_KEY_ID_PATH,
115
+ AUTO_ML_KMS_KEY_ID_PATH,
116
+ AUTO_ML_V2_KMS_KEY_ID_PATH,
117
+ AUTO_ML_VPC_CONFIG_PATH,
118
+ AUTO_ML_V2_VPC_CONFIG_PATH,
119
+ AUTO_ML_VOLUME_KMS_KEY_ID_PATH,
120
+ AUTO_ML_V2_VOLUME_KMS_KEY_ID_PATH,
121
+ AUTO_ML_INTER_CONTAINER_ENCRYPTION_PATH,
122
+ AUTO_ML_V2_INTER_CONTAINER_ENCRYPTION_PATH,
123
+ ENDPOINT_CONFIG_DATA_CAPTURE_KMS_KEY_ID_PATH,
124
+ SESSION_DEFAULT_S3_BUCKET_PATH,
125
+ SESSION_DEFAULT_S3_OBJECT_KEY_PREFIX_PATH,
126
+ MONITORING_SCHEDULE_CONFIG,
127
+ MONITORING_JOB_DEFINITION,
128
+ MONITORING_OUTPUT_CONFIG,
129
+ MONITORING_RESOURCES,
130
+ CLUSTER_CONFIG,
131
+ NETWORK_CONFIG,
132
+ ENABLE_INTER_CONTAINER_TRAFFIC_ENCRYPTION,
133
+ ENABLE_NETWORK_ISOLATION,
134
+ VPC_CONFIG,
135
+ SUBNETS,
136
+ SECURITY_GROUP_IDS,
137
+ ROLE_ARN,
138
+ VALUE,
139
+ OUTPUT_CONFIG,
140
+ DATA_CAPTURE_CONFIG,
141
+ PRODUCTION_VARIANTS,
142
+ AUTO_ML_JOB_CONFIG,
143
+ SECURITY_CONFIG,
144
+ OUTPUT_DATA_CONFIG,
145
+ MODEL_PACKAGE,
146
+ VALIDATION_SPECIFICATION,
147
+ TRANSFORM_JOB_DEFINITION,
148
+ TRANSFORM_JOB_ENVIRONMENT_PATH,
149
+ TRANSFORM_OUTPUT,
150
+ TRANSFORM_RESOURCES,
151
+ OFFLINE_STORE_CONFIG,
152
+ S3_STORAGE_CONFIG,
153
+ ONLINE_STORE_CONFIG,
154
+ PROCESSING_INPUTS,
155
+ DATASET_DEFINITION,
156
+ ATHENA_DATASET_DEFINITION,
157
+ REDSHIFT_DATASET_DEFINITION,
158
+ CLUSTER_ROLE_ARN,
159
+ PROCESSING_OUTPUT_CONFIG,
160
+ PROCESSING_RESOURCES,
161
+ PROFILER_CONFIG,
162
+ DISABLE_PROFILER,
163
+ RESOURCE_CONFIG,
164
+ EXECUTION_ROLE_ARN,
165
+ ASYNC_INFERENCE_CONFIG,
166
+ SCHEMA_VERSION,
167
+ PYTHON_SDK,
168
+ MODULES,
169
+ DEFAULT_S3_BUCKET,
170
+ DEFAULT_S3_OBJECT_KEY_PREFIX,
171
+ SESSION,
172
+ ENVIRONMENT,
173
+ CONTAINERS,
174
+ PRIMARY_CONTAINER,
175
+ INFERENCE_SPECIFICATION,
176
+ DEBUG_HOOK_CONFIG,
177
+ SAGEMAKER_PYTHON_SDK_LOCAL_MODE_CONFIG_SCHEMA,
178
+ LOCAL,
179
+ LOCAL_CODE,
180
+ CONTAINER_CONFIG,
181
+ )
@@ -0,0 +1,238 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+ """This module configures the default values defined by the user for SageMaker Python SDK calls.
14
+
15
+ It supports loading config files from the local file system and Amazon S3.
16
+ The schema of the config file is dictated in config_schema.py in the same module.
17
+
18
+ """
19
+ from __future__ import absolute_import, annotations
20
+
21
+ import pathlib
22
+ import os
23
+ from typing import List
24
+ import boto3
25
+ import yaml
26
+ import jsonschema
27
+ from platformdirs import site_config_dir, user_config_dir
28
+ from botocore.utils import merge_dicts
29
+ from six.moves.urllib.parse import urlparse
30
+ from sagemaker.core.config.config_schema import SAGEMAKER_PYTHON_SDK_CONFIG_SCHEMA
31
+ from sagemaker.core.config.config_utils import (
32
+ non_repeating_log_factory,
33
+ get_sagemaker_config_logger,
34
+ )
35
+
36
+ logger = get_sagemaker_config_logger()
37
+ log_info_function = non_repeating_log_factory(logger, "info")
38
+
39
+ _APP_NAME = "sagemaker"
40
+ # The default name of the config file.
41
+ _CONFIG_FILE_NAME = "config.yaml"
42
+ # The default config file location of the Administrator provided config file. This path can be
43
+ # overridden with `SAGEMAKER_ADMIN_CONFIG_OVERRIDE` environment variable.
44
+ _DEFAULT_ADMIN_CONFIG_FILE_PATH = os.path.join(site_config_dir(_APP_NAME), _CONFIG_FILE_NAME)
45
+ # The default config file location of the user provided config file. This path can be
46
+ # overridden with `SAGEMAKER_USER_CONFIG_OVERRIDE` environment variable.
47
+ _DEFAULT_USER_CONFIG_FILE_PATH = os.path.join(user_config_dir(_APP_NAME), _CONFIG_FILE_NAME)
48
+ # The default config file location of the local mode.
49
+ _DEFAULT_LOCAL_MODE_CONFIG_FILE_PATH = os.path.join(
50
+ os.path.expanduser("~"), ".sagemaker", _CONFIG_FILE_NAME
51
+ )
52
+
53
+ ENV_VARIABLE_ADMIN_CONFIG_OVERRIDE = "SAGEMAKER_ADMIN_CONFIG_OVERRIDE"
54
+ ENV_VARIABLE_USER_CONFIG_OVERRIDE = "SAGEMAKER_USER_CONFIG_OVERRIDE"
55
+
56
+ S3_PREFIX = "s3://"
57
+
58
+
59
+ def load_sagemaker_config(
60
+ additional_config_paths: List[str] = None, s3_resource=None, repeat_log=False
61
+ ) -> dict:
62
+ """Loads config files and merges them.
63
+
64
+ By default, this method first searches for config files in the default locations
65
+ defined by the SDK.
66
+
67
+ Users can override the default admin and user config file paths using the
68
+ ``SAGEMAKER_ADMIN_CONFIG_OVERRIDE`` and ``SAGEMAKER_USER_CONFIG_OVERRIDE`` environment
69
+ variables, respectively.
70
+
71
+ Additional config file paths can also be provided as a parameter.
72
+
73
+ This method then:
74
+ * Loads each config file, whether it is Amazon S3 or the local file system.
75
+ * Validates the schema of the config files.
76
+ * Merges the files in the same order.
77
+
78
+ This method throws exceptions in the following cases:
79
+ * ``jsonschema.exceptions.ValidationError``: Schema validation fails for one or more
80
+ config files.
81
+ * ``RuntimeError``: The method is unable to retrieve the list of all S3 files with the
82
+ same prefix or is unable to retrieve the file.
83
+ * ``ValueError``: There are no S3 files with the prefix when an S3 URI is provided.
84
+ * ``ValueError``: There is no config.yaml file in the S3 bucket when an S3 URI is
85
+ provided.
86
+ * ``ValueError``: A file doesn't exist in a path that was specified by the user as
87
+ part of an environment variable or additional configuration file path. This doesn't
88
+ include the default config file locations.
89
+
90
+ Args:
91
+ additional_config_paths: List of config file paths.
92
+ These paths can be one of the following. In the case of a directory, this method
93
+ searches for a ``config.yaml`` file in that directory. This method does not perform a
94
+ recursive search of folders in that directory.
95
+
96
+ * Local file path
97
+ * Local directory path
98
+ * S3 URI of the config file
99
+ * S3 URI of the directory containing the config file
100
+
101
+ Note: S3 URI follows the format ``s3://<bucket>/<Key prefix>``
102
+ s3_resource (boto3.resource("s3")): The Boto3 S3 resource. This is used to fetch
103
+ config files from S3. If it is not provided but config files are present in S3,
104
+ this method creates a default S3 resource. See `Boto3 Session documentation
105
+ <https://boto3.amazonaws.com/v1/documentation/api\
106
+ /latest/reference/core/session.html#boto3.session.Session.resource>`__.
107
+ This argument is not needed if the config files are present in the local file system.
108
+ repeat_log (bool): Whether the log with the same contents should be emitted.
109
+ Default to ``False``
110
+ """
111
+ default_config_path = os.getenv(
112
+ ENV_VARIABLE_ADMIN_CONFIG_OVERRIDE, _DEFAULT_ADMIN_CONFIG_FILE_PATH
113
+ )
114
+ user_config_path = os.getenv(ENV_VARIABLE_USER_CONFIG_OVERRIDE, _DEFAULT_USER_CONFIG_FILE_PATH)
115
+ config_paths = [default_config_path, user_config_path]
116
+ if additional_config_paths:
117
+ config_paths += additional_config_paths
118
+ config_paths = list(filter(lambda item: item is not None, config_paths))
119
+ merged_config = {}
120
+
121
+ log_info = log_info_function
122
+ if repeat_log:
123
+ log_info = logger.info
124
+
125
+ for file_path in config_paths:
126
+ config_from_file = {}
127
+ if file_path.startswith(S3_PREFIX):
128
+ config_from_file = _load_config_from_s3(file_path, s3_resource)
129
+ else:
130
+ try:
131
+ config_from_file = _load_config_from_file(file_path)
132
+ except ValueError as error:
133
+ if file_path not in (
134
+ _DEFAULT_ADMIN_CONFIG_FILE_PATH,
135
+ _DEFAULT_USER_CONFIG_FILE_PATH,
136
+ ):
137
+ # Throw exception only when User provided file path is invalid.
138
+ # If there are no files in the Default config file locations, don't throw
139
+ # Exceptions.
140
+ raise
141
+
142
+ logger.debug(error)
143
+ if config_from_file:
144
+ validate_sagemaker_config(config_from_file)
145
+ merge_dicts(merged_config, config_from_file)
146
+ log_info("Fetched defaults config from location: %s", file_path)
147
+ else:
148
+ log_info("Not applying SDK defaults from location: %s", file_path)
149
+
150
+ return merged_config
151
+
152
+
153
+ def validate_sagemaker_config(sagemaker_config: dict = None):
154
+ """Validates whether a given dictionary adheres to the schema.
155
+
156
+ The schema is defined at
157
+ ``sagemaker.config.config_schema.SAGEMAKER_PYTHON_SDK_CONFIG_SCHEMA``.
158
+
159
+ Args:
160
+ sagemaker_config: A dictionary containing default values for the
161
+ SageMaker Python SDK. (default: None).
162
+ """
163
+ jsonschema.validate(sagemaker_config, SAGEMAKER_PYTHON_SDK_CONFIG_SCHEMA)
164
+
165
+
166
+ def load_local_mode_config() -> dict | None:
167
+ """Loads the local mode config file."""
168
+ try:
169
+ content = _load_config_from_file(_DEFAULT_LOCAL_MODE_CONFIG_FILE_PATH)
170
+ except ValueError:
171
+ content = None
172
+
173
+ return content
174
+
175
+
176
+ def _load_config_from_file(file_path: str) -> dict:
177
+ """Placeholder docstring"""
178
+ inferred_file_path = file_path
179
+ if os.path.isdir(file_path):
180
+ inferred_file_path = os.path.join(file_path, _CONFIG_FILE_NAME)
181
+ if not os.path.exists(inferred_file_path):
182
+ raise ValueError(
183
+ f"Unable to load the config file from the location: {file_path}"
184
+ f"Provide a valid file path"
185
+ )
186
+ logger.debug("Fetching defaults config from location: %s", file_path)
187
+ with open(inferred_file_path, "r") as f:
188
+ content = yaml.safe_load(f)
189
+ return content
190
+
191
+
192
+ def _load_config_from_s3(s3_uri, s3_resource_for_config) -> dict:
193
+ """Placeholder docstring"""
194
+ if not s3_resource_for_config:
195
+ # Constructing a default Boto3 S3 Resource from a default Boto3 session.
196
+ boto_session = boto3.DEFAULT_SESSION or boto3.Session()
197
+ boto_region_name = boto_session.region_name
198
+ if boto_region_name is None:
199
+ raise ValueError(
200
+ "Must setup local AWS configuration with a region supported by SageMaker."
201
+ )
202
+ s3_resource_for_config = boto_session.resource("s3", region_name=boto_region_name)
203
+
204
+ logger.debug("Fetching defaults config from location: %s", s3_uri)
205
+ inferred_s3_uri = _get_inferred_s3_uri(s3_uri, s3_resource_for_config)
206
+ parsed_url = urlparse(inferred_s3_uri)
207
+ bucket, key_prefix = parsed_url.netloc, parsed_url.path.lstrip("/")
208
+ s3_object = s3_resource_for_config.Object(bucket, key_prefix)
209
+ s3_file_content = s3_object.get()["Body"].read()
210
+ return yaml.safe_load(s3_file_content.decode("utf-8"))
211
+
212
+
213
+ def _get_inferred_s3_uri(s3_uri, s3_resource_for_config):
214
+ """Placeholder docstring"""
215
+ parsed_url = urlparse(s3_uri)
216
+ bucket, key_prefix = parsed_url.netloc, parsed_url.path.lstrip("/")
217
+ s3_bucket = s3_resource_for_config.Bucket(name=bucket)
218
+ s3_objects = s3_bucket.objects.filter(Prefix=key_prefix).all()
219
+ s3_files_with_same_prefix = [
220
+ "{}{}/{}".format(S3_PREFIX, bucket, s3_object.key) for s3_object in s3_objects
221
+ ]
222
+ if len(s3_files_with_same_prefix) == 0:
223
+ # Customer provided us with an incorrect s3 path.
224
+ raise ValueError("Provide a valid S3 path instead of {}".format(s3_uri))
225
+ if len(s3_files_with_same_prefix) > 1:
226
+ # Customer has provided us with a S3 URI which points to a directory
227
+ # search for s3://<bucket>/directory-key-prefix/config.yaml
228
+ inferred_s3_uri = str(pathlib.PurePosixPath(s3_uri, _CONFIG_FILE_NAME)).replace(
229
+ "s3:/", "s3://"
230
+ )
231
+ if inferred_s3_uri not in s3_files_with_same_prefix:
232
+ # We don't know which file we should be operating with.
233
+ raise ValueError(
234
+ f"Provide an S3 URI of a directory that has a {_CONFIG_FILE_NAME} file."
235
+ )
236
+ # Customer has a config.yaml present in the directory that was provided as the S3 URI
237
+ return inferred_s3_uri
238
+ return s3_uri