Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append the default_bucket_prefix to s3 paths if one exists to inference sample notebooks #4808

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
"\n",
"When training large models with huge amounts of data, you'll typically use big data tools, like Amazon Athena, AWS Glue, or Amazon EMR, to create your data in S3. For the purposes of this example, we are using a heart failure dataset of 299 patients. \n",
"\n",
"Davide Chicco, Giuseppe Jurman: \u201cMachine learning can predict survival of patients with heart failure from serum creatinine and ejection fraction alone\u201d. BMC Medical Informatics and Decision Making 20, 16 (2020).\n",
"Davide Chicco, Giuseppe Jurman: “Machine learning can predict survival of patients with heart failure from serum creatinine and ejection fraction alone. BMC Medical Informatics and Decision Making 20, 16 (2020).\n",
"[Web Link](\n",
"https://bmcmedinformdecismak.biomedcentral.com/articles/10.1186/s12911-020-1023-5)\n",
"\n",
Expand Down Expand Up @@ -382,13 +382,21 @@
"account = sess.boto_session.client(\"sts\").get_caller_identity()[\"Account\"]\n",
"region = sess.boto_session.region_name\n",
"image = \"{}.dkr.ecr.{}.amazonaws.com/causal-nex-container:latest\".format(account, region)\n",
"default_bucket = sess.default_bucket()\n",
"default_bucket_prefix = sess.default_bucket_prefix\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" s3_output_path = f\"s3://{default_bucket}/{default_bucket_prefix}/output\"\n",
"else:\n",
" s3_output_path = f\"s3://{default_bucket}/output\"\n",
"\n",
"bn = sage.estimator.Estimator(\n",
" image_uri=image,\n",
" role=role,\n",
" instance_count=1,\n",
" instance_type=\"ml.c4.2xlarge\",\n",
" output_path=\"s3://{}/output\".format(sess.default_bucket()),\n",
" output_path=s3_output_path,\n",
" sagemaker_session=sess,\n",
")\n",
"\n",
Expand Down Expand Up @@ -502,7 +510,7 @@
"- Does treatment X help to cure the disease?\n",
"- What happens if we change the type Y?\n",
"\n",
"Actually doing the intervention might be unfeasible or unethical \u2014 side-stepping actual interventions and still getting at causal effects is the whole point of this approach to [causal inference](https://fabiandablander.com/r/Causal-Inference.html).\n",
"Actually doing the intervention might be unfeasible or unethical side-stepping actual interventions and still getting at causal effects is the whole point of this approach to [causal inference](https://fabiandablander.com/r/Causal-Inference.html).\n",
"To read more about interventions [go here](https://medium.data4sci.com/causal-inference-part-ix-interventions-c3f94190191d) or [here](https://www.cmu.edu/dietrich/philosophy/docs/scheines/PSA2006.pdf). For the deeper understanding we recommend reading \"Book of Why\" by Judea Pearl.\n",
"\n",
"Some example questions that can be answered with Causal Analysis are:\n",
Expand Down Expand Up @@ -641,4 +649,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@
"outputs": [],
"source": [
"bucket_prefix = \"DEMO-async-inference\"\n",
"default_bucket_prefix = sm_session.default_bucket_prefix\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" bucket_prefix = f\"{default_bucket_prefix}/{bucket_prefix}\"\n",
"\n",
"resource_name = \"AsyncInferenceDemo-{}-{}\""
]
},
Expand Down Expand Up @@ -418,7 +424,7 @@
" # additional instances before the effects of previous activities are visible.\n",
" # You can configure the length of time based on your instance startup time or other application needs.\n",
" # ScaleInCooldown - The amount of time, in seconds, after a scale in activity completes before another scale in activity can start.\n",
" \"ScaleOutCooldown\": 300 # ScaleOutCooldown - The amount of time, in seconds, after a scale out activity completes before another scale out activity can start.\n",
" \"ScaleOutCooldown\": 300, # ScaleOutCooldown - The amount of time, in seconds, after a scale out activity completes before another scale out activity can start.\n",
" # 'DisableScaleIn': True|False - ndicates whether scale in by the target tracking policy is disabled.\n",
" # If the value is true , scale in is disabled and the target tracking policy won't remove capacity from the scalable resource.\n",
" },\n",
Expand Down
8 changes: 7 additions & 1 deletion async-inference/Async-Inference-Walkthrough.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@
"outputs": [],
"source": [
"bucket_prefix = \"async-inference-demo\"\n",
"default_bucket_prefix = sm_session.default_bucket_prefix\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" bucket_prefix = f\"{default_bucket_prefix}/{bucket_prefix}\"\n",
"\n",
"resource_name = \"AsyncInferenceDemo-{}-{}\""
]
},
Expand Down Expand Up @@ -448,7 +454,7 @@
" # additional instances before the effects of previous activities are visible.\n",
" # You can configure the length of time based on your instance startup time or other application needs.\n",
" # ScaleInCooldown - The amount of time, in seconds, after a scale in activity completes before another scale in activity can start.\n",
" \"ScaleOutCooldown\": 300 # ScaleOutCooldown - The amount of time, in seconds, after a scale out activity completes before another scale out activity can start.\n",
" \"ScaleOutCooldown\": 300, # ScaleOutCooldown - The amount of time, in seconds, after a scale out activity completes before another scale out activity can start.\n",
" # 'DisableScaleIn': True|False - ndicates whether scale in by the target tracking policy is disabled.\n",
" # If the value is true , scale in is disabled and the target tracking policy won't remove capacity from the scalable resource.\n",
" },\n",
Expand Down
16 changes: 12 additions & 4 deletions async-inference/HuggingFace-Async-Inference-Walkthrough.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"sagemaker_client = boto_session.client(\"sagemaker\")\n",
"sm_runtime = boto_session.client(\"sagemaker-runtime\")\n",
"s3_bucket = sm_session.default_bucket()\n",
"default_bucket_prefix = sm_session.default_bucket_prefix\n",
"current_timestamp = strftime(\"%m-%d-%H-%M\", gmtime())\n",
"logger.info(f\"Region = {region}\")\n",
"logger.info(f\"Role = {role}\")"
Expand Down Expand Up @@ -289,7 +290,15 @@
"metadata": {},
"outputs": [],
"source": [
"endpoint_config_name = model_name"
"endpoint_config_name = model_name\n",
"\n",
"input_s3_location = f\"s3://{s3_bucket}/input/input.json\"\n",
"output_s3_location = f\"s3://{s3_bucket}/output\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" input_s3_location = f\"s3://{s3_bucket}/{default_bucket_prefix}/input/input.json\"\n",
" output_s3_location = f\"s3://{s3_bucket}/{default_bucket_prefix}/output\""
]
},
{
Expand Down Expand Up @@ -324,7 +333,7 @@
" ],\n",
" AsyncInferenceConfig={\n",
" \"OutputConfig\": {\n",
" \"S3OutputPath\": f\"s3://{s3_bucket}/output\",\n",
" \"S3OutputPath\": output_s3_location,\n",
" # Optionally specify Amazon SNS topics\n",
" # \"NotificationConfig\": {\n",
" # \"SuccessTopic\": \"arn:aws:sns:us-east-2:123456789012:MyTopic\",\n",
Expand Down Expand Up @@ -390,7 +399,6 @@
"metadata": {},
"outputs": [],
"source": [
"input_s3_location = f\"s3://{s3_bucket}/input/input.json\"\n",
"print(input_s3_location)"
]
},
Expand Down Expand Up @@ -555,4 +563,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
21 changes: 18 additions & 3 deletions async-inference/Transcription_on_SM_endpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@
"sess = sagemaker.Session()\n",
"\n",
"sagemaker_session_bucket = None\n",
"default_bucket_prefix = None\n",
"\n",
"if sagemaker_session_bucket is None and sess is not None:\n",
" sagemaker_session_bucket = sess.default_bucket()\n",
" default_bucket_prefix = sess.default_bucket_prefix\n",
"\n",
"try:\n",
" role = sagemaker.get_execution_role()\n",
Expand All @@ -214,7 +217,13 @@
"metadata": {},
"outputs": [],
"source": [
"s3_location = f\"s3://{sagemaker_session_bucket}/whisper/model/model.tar.gz\""
"s3_location = f\"s3://{sagemaker_session_bucket}/whisper/model/model.tar.gz\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" s3_location = (\n",
" f\"s3://{sagemaker_session_bucket}/{default_bucket_prefix}/whisper/model/model.tar.gz\"\n",
" )"
]
},
{
Expand Down Expand Up @@ -332,6 +341,12 @@
"\n",
"async_endpoint_name = name_from_base(\"whisper-large-v2-custom-asyc\")\n",
"\n",
"s3_output_path = \"async_inference/output\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" s3_output_path = f\"{default_bucket_prefix}/async_inference/output\"\n",
"\n",
"# create Hugging Face Model Class\n",
"huggingface_model = HuggingFaceModel(\n",
" model_data=s3_location, # path to your model and script\n",
Expand All @@ -344,7 +359,7 @@
"# create async endpoint configuration\n",
"async_config = AsyncInferenceConfig(\n",
" output_path=s3_path_join(\n",
" \"s3://\", sagemaker_session_bucket, \"async_inference/output\"\n",
" \"s3://\", sagemaker_session_bucket, s3_output_path\n",
" ), # Where our results will be stored\n",
" # Add nofitication SNS if needed\n",
" notification_config={\n",
Expand Down Expand Up @@ -461,7 +476,7 @@
" \"Statistic\": \"Average\",\n",
" },\n",
" \"ScaleInCooldown\": 300, # ScaleInCooldown - The amount of time, in seconds, after a scale-in activity completes before another scale in activity can start.\n",
" \"ScaleOutCooldown\": 300 # ScaleOutCooldown - The amount of time, in seconds, after a scale-out activity completes before another scale out activity can start.\n",
" \"ScaleOutCooldown\": 300, # ScaleOutCooldown - The amount of time, in seconds, after a scale-out activity completes before another scale out activity can start.\n",
" # 'DisableScaleIn': True|False - indicates whether scale in by the target tracking policy is disabled.\n",
" # If the value is true, scale-in is disabled and the target tracking policy won't remove capacity from the scalable resource.\n",
" },\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
"role = sagemaker.get_execution_role()\n",
"bucket_name = sm_session.default_bucket()\n",
"region = boto3.Session().region_name\n",
"default_bucket_prefix = sm_session.default_bucket_prefix\n",
"\n",
"print(f\"Default IAM Role: {role}\")\n",
"print(f\"Default S3 Bucket: {bucket_name}\")\n",
Expand Down Expand Up @@ -308,6 +309,10 @@
"source": [
"prefix = \"triton-mme\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" prefix = f\"{default_bucket_prefix}/{prefix}\"\n",
"\n",
"! mkdir -p models/$prefix/MNIST1/1\n",
"! cp models/SavedModel/00000000 --recursive ./models/$prefix/MNIST1/1/model.savedmodel/"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@
"runtime_sm_client = boto3.client(\"sagemaker-runtime\")\n",
"sagemaker_session = sagemaker.Session(boto_session=boto3.Session())\n",
"bucket = sagemaker_session.default_bucket()\n",
"default_bucket_prefix = sagemaker_session.default_bucket_prefix\n",
"prefix = \"resnet50-sme-gpu-onnx\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" prefix = f\"{default_bucket_prefix}/{prefix}\"\n",
"\n",
"# endpoint variables\n",
"sm_model_name = f\"{prefix}-mdl-{ts}\"\n",
"endpoint_config_name = f\"{prefix}-epc-{ts}\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"sm_session = sagemaker.Session()\n",
"role = sagemaker.get_execution_role()\n",
"bucket_name = sm_session.default_bucket()\n",
"default_bucket_prefix = sm_session.default_bucket_prefix\n",
"region = boto3.Session().region_name\n",
"\n",
"print(f\"Default IAM Role: {role}\")\n",
Expand Down Expand Up @@ -304,6 +305,10 @@
"source": [
"prefix = \"triton-sme\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" prefix = f\"{default_bucket_prefix}/{prefix}\"\n",
"\n",
"# Reorganize the model structure that is required by Triton Server.\n",
"! mkdir -p model/$prefix/MNIST/1\n",
"! cp model/SavedModel/00000000 --recursive ./model/$prefix/MNIST/1/model.savedmodel/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,14 @@
"runtime_sm_client = boto3.client(\"sagemaker-runtime\")\n",
"sagemaker_session = sagemaker.Session(boto_session=boto3.Session())\n",
"bucket = sagemaker_session.default_bucket()\n",
"default_bucket_prefix = sagemaker_session.default_bucket_prefix\n",
"\n",
"prefix = \"resnet50-mme-gpu\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" prefix = f\"{default_bucket_prefix}/{prefix}\"\n",
"\n",
"# endpoint variables\n",
"sm_model_name = f\"{prefix}-mdl-{ts}\"\n",
"endpoint_config_name = f\"{prefix}-epc-{ts}\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,13 @@
"runtime_sm_client = boto3.client(\"sagemaker-runtime\")\n",
"sagemaker_session = sagemaker.Session(boto_session=boto3.Session())\n",
"bucket = sagemaker_session.default_bucket()\n",
"default_bucket_prefix = sagemaker_session.default_bucket_prefix\n",
"prefix = \"resnet50-mme-gpu-onnx-tensorRT-pyTorch\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" prefix = f\"{default_bucket_prefix}/{prefix}\"\n",
"\n",
"# endpoint variables\n",
"sm_model_name = f\"{prefix}-mdl-{ts}\"\n",
"endpoint_config_name = f\"{prefix}-epc-{ts}\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"\n",
"# bucket = session.default_bucket() # bucket to house artifacts\n",
"# s3_location = f\"s3://{bucket}/djl-serving/gpt-j-6B\"\n",
"# default_bucket_prefix = session.default_bucket_prefix\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"# if default_bucket_prefix:\n",
"# s3_location = f\"s3://{bucket}/{default_bucket_prefix}/djl-serving/gpt-j-6B\"\n",
"# S3Uploader.upload(\"gpt-j-6B\", s3_location)"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,18 @@
"outputs": [],
"source": [
"# upload model.tar.gz to s3\n",
"default_bucket = sess.default_bucket()\n",
"default_bucket_prefix = sess.default_bucket_prefix\n",
"\n",
"s3_upload_path = f\"s3://{default_bucket}/stable-cascade\"\n",
"\n",
"# If a default bucket prefix is specified, append it to the s3 path\n",
"if default_bucket_prefix:\n",
" s3_upload_path = f\"s3://{default_bucket}/{default_bucket_prefix}/stable-cascade\"\n",
"\n",
"s3_model_uri = S3Uploader.upload(\n",
" local_path=\"model.tar.gz\",\n",
" desired_s3_uri=f\"s3://{sess.default_bucket()}/stable-cascade\",\n",
" desired_s3_uri=s3_upload_path,\n",
")\n",
"print(f\"model uploaded to: {s3_model_uri}\")"
]
Expand Down
Loading