sagemaker-core 1.0.62__py3-none-any.whl → 2.3.1__py3-none-any.whl

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