From 6549dc1d6bc0276179125baf161895445d663111 Mon Sep 17 00:00:00 2001 From: Samhita Alla Date: Fri, 19 Jul 2024 18:32:20 +0530 Subject: [PATCH 1/2] update sagemaker agent docs Signed-off-by: Samhita Alla --- ...sagemaker_inference_agent_example_usage.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py b/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py index 70d02c6c9..c0f2b83d9 100644 --- a/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py +++ b/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py @@ -78,8 +78,7 @@ def sagemaker_xgboost_wf( REGION = "us-east-2" S3_OUTPUT_PATH = "s3://sagemaker-agent-xgboost/inference-output/output" -NEW_DEPLOYMENT_NAME = "xgboost-fastapi-{idempotence_token}" -EXISTING_DEPLOYMENT_NAME = "xgboost-fastapi-{inputs.idempotence_token}" +DEPLOYMENT_NAME = "xgboost-fastapi" sagemaker_image = ImageSpec( name="sagemaker-xgboost", @@ -90,10 +89,10 @@ def sagemaker_xgboost_wf( sagemaker_deployment_wf = create_sagemaker_deployment( - name="xgboost", + name="xgboost-fastapi", model_input_types=kwtypes(model_path=str, execution_role_arn=str), model_config={ - "ModelName": NEW_DEPLOYMENT_NAME, + "ModelName": DEPLOYMENT_NAME, "PrimaryContainer": { "Image": "{images.primary_container_image}", "ModelDataUrl": "{inputs.model_path}", @@ -102,11 +101,11 @@ def sagemaker_xgboost_wf( }, endpoint_config_input_types=kwtypes(instance_type=str), endpoint_config_config={ - "EndpointConfigName": NEW_DEPLOYMENT_NAME, + "EndpointConfigName": DEPLOYMENT_NAME, "ProductionVariants": [ { "VariantName": "variant-name-1", - "ModelName": EXISTING_DEPLOYMENT_NAME, + "ModelName": DEPLOYMENT_NAME, "InitialInstanceCount": 1, "InstanceType": "{inputs.instance_type}", }, @@ -114,11 +113,12 @@ def sagemaker_xgboost_wf( "AsyncInferenceConfig": {"OutputConfig": {"S3OutputPath": S3_OUTPUT_PATH}}, }, endpoint_config={ - "EndpointName": NEW_DEPLOYMENT_NAME, - "EndpointConfigName": EXISTING_DEPLOYMENT_NAME, + "EndpointName": DEPLOYMENT_NAME, + "EndpointConfigName": DEPLOYMENT_NAME, }, images={"primary_container_image": sagemaker_image}, region=REGION, + idempotence_token=True, # set to True by default ) @@ -128,10 +128,10 @@ def sagemaker_xgboost_wf( # {py:func}`~flytekitplugins.awssagemaker_inference.create_sagemaker_deployment` function. # # An idempotence token ensures the generation of unique tokens for each configuration, preventing name collisions during updates. +# By default, it is set to `True`, causing the agent to append an idempotence token to the model name, endpoint config name, and endpoint. # -# - `idempotence_token` represents the configuration hash. -# - `inputs.idempotence_token` refers to the idempotence token from the previous task. -# The workflow injects idempotence token from the previous task into the current task as an input. +# - If a field value isn't provided (e.g., `ModelName`), the agent appends the idempotence token to the workflow name and uses that as the `ModelName`. +# - You can also manually set the idempotence token by adding `{idempotence_token}` to the relevant fields in the configuration, e.g., `xgboost-{idempotence_token}`. # # `sagemaker_image` should include the inference code, necessary libraries, and an entrypoint for model serving. # @@ -142,6 +142,10 @@ def sagemaker_xgboost_wf( # # If the plugin attempts to create a deployment that already exists, it will return the existing ARNs instead of raising an error. # +# :::{note} +# When two executions run in parallel and attempt to create the same endpoint, one execution will proceed with creating the endpoint while both will wait until the endpoint creation process is complete. +# ::: +# # To receive inference requests, the container built with `sagemaker_image` must have a web server # listening on port 8080 and must accept POST and GET requests to the `/invocations` and `/ping` endpoints, respectively. # From c6675c917441a944a3173b8c09ce2ea9a07437c8 Mon Sep 17 00:00:00 2001 From: Samhita Alla Date: Fri, 19 Jul 2024 18:33:30 +0530 Subject: [PATCH 2/2] minor update Signed-off-by: Samhita Alla --- .../sagemaker_inference_agent_example_usage.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py b/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py index c0f2b83d9..adc2578ca 100644 --- a/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py +++ b/examples/sagemaker_inference_agent/sagemaker_inference_agent/sagemaker_inference_agent_example_usage.py @@ -128,7 +128,8 @@ def sagemaker_xgboost_wf( # {py:func}`~flytekitplugins.awssagemaker_inference.create_sagemaker_deployment` function. # # An idempotence token ensures the generation of unique tokens for each configuration, preventing name collisions during updates. -# By default, it is set to `True`, causing the agent to append an idempotence token to the model name, endpoint config name, and endpoint. +# By default, `idempotence_token` in `create_sagemaker_deployment` is set to `True`, causing the agent to append an idempotence token to the +# model name, endpoint config name, and endpoint. # # - If a field value isn't provided (e.g., `ModelName`), the agent appends the idempotence token to the workflow name and uses that as the `ModelName`. # - You can also manually set the idempotence token by adding `{idempotence_token}` to the relevant fields in the configuration, e.g., `xgboost-{idempotence_token}`.