Skip to content

Commit

Permalink
Add ContainerConfig example comment to ir notebooks (#3600)
Browse files Browse the repository at this point in the history
* Add ContainerConfig example comment to ir notebooks

* adding containerConfig md to rest of the notebooks

* add containerConfig md and handle missing variantName

* rerun pr tests

* rerun pr tests

* rerun pr tests

* rerun pr tests

Co-authored-by: Gary Wang <[email protected]>
  • Loading branch information
gwang111 and gwang111 authored Oct 3, 2022
1 parent 413abd0 commit ed1b78c
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,79 @@
"print(model_package_version_response)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Alternative Option: ContainerConfig\n",
"\n",
"If you are missing mandatory fields to create an inference recommender job in your model package version like so (this `create_model_package` is missing `Domain`, `Task`, and `SamplePayloadUrl`):\n",
"\n",
"```\n",
"client.create_model_package(\n",
" ModelPackageGroupName=str(model_package_group_name),\n",
" ModelPackageDescription=\"HuggingFace PyTorch Inference Recommender Demo\",\n",
" InferenceSpecification={\n",
" \"Containers\": [\n",
" {\n",
" \"ContainerHostname\": \"huggingface-pytorch\",\n",
" \"Image\": inference_image,\n",
" \"ModelDataUrl\": model_url,\n",
" \"Framework\": ml_framework,\n",
" \"NearestModelName\": model,\n",
" \"Environment\": {\n",
" \"SAGEMAKER_CONTAINER_LOG_LEVEL\": \"20\",\n",
" \"SAGEMAKER_PROGRAM\": \"inference.py\",\n",
" \"SAGEMAKER_REGION\": region,\n",
" \"SAGEMAKER_SUBMIT_DIRECTORY\": model_url,\n",
" },\n",
" },\n",
" ],\n",
" \"SupportedRealtimeInferenceInstanceTypes\": [\n",
" \"ml.c5.large\",\n",
" \"ml.c5.xlarge\",\n",
" \"ml.c5.2xlarge\",\n",
" \"ml.m5.xlarge\",\n",
" \"ml.m5.2xlarge\",\n",
" ],\n",
" \"SupportedContentTypes\": [\"text/csv\"],\n",
" \"SupportedResponseMIMETypes\": [\"text/csv\"],\n",
" },\n",
")\n",
"```\n",
"\n",
"You may define the fields `Domain`, `Task`, and `SamplePayloadUrl` in the optional field `ContainerConfig` like so:\n",
"\n",
"```\n",
"payload_config = {\n",
" \"SamplePayloadUrl\": sample_payload_url,\n",
"}\n",
"\n",
"container_config = {\n",
" \"Domain\": ml_domain,\n",
" \"Task\": ml_task,\n",
" \"PayloadConfig\": payload_config,\n",
"}\n",
"```\n",
"\n",
"And then provide it directly within `create_inference_recommendations_job()` API like so:\n",
"\n",
"```\n",
"default_response = client.create_inference_recommendations_job(\n",
" JobName=str(default_job),\n",
" JobDescription=\"\",\n",
" JobType=\"Default\",\n",
" RoleArn=role,\n",
" InputConfig={\n",
" \"ModelPackageVersionArn\": model_package_arn,\n",
" \"ContainerConfig\": container_config\n",
" },\n",
")\n",
"```\n",
"\n",
"For more information on what else can be provided via `ContainerConfig` please refer to the `CreateInferenceRecommendationsJob` doc here: [CreateInferenceRecommendationsJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateInferenceRecommendationsJob.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -621,7 +694,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)"
]
},
Expand Down
54 changes: 52 additions & 2 deletions sagemaker-inference-recommender/inference-recommender.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,54 @@
"sm_client.describe_model_package(ModelPackageName=model_package_arn)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Alternative Option: ContainerConfig\n",
"\n",
"If you are missing mandatory fields to create an inference recommender job in your model package version like so (this `create_model_package_input_dict` is missing `Domain`, `Task`, and `SamplePayloadUrl`):\n",
"\n",
"```\n",
"create_model_package_input_dict = {\n",
" \"ModelPackageGroupName\": model_package_group_name,\n",
" \"ModelPackageDescription\": model_package_description,\n",
" \"ModelApprovalStatus\": model_approval_status,\n",
"}\n",
"```\n",
"\n",
"You may define the fields `Domain`, `Task`, and `SamplePayloadUrl` in the optional field `ContainerConfig` like so:\n",
"\n",
"```\n",
"payload_config = {\n",
" \"SamplePayloadUrl\": sample_payload_url,\n",
"}\n",
"\n",
"container_config = {\n",
" \"Domain\": ml_domain.upper(),\n",
" \"Task\": ml_task.upper(),\n",
" \"PayloadConfig\": payload_config,\n",
"}\n",
"```\n",
"\n",
"And then provide it directly within `create_inference_recommendations_job()` API like so:\n",
"\n",
"```\n",
"default_response = client.create_inference_recommendations_job(\n",
" JobName=str(default_job),\n",
" JobDescription=\"\",\n",
" JobType=\"Default\",\n",
" RoleArn=role,\n",
" InputConfig={\n",
" \"ModelPackageVersionArn\": model_package_arn,\n",
" \"ContainerConfig\": container_config\n",
" },\n",
")\n",
"```\n",
"\n",
"For more information on what else can be provided via `ContainerConfig` please refer to the `CreateInferenceRecommendationsJob` doc here: [CreateInferenceRecommendationsJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateInferenceRecommendationsJob.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -709,7 +757,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)\n",
"df.head()"
]
Expand Down Expand Up @@ -828,7 +877,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)\n",
"df.head()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
},
"jupyter": {},
"pycharm": {
"name": "#%%\n"
}
Expand All @@ -56,8 +55,7 @@
"execution_count": null,
"metadata": {
"collapsed": false,
"jupyter": {
},
"jupyter": {},
"pycharm": {
"name": "#%%\n"
}
Expand Down Expand Up @@ -459,6 +457,79 @@
"print(model_package_version_response)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Alternative Option: ContainerConfig\n",
"\n",
"If you are missing mandatory fields to create an inference recommender job in your model package version like so (this `create_model_package` is missing `Domain`, `Task`, and `SamplePayloadUrl`):\n",
"\n",
"```\n",
"client.create_model_package(\n",
" ModelPackageGroupName=str(model_package_group_name),\n",
" ModelPackageDescription=\"scikit-learn Inference Recommender Demo\",\n",
" InferenceSpecification={\n",
" \"Containers\": [\n",
" {\n",
" \"ContainerHostname\": \"scikit-learn\",\n",
" \"Image\": inference_image,\n",
" \"ModelDataUrl\": model_url,\n",
" \"Framework\": ml_framework,\n",
" \"NearestModelName\": model,\n",
" \"Environment\": {\n",
" \"SAGEMAKER_CONTAINER_LOG_LEVEL\": \"20\",\n",
" \"SAGEMAKER_PROGRAM\": sagemaker_program,\n",
" \"SAGEMAKER_REGION\": region,\n",
" \"SAGEMAKER_SUBMIT_DIRECTORY\": sourcedir_url,\n",
" },\n",
" },\n",
" ],\n",
" \"SupportedRealtimeInferenceInstanceTypes\": [\n",
" \"ml.c5.large\",\n",
" \"ml.c5.xlarge\",\n",
" \"ml.c5.2xlarge\",\n",
" \"ml.m5.xlarge\",\n",
" \"ml.m5.2xlarge\",\n",
" ],\n",
" \"SupportedContentTypes\": [\"text/csv\"],\n",
" \"SupportedResponseMIMETypes\": [\"text/csv\"],\n",
" },\n",
")\n",
"```\n",
"\n",
"You may define the fields `Domain`, `Task`, and `SamplePayloadUrl` in the optional field `ContainerConfig` like so:\n",
"\n",
"```\n",
"payload_config = {\n",
" \"SamplePayloadUrl\": sample_payload_url,\n",
"}\n",
"\n",
"container_config = {\n",
" \"Domain\": ml_domain,\n",
" \"Task\": ml_task,\n",
" \"PayloadConfig\": payload_config,\n",
"}\n",
"```\n",
"\n",
"And then provide it directly within `create_inference_recommendations_job()` API like so:\n",
"\n",
"```\n",
"default_response = client.create_inference_recommendations_job(\n",
" JobName=str(default_job),\n",
" JobDescription=\"\",\n",
" JobType=\"Default\",\n",
" RoleArn=role,\n",
" InputConfig={\n",
" \"ModelPackageVersionArn\": model_package_arn,\n",
" \"ContainerConfig\": container_config\n",
" },\n",
")\n",
"```\n",
"\n",
"For more information on what else can be provided via `ContainerConfig` please refer to the `CreateInferenceRecommendationsJob` doc here: [CreateInferenceRecommendationsJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateInferenceRecommendationsJob.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -567,7 +638,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)"
]
},
Expand Down Expand Up @@ -717,7 +789,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)\n",
"df.head()"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,54 @@
"print(\"ModelPackage Version ARN : {}\".format(model_package_arn))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Alternative Option: ContainerConfig\n",
"\n",
"If you are missing mandatory fields to create an inference recommender job in your model package version like so (this `create_model_package_input_dict` is missing `Domain`, `Task`, and `SamplePayloadUrl`):\n",
"\n",
"```\n",
"create_model_package_input_dict = {\n",
" \"ModelPackageGroupName\": model_package_group_name,\n",
" \"ModelPackageDescription\": model_package_description,\n",
" \"ModelApprovalStatus\": model_approval_status,\n",
"}\n",
"```\n",
"\n",
"You may define the fields `Domain`, `Task`, and `SamplePayloadUrl` in the optional field `ContainerConfig` like so:\n",
"\n",
"```\n",
"payload_config = {\n",
" \"SamplePayloadUrl\": sample_payload_url,\n",
"}\n",
"\n",
"container_config = {\n",
" \"Domain\": ml_domain.upper(),\n",
" \"Task\": ml_task.upper(),\n",
" \"PayloadConfig\": payload_config,\n",
"}\n",
"```\n",
"\n",
"And then provide it directly within `create_inference_recommendations_job()` API like so:\n",
"\n",
"```\n",
"default_response = client.create_inference_recommendations_job(\n",
" JobName=str(default_job),\n",
" JobDescription=\"\",\n",
" JobType=\"Default\",\n",
" RoleArn=role,\n",
" InputConfig={\n",
" \"ModelPackageVersionArn\": model_package_arn,\n",
" \"ContainerConfig\": container_config\n",
" },\n",
")\n",
"```\n",
"\n",
"For more information on what else can be provided via `ContainerConfig` please refer to the `CreateInferenceRecommendationsJob` doc here: [CreateInferenceRecommendationsJob](https://docs.aws.amazon.com/sagemaker/latest/APIReference/API_CreateInferenceRecommendationsJob.html)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -583,7 +631,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)\n",
"df.head()"
]
Expand Down Expand Up @@ -778,7 +827,8 @@
" for x in inference_recommender_job[\"InferenceRecommendations\"]\n",
"]\n",
"df = pd.DataFrame(data)\n",
"df.drop(\"VariantName\", inplace=True, axis=1)\n",
"dropFilter = df.filter([\"VariantName\"])\n",
"df.drop(dropFilter, inplace=True, axis=1)\n",
"pd.set_option(\"max_colwidth\", 400)\n",
"df.head()"
]
Expand Down
Loading

0 comments on commit ed1b78c

Please sign in to comment.