Skip to content

Commit

Permalink
update sagemaker agent docs (#1710)
Browse files Browse the repository at this point in the history
* update sagemaker agent docs

Signed-off-by: Samhita Alla <aallasamhita@gmail.com>

* minor update

Signed-off-by: Samhita Alla <aallasamhita@gmail.com>

---------

Signed-off-by: Samhita Alla <aallasamhita@gmail.com>
  • Loading branch information
samhita-alla authored Jul 23, 2024
1 parent 027d7d1 commit 03395b6
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}",
Expand All @@ -102,23 +101,24 @@ 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}",
},
],
"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
)


Expand All @@ -128,10 +128,11 @@ 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, `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.
#
# - `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.
#
Expand All @@ -142,6 +143,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.
#
Expand Down

0 comments on commit 03395b6

Please sign in to comment.