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,622 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License"). You
4
+ # may not use this file except in compliance with the License. A copy of
5
+ # the License is located at
6
+ #
7
+ # http://aws.amazon.com/apache2.0/
8
+ #
9
+ # or in the "license" file accompanying this file. This file is
10
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
+ # ANY KIND, either express or implied. See the License for the specific
12
+ # language governing permissions and limitations under the License.
13
+ """Placeholder docstring"""
14
+ from __future__ import absolute_import
15
+
16
+ import logging
17
+ import re
18
+
19
+ from typing import List, Dict, Optional
20
+ import sagemaker
21
+ from sagemaker.core.parameter import CategoricalParameter
22
+
23
+ INFERENCE_RECOMMENDER_FRAMEWORK_MAPPING = {
24
+ "xgboost": "XGBOOST",
25
+ "sklearn": "SAGEMAKER-SCIKIT-LEARN",
26
+ "pytorch": "PYTORCH",
27
+ "tensorflow": "TENSORFLOW",
28
+ "mxnet": "MXNET",
29
+ }
30
+
31
+ # Setting LOGGER for backward compatibility, in case users import it...
32
+ logger = LOGGER = logging.getLogger("sagemaker")
33
+
34
+
35
+ class Phase:
36
+ """Used to store phases of a traffic pattern to perform endpoint load testing.
37
+
38
+ Required for an Advanced Inference Recommendations Job
39
+ """
40
+
41
+ def __init__(self, duration_in_seconds: int, initial_number_of_users: int, spawn_rate: int):
42
+ """Initialize a `Phase`"""
43
+ self.to_json = {
44
+ "DurationInSeconds": duration_in_seconds,
45
+ "InitialNumberOfUsers": initial_number_of_users,
46
+ "SpawnRate": spawn_rate,
47
+ }
48
+
49
+
50
+ class ModelLatencyThreshold:
51
+ """Used to store inference request/response latency to perform endpoint load testing.
52
+
53
+ Required for an Advanced Inference Recommendations Job
54
+ """
55
+
56
+ def __init__(self, percentile: str, value_in_milliseconds: int):
57
+ """Initialize a `ModelLatencyThreshold`"""
58
+ self.to_json = {"Percentile": percentile, "ValueInMilliseconds": value_in_milliseconds}
59
+
60
+
61
+ class InferenceRecommenderMixin:
62
+ """A mixin class for SageMaker ``Inference Recommender`` that will be extended by ``Model``"""
63
+
64
+ def right_size(
65
+ self,
66
+ sample_payload_url: str = None,
67
+ supported_content_types: List[str] = None,
68
+ supported_instance_types: List[str] = None,
69
+ job_name: str = None,
70
+ framework: str = None,
71
+ job_duration_in_seconds: int = None,
72
+ hyperparameter_ranges: List[Dict[str, CategoricalParameter]] = None,
73
+ phases: List[Phase] = None,
74
+ traffic_type: str = None,
75
+ max_invocations: int = None,
76
+ model_latency_thresholds: List[ModelLatencyThreshold] = None,
77
+ max_tests: int = None,
78
+ max_parallel_tests: int = None,
79
+ log_level: Optional[str] = "Verbose",
80
+ ):
81
+ """Recommends an instance type for a SageMaker or BYOC model.
82
+
83
+ Create a SageMaker ``Model`` or use a registered ``ModelPackage``,
84
+ to start an Inference Recommender job.
85
+
86
+ The name of the created model is accessible in the ``name`` field of
87
+ this ``Model`` after right_size returns.
88
+
89
+ Args:
90
+ sample_payload_url (str): The S3 path where the sample payload is stored.
91
+ supported_content_types: (list[str]): The supported MIME types for the input data.
92
+ supported_instance_types (list[str]): A list of the instance types that this model
93
+ is expected to work on. (default: None).
94
+ job_name (str): The name of the Inference Recommendations Job. (default: None).
95
+ framework (str): The machine learning framework of the Image URI.
96
+ Only required to specify if you bring your own custom containers (default: None).
97
+ job_duration_in_seconds (int): The maximum job duration that a job can run for.
98
+ (default: None).
99
+ hyperparameter_ranges (list[Dict[str, sagemaker.parameter.CategoricalParameter]]):
100
+ Specifies the hyper parameters to be used during endpoint load tests.
101
+ `instance_type` must be specified as a hyperparameter range.
102
+ `env_vars` can be specified as an optional hyperparameter range. (default: None).
103
+ Example::
104
+
105
+ hyperparameter_ranges = [{
106
+ 'instance_types': CategoricalParameter(['ml.c5.xlarge', 'ml.c5.2xlarge']),
107
+ 'OMP_NUM_THREADS': CategoricalParameter(['1', '2', '3', '4'])
108
+ }]
109
+
110
+ phases (list[Phase]): Shape of the traffic pattern to use in the load test
111
+ (default: None).
112
+ traffic_type (str): Specifies the traffic pattern type. Currently only supports
113
+ one type 'PHASES' (default: None).
114
+ max_invocations (str): defines the minimum invocations per minute for the endpoint
115
+ to support (default: None).
116
+ model_latency_thresholds (list[ModelLatencyThreshold]): defines the maximum response
117
+ latency for endpoints to support (default: None).
118
+ max_tests (int): restricts how many endpoints in total are allowed to be
119
+ spun up for this job (default: None).
120
+ max_parallel_tests (int): restricts how many concurrent endpoints
121
+ this job is allowed to spin up (default: None).
122
+ log_level (str): specifies the inline output when waiting for right_size to complete
123
+ (default: "Verbose").
124
+
125
+ Returns:
126
+ sagemaker.model.Model: A SageMaker ``Model`` object. See
127
+ :func:`~sagemaker.model.Model` for full details.
128
+ """
129
+
130
+ if not framework and self._framework():
131
+ framework = INFERENCE_RECOMMENDER_FRAMEWORK_MAPPING.get(self._framework(), framework)
132
+
133
+ framework_version = self._get_framework_version()
134
+
135
+ endpoint_configurations = self._convert_to_endpoint_configurations_json(
136
+ hyperparameter_ranges=hyperparameter_ranges
137
+ )
138
+ traffic_pattern = self._convert_to_traffic_pattern_json(
139
+ traffic_type=traffic_type, phases=phases
140
+ )
141
+ stopping_conditions = self._convert_to_stopping_conditions_json(
142
+ max_invocations=max_invocations, model_latency_thresholds=model_latency_thresholds
143
+ )
144
+ resource_limit = self._convert_to_resource_limit_json(
145
+ max_tests=max_tests, max_parallel_tests=max_parallel_tests
146
+ )
147
+
148
+ if endpoint_configurations or traffic_pattern or stopping_conditions or resource_limit:
149
+ logger.info("Advanced Job parameters were specified. Running Advanced job...")
150
+ job_type = "Advanced"
151
+ else:
152
+ logger.info("Advanced Job parameters were not specified. Running Default job...")
153
+ job_type = "Default"
154
+
155
+ self._init_sagemaker_session_if_does_not_exist()
156
+
157
+ if isinstance(self, sagemaker.model.Model) and not isinstance(
158
+ self, sagemaker.model.ModelPackage
159
+ ):
160
+ primary_container_def = self.prepare_container_def()
161
+ if not self.name:
162
+ self._ensure_base_name_if_needed(
163
+ image_uri=primary_container_def["Image"],
164
+ script_uri=self.source_dir,
165
+ model_uri=self.model_data,
166
+ )
167
+ self._set_model_name_if_needed()
168
+
169
+ create_model_args = dict(
170
+ name=self.name,
171
+ role=self.role,
172
+ container_defs=None,
173
+ primary_container=primary_container_def,
174
+ vpc_config=self.vpc_config,
175
+ enable_network_isolation=self.enable_network_isolation(),
176
+ )
177
+ logger.warning("Attempting to create new model with name %s", self.name)
178
+ self.sagemaker_session.create_model(**create_model_args)
179
+
180
+ ret_name = self.sagemaker_session.create_inference_recommendations_job(
181
+ role=self.role,
182
+ job_name=job_name,
183
+ job_type=job_type,
184
+ job_duration_in_seconds=job_duration_in_seconds,
185
+ model_name=self.name,
186
+ model_package_version_arn=getattr(self, "model_package_arn", None),
187
+ framework=framework,
188
+ framework_version=framework_version,
189
+ sample_payload_url=sample_payload_url,
190
+ supported_content_types=supported_content_types,
191
+ supported_instance_types=supported_instance_types,
192
+ endpoint_configurations=endpoint_configurations,
193
+ traffic_pattern=traffic_pattern,
194
+ stopping_conditions=stopping_conditions,
195
+ resource_limit=resource_limit,
196
+ )
197
+
198
+ self.inference_recommender_job_results = (
199
+ self.sagemaker_session.wait_for_inference_recommendations_job(
200
+ ret_name, log_level=log_level
201
+ )
202
+ )
203
+ self.inference_recommendations = self.inference_recommender_job_results.get(
204
+ "InferenceRecommendations"
205
+ )
206
+
207
+ return self
208
+
209
+ def _update_params(
210
+ self,
211
+ **kwargs,
212
+ ):
213
+ """Check and update params based on inference recommendation id or right size case"""
214
+ instance_type = kwargs["instance_type"]
215
+ initial_instance_count = kwargs["initial_instance_count"]
216
+ accelerator_type = kwargs["accelerator_type"]
217
+ async_inference_config = kwargs["async_inference_config"]
218
+ serverless_inference_config = kwargs["serverless_inference_config"]
219
+ explainer_config = kwargs["explainer_config"]
220
+ inference_recommendation_id = kwargs["inference_recommendation_id"]
221
+ inference_recommender_job_results = kwargs["inference_recommender_job_results"]
222
+ if inference_recommendation_id is not None:
223
+ inference_recommendation = self._update_params_for_recommendation_id(
224
+ instance_type=instance_type,
225
+ initial_instance_count=initial_instance_count,
226
+ accelerator_type=accelerator_type,
227
+ async_inference_config=async_inference_config,
228
+ serverless_inference_config=serverless_inference_config,
229
+ inference_recommendation_id=inference_recommendation_id,
230
+ explainer_config=explainer_config,
231
+ )
232
+ elif inference_recommender_job_results is not None:
233
+ inference_recommendation = self._update_params_for_right_size(
234
+ instance_type,
235
+ initial_instance_count,
236
+ accelerator_type,
237
+ serverless_inference_config,
238
+ async_inference_config,
239
+ explainer_config,
240
+ )
241
+
242
+ return (
243
+ inference_recommendation
244
+ if inference_recommendation
245
+ else (instance_type, initial_instance_count)
246
+ )
247
+
248
+ def _update_params_for_right_size(
249
+ self,
250
+ instance_type=None,
251
+ initial_instance_count=None,
252
+ accelerator_type=None,
253
+ serverless_inference_config=None,
254
+ async_inference_config=None,
255
+ explainer_config=None,
256
+ ):
257
+ """Validates that Inference Recommendation parameters can be used in `model.deploy()`
258
+
259
+ Args:
260
+ instance_type (str): The initial number of instances to run
261
+ in the ``Endpoint`` created from this ``Model``. If not using
262
+ serverless inference or the model has not called ``right_size()``,
263
+ then it need to be a number larger or equals
264
+ to 1 (default: None)
265
+ initial_instance_count (int):The EC2 instance type to deploy this Model to.
266
+ For example, 'ml.p2.xlarge', or 'local' for local mode. If not using
267
+ serverless inference or the model has not called ``right_size()``,
268
+ then it is required to deploy a model.
269
+ (default: None)
270
+ accelerator_type (str): whether accelerator_type has been passed into `model.deploy()`.
271
+ serverless_inference_config (sagemaker.serve.serverless.ServerlessInferenceConfig)):
272
+ whether serverless_inference_config has been passed into `model.deploy()`.
273
+ async_inference_config (sagemaker.model_monitor.AsyncInferenceConfig):
274
+ whether async_inference_config has been passed into `model.deploy()`.
275
+ explainer_config (sagemaker.explainer.ExplainerConfig): whether explainer_config
276
+ has been passed into `model.deploy()`.
277
+
278
+ Returns:
279
+ (string, int) or None: Top instance_type and associated initial_instance_count
280
+ if self.inference_recommender_job_results has been generated. Otherwise, return None.
281
+ """
282
+ if accelerator_type:
283
+ raise ValueError("accelerator_type is not compatible with right_size().")
284
+ if instance_type or initial_instance_count:
285
+ logger.warning(
286
+ "instance_type or initial_instance_count specified."
287
+ "Overriding right_size() recommendations."
288
+ )
289
+ return None
290
+ if async_inference_config:
291
+ logger.warning(
292
+ "async_inference_config is specified. Overriding right_size() recommendations."
293
+ )
294
+ return None
295
+ if serverless_inference_config:
296
+ logger.warning(
297
+ "serverless_inference_config is specified. Overriding right_size() recommendations."
298
+ )
299
+ return None
300
+ if explainer_config:
301
+ logger.warning(
302
+ "explainer_config is specified. Overriding right_size() recommendations."
303
+ )
304
+ return None
305
+
306
+ return self._filter_recommendations_for_realtime()
307
+
308
+ def _update_params_for_recommendation_id(
309
+ self,
310
+ instance_type,
311
+ initial_instance_count,
312
+ accelerator_type,
313
+ async_inference_config,
314
+ serverless_inference_config,
315
+ inference_recommendation_id,
316
+ explainer_config,
317
+ ):
318
+ """Update parameters with inference recommendation results.
319
+
320
+ Args:
321
+ instance_type (str): The EC2 instance type to deploy this Model to.
322
+ For example, 'ml.p2.xlarge', or 'local' for local mode. If not using
323
+ serverless inference, then it is required to deploy a model.
324
+ initial_instance_count (int): The initial number of instances to run
325
+ in the ``Endpoint`` created from this ``Model``. If not using
326
+ serverless inference, then it need to be a number larger or equals
327
+ to 1.
328
+ accelerator_type (str): Type of Elastic Inference accelerator to
329
+ deploy this model for model loading and inference, for example,
330
+ 'ml.eia1.medium'. If not specified, no Elastic Inference
331
+ accelerator will be attached to the endpoint. For more
332
+ information:
333
+ https://docs.aws.amazon.com/sagemaker/latest/dg/ei.html
334
+ async_inference_config (sagemaker.model_monitor.AsyncInferenceConfig): Specifies
335
+ configuration related to async endpoint. Use this configuration when trying
336
+ to create async endpoint and make async inference. If empty config object
337
+ passed through, will use default config to deploy async endpoint. Deploy a
338
+ real-time endpoint if it's None.
339
+ serverless_inference_config (sagemaker.serve.serverless.ServerlessInferenceConfig):
340
+ Specifies configuration related to serverless endpoint. Use this configuration
341
+ when trying to create serverless endpoint and make serverless inference. If
342
+ empty object passed through, will use pre-defined values in
343
+ ``ServerlessInferenceConfig`` class to deploy serverless endpoint. Deploy an
344
+ instance based endpoint if it's None.
345
+ inference_recommendation_id (str): The recommendation id which specifies
346
+ the recommendation you picked from inference recommendation job
347
+ results and would like to deploy the model and endpoint with
348
+ recommended parameters.
349
+ explainer_config (sagemaker.explainer.ExplainerConfig): Specifies online explainability
350
+ configuration for use with Amazon SageMaker Clarify. Default: None.
351
+ Raises:
352
+ ValueError: If arguments combination check failed in these circumstances:
353
+ - If only one of instance type or instance count specified or
354
+ - If recommendation id does not follow the required format or
355
+ - If recommendation id is not valid or
356
+ - If inference recommendation id is specified along with incompatible parameters
357
+ Returns:
358
+ (string, int): instance type and associated instance count from selected
359
+ inference recommendation id if arguments combination check passed.
360
+ """
361
+
362
+ if instance_type is not None and initial_instance_count is not None:
363
+ logger.warning(
364
+ "Both instance_type and initial_instance_count are specified,"
365
+ "overriding the recommendation result."
366
+ )
367
+ return (instance_type, initial_instance_count)
368
+
369
+ # Validate non-compatible parameters with recommendation id
370
+ if accelerator_type is not None:
371
+ raise ValueError("accelerator_type is not compatible with inference_recommendation_id.")
372
+ if async_inference_config is not None:
373
+ raise ValueError(
374
+ "async_inference_config is not compatible with inference_recommendation_id."
375
+ )
376
+ if serverless_inference_config is not None:
377
+ raise ValueError(
378
+ "serverless_inference_config is not compatible with inference_recommendation_id."
379
+ )
380
+ if explainer_config is not None:
381
+ raise ValueError("explainer_config is not compatible with inference_recommendation_id.")
382
+
383
+ # Validate recommendation id
384
+ if not re.match(r"[a-zA-Z0-9](-*[a-zA-Z0-9]){0,63}\/\w{8}$", inference_recommendation_id):
385
+ raise ValueError("inference_recommendation_id is not valid")
386
+ job_or_model_name = inference_recommendation_id.split("/")[0]
387
+
388
+ sage_client = self.sagemaker_session.sagemaker_client
389
+ # Get recommendation from right size job and model
390
+ (
391
+ right_size_recommendation,
392
+ model_recommendation,
393
+ right_size_job_res,
394
+ ) = self._get_recommendation(
395
+ sage_client=sage_client,
396
+ job_or_model_name=job_or_model_name,
397
+ inference_recommendation_id=inference_recommendation_id,
398
+ )
399
+
400
+ # Update params beased on model recommendation
401
+ if model_recommendation:
402
+ if initial_instance_count is None:
403
+ raise ValueError("Must specify model recommendation id and instance count.")
404
+ self.env.update(model_recommendation["Environment"])
405
+ instance_type = model_recommendation["InstanceType"]
406
+ return (instance_type, initial_instance_count)
407
+
408
+ # Update params based on default inference recommendation
409
+ if bool(instance_type) != bool(initial_instance_count):
410
+ raise ValueError(
411
+ "instance_type and initial_instance_count are mutually exclusive with"
412
+ "recommendation id since they are in recommendation."
413
+ "Please specify both of them if you want to override the recommendation."
414
+ )
415
+ input_config = right_size_job_res["InputConfig"]
416
+ model_config = right_size_recommendation["ModelConfiguration"]
417
+ envs = (
418
+ model_config["EnvironmentParameters"]
419
+ if "EnvironmentParameters" in model_config
420
+ else None
421
+ )
422
+ # Update envs
423
+ recommend_envs = {}
424
+ if envs is not None:
425
+ for env in envs:
426
+ recommend_envs[env["Key"]] = env["Value"]
427
+ self.env.update(recommend_envs)
428
+
429
+ # Update params with non-compilation recommendation results
430
+ if (
431
+ "InferenceSpecificationName" not in model_config
432
+ and "CompilationJobName" not in model_config
433
+ ):
434
+
435
+ if "ModelPackageVersionArn" in input_config:
436
+ modelpkg_res = sage_client.describe_model_package(
437
+ ModelPackageName=input_config["ModelPackageVersionArn"]
438
+ )
439
+ self.model_data = modelpkg_res["InferenceSpecification"]["Containers"][0][
440
+ "ModelDataUrl"
441
+ ]
442
+ self.image_uri = modelpkg_res["InferenceSpecification"]["Containers"][0]["Image"]
443
+ elif "ModelName" in input_config:
444
+ model_res = sage_client.describe_model(ModelName=input_config["ModelName"])
445
+ self.model_data = model_res["PrimaryContainer"]["ModelDataUrl"]
446
+ self.image_uri = model_res["PrimaryContainer"]["Image"]
447
+ else:
448
+ if "InferenceSpecificationName" in model_config:
449
+ modelpkg_res = sage_client.describe_model_package(
450
+ ModelPackageName=input_config["ModelPackageVersionArn"]
451
+ )
452
+ self.model_data = modelpkg_res["AdditionalInferenceSpecificationDefinition"][
453
+ "Containers"
454
+ ][0]["ModelDataUrl"]
455
+ self.image_uri = modelpkg_res["AdditionalInferenceSpecificationDefinition"][
456
+ "Containers"
457
+ ][0]["Image"]
458
+ elif "CompilationJobName" in model_config:
459
+ compilation_res = sage_client.describe_compilation_job(
460
+ CompilationJobName=model_config["CompilationJobName"]
461
+ )
462
+ self.model_data = compilation_res["ModelArtifacts"]["S3ModelArtifacts"]
463
+ self.image_uri = compilation_res["InferenceImage"]
464
+
465
+ instance_type = right_size_recommendation["EndpointConfiguration"]["InstanceType"]
466
+ initial_instance_count = right_size_recommendation["EndpointConfiguration"][
467
+ "InitialInstanceCount"
468
+ ]
469
+
470
+ return (instance_type, initial_instance_count)
471
+
472
+ def _convert_to_endpoint_configurations_json(
473
+ self, hyperparameter_ranges: List[Dict[str, CategoricalParameter]]
474
+ ):
475
+ """Bundle right_size() parameters into an endpoint configuration for Advanced job"""
476
+ if not hyperparameter_ranges:
477
+ return None
478
+
479
+ endpoint_configurations_to_json = []
480
+ for parameter_range in hyperparameter_ranges:
481
+ if not parameter_range.get("instance_types"):
482
+ raise ValueError("instance_type must be defined as a hyperparameter_range")
483
+ parameter_range = parameter_range.copy()
484
+ instance_types = parameter_range.get("instance_types").values
485
+ parameter_range.pop("instance_types")
486
+
487
+ for instance_type in instance_types:
488
+ parameter_ranges = [
489
+ {"Name": name, "Value": param.values} for name, param in parameter_range.items()
490
+ ]
491
+ endpoint_configurations_to_json.append(
492
+ {
493
+ "EnvironmentParameterRanges": {
494
+ "CategoricalParameterRanges": parameter_ranges
495
+ },
496
+ "InstanceType": instance_type,
497
+ }
498
+ )
499
+
500
+ return endpoint_configurations_to_json
501
+
502
+ def _convert_to_traffic_pattern_json(self, traffic_type: str, phases: List[Phase]):
503
+ """Bundle right_size() parameters into a traffic pattern for Advanced job"""
504
+ if not phases:
505
+ return None
506
+ return {
507
+ "Phases": [phase.to_json for phase in phases],
508
+ "TrafficType": traffic_type if traffic_type else "PHASES",
509
+ }
510
+
511
+ def _convert_to_resource_limit_json(self, max_tests: int, max_parallel_tests: int):
512
+ """Bundle right_size() parameters into a resource limit for Advanced job"""
513
+ if not max_tests and not max_parallel_tests:
514
+ return None
515
+ resource_limit = {}
516
+ if max_tests:
517
+ resource_limit["MaxNumberOfTests"] = max_tests
518
+ if max_parallel_tests:
519
+ resource_limit["MaxParallelOfTests"] = max_parallel_tests
520
+ return resource_limit
521
+
522
+ def _convert_to_stopping_conditions_json(
523
+ self, max_invocations: int, model_latency_thresholds: List[ModelLatencyThreshold]
524
+ ):
525
+ """Bundle right_size() parameters into stopping conditions for Advanced job"""
526
+ if not max_invocations and not model_latency_thresholds:
527
+ return None
528
+ stopping_conditions = {}
529
+ if max_invocations:
530
+ stopping_conditions["MaxInvocations"] = max_invocations
531
+ if model_latency_thresholds:
532
+ stopping_conditions["ModelLatencyThresholds"] = [
533
+ threshold.to_json for threshold in model_latency_thresholds
534
+ ]
535
+ return stopping_conditions
536
+
537
+ def _get_recommendation(self, sage_client, job_or_model_name, inference_recommendation_id):
538
+ """Get recommendation from right size job and model"""
539
+ right_size_recommendation, model_recommendation, right_size_job_res = None, None, None
540
+ right_size_recommendation, right_size_job_res = self._get_right_size_recommendation(
541
+ sage_client=sage_client,
542
+ job_or_model_name=job_or_model_name,
543
+ inference_recommendation_id=inference_recommendation_id,
544
+ )
545
+ if right_size_recommendation is None:
546
+ model_recommendation = self._get_model_recommendation(
547
+ sage_client=sage_client,
548
+ job_or_model_name=job_or_model_name,
549
+ inference_recommendation_id=inference_recommendation_id,
550
+ )
551
+ if model_recommendation is None:
552
+ raise ValueError("inference_recommendation_id is not valid")
553
+
554
+ return right_size_recommendation, model_recommendation, right_size_job_res
555
+
556
+ def _get_right_size_recommendation(
557
+ self,
558
+ sage_client,
559
+ job_or_model_name,
560
+ inference_recommendation_id,
561
+ ):
562
+ """Get recommendation from right size job"""
563
+ right_size_recommendation, right_size_job_res = None, None
564
+ try:
565
+ right_size_job_res = sage_client.describe_inference_recommendations_job(
566
+ JobName=job_or_model_name
567
+ )
568
+ if right_size_job_res:
569
+ right_size_recommendation = self._search_recommendation(
570
+ recommendation_list=right_size_job_res["InferenceRecommendations"],
571
+ inference_recommendation_id=inference_recommendation_id,
572
+ )
573
+ except sage_client.exceptions.ResourceNotFound:
574
+ pass
575
+
576
+ return right_size_recommendation, right_size_job_res
577
+
578
+ def _get_model_recommendation(
579
+ self,
580
+ sage_client,
581
+ job_or_model_name,
582
+ inference_recommendation_id,
583
+ ):
584
+ """Get recommendation from model"""
585
+ model_recommendation = None
586
+ try:
587
+ model_res = sage_client.describe_model(ModelName=job_or_model_name)
588
+ if model_res:
589
+ model_recommendation = self._search_recommendation(
590
+ recommendation_list=model_res["DeploymentRecommendation"][
591
+ "RealTimeInferenceRecommendations"
592
+ ],
593
+ inference_recommendation_id=inference_recommendation_id,
594
+ )
595
+ except sage_client.exceptions.ResourceNotFound:
596
+ pass
597
+
598
+ return model_recommendation
599
+
600
+ def _search_recommendation(self, recommendation_list, inference_recommendation_id):
601
+ """Search recommendation based on recommendation id"""
602
+ return next(
603
+ (
604
+ rec
605
+ for rec in recommendation_list
606
+ if rec["RecommendationId"] == inference_recommendation_id
607
+ ),
608
+ None,
609
+ )
610
+
611
+ # TODO: until we have bandwidth to integrate right_size + deploy with serverless
612
+ def _filter_recommendations_for_realtime(self):
613
+ """Filter recommendations list to find a realtime instance"""
614
+ instance_type = None
615
+ initial_instance_count = None
616
+ for recommendations in self.inference_recommendations:
617
+ if "ServerlessConfig" not in recommendations["EndpointConfiguration"]:
618
+ instance_type = recommendations["EndpointConfiguration"]["InstanceType"]
619
+ initial_instance_count = recommendations["EndpointConfiguration"][
620
+ "InitialInstanceCount"
621
+ ]
622
+ return (instance_type, initial_instance_count)