Skip to content

Commit 940df69

Browse files
authored
26-Nov: Fixes to Issue #1800 and SDKv2 corrections
## Description of Changes 1- Solution to #1800 to call serializer in the Predictor constructor 2-SDKv2 updates incorporated (renamed RealTimePredictor, removed content_type from Predictor constructor, renamed image_name in estimator call etc.) 3-Changed inference instance type to m5.large (newer generation, less cost) ## Test Scenario Tested in SageMaker Studio (but with Sagemaker Classic Notebook option) SageMaker SDK version = 2.16.3.post0 See completed notebook here: https://github.com/CloudaYolla/fastai-study-group-DL4coders/blob/main/zoo-smaker-nb/DeepAR-Electricity-StudioNI-PA4.ipynb
1 parent aa22e25 commit 940df69

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

introduction_to_amazon_algorithms/deepar_electricity/DeepAR-Electricity.ipynb

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,23 @@
1616
"* Make requests to the deployed model to obtain forecasts interactively\n",
1717
"* Illustrate advanced features of DeepAR: missing values, additional time features, non-regular frequencies and category information\n",
1818
"\n",
19-
"Running this notebook takes around 40 min on a ml.c4.2xlarge for the training, and inference is done on a ml.m4.xlarge (the usage time will depend on how long you leave your served model running).\n",
19+
"Running this notebook takes around 40 min on a ml.c4.2xlarge for the training, and inference is done on a ml.m5.large (the usage time will depend on how long you leave your served model running).\n",
20+
"\n",
21+
"This notebook is tested using SageMaker Studio but using classic Notebook (From the SageMaker Menu, go to Help -> select `Launch Classic Notebook`). \n",
2022
"\n",
2123
"For more information see the DeepAR [documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/deepar.html) or [paper](https://arxiv.org/abs/1704.04110), "
2224
]
2325
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {},
30+
"outputs": [],
31+
"source": [
32+
"import sys\n",
33+
"!{sys.executable} -m pip install s3fs"
34+
]
35+
},
2436
{
2537
"cell_type": "code",
2638
"execution_count": null,
@@ -116,7 +128,9 @@
116128
{
117129
"cell_type": "code",
118130
"execution_count": null,
119-
"metadata": {},
131+
"metadata": {
132+
"scrolled": false
133+
},
120134
"outputs": [],
121135
"source": [
122136
"image_name = sagemaker.amazon.amazon_estimator.get_image_uri(region, \"forecasting-deepar\", \"latest\")"
@@ -424,8 +438,8 @@
424438
"outputs": [],
425439
"source": [
426440
"estimator = sagemaker.estimator.Estimator(\n",
441+
" image_uri=image_name,\n",
427442
" sagemaker_session=sagemaker_session,\n",
428-
" image_name=image_name,\n",
429443
" role=role,\n",
430444
" train_instance_count=1,\n",
431445
" train_instance_type='ml.c4.2xlarge',\n",
@@ -530,10 +544,22 @@
530544
"metadata": {},
531545
"outputs": [],
532546
"source": [
533-
"class DeepARPredictor(sagemaker.predictor.RealTimePredictor):\n",
547+
"from sagemaker.serializers import IdentitySerializer"
548+
]
549+
},
550+
{
551+
"cell_type": "code",
552+
"execution_count": null,
553+
"metadata": {},
554+
"outputs": [],
555+
"source": [
556+
"class DeepARPredictor(sagemaker.predictor.Predictor):\n",
534557
" \n",
535558
" def __init__(self, *args, **kwargs):\n",
536-
" super().__init__(*args, content_type=sagemaker.content_types.CONTENT_TYPE_JSON, **kwargs)\n",
559+
" super().__init__(*args, \n",
560+
" #serializer=JSONSerializer(),\n",
561+
" serializer=IdentitySerializer(content_type=\"application/json\"),\n",
562+
" **kwargs)\n",
537563
" \n",
538564
" def predict(self, ts, cat=None, dynamic_feat=None, \n",
539565
" num_samples=100, return_samples=False, quantiles=[\"0.1\", \"0.5\", \"0.9\"]):\n",
@@ -556,7 +582,7 @@
556582
" \n",
557583
" def __encode_request(self, ts, cat, dynamic_feat, num_samples, return_samples, quantiles):\n",
558584
" instance = series_to_dict(ts, cat if cat is not None else None, dynamic_feat if dynamic_feat else None)\n",
559-
"\n",
585+
" \n",
560586
" configuration = {\n",
561587
" \"num_samples\": num_samples,\n",
562588
" \"output_types\": [\"quantiles\", \"samples\"] if return_samples else [\"quantiles\"],\n",
@@ -619,7 +645,7 @@
619645
"source": [
620646
"predictor = estimator.deploy(\n",
621647
" initial_instance_count=1,\n",
622-
" instance_type='ml.m4.xlarge',\n",
648+
" instance_type='ml.m5.large',\n",
623649
" predictor_cls=DeepARPredictor)"
624650
]
625651
},
@@ -984,8 +1010,8 @@
9841010
"source": [
9851011
"%%time\n",
9861012
"estimator_new_features = sagemaker.estimator.Estimator(\n",
1013+
" image_uri=image_name,\n",
9871014
" sagemaker_session=sagemaker_session,\n",
988-
" image_name=image_name,\n",
9891015
" role=role,\n",
9901016
" train_instance_count=1,\n",
9911017
" train_instance_type='ml.c4.2xlarge',\n",
@@ -1030,7 +1056,7 @@
10301056
"%%time\n",
10311057
"predictor_new_features = estimator_new_features.deploy(\n",
10321058
" initial_instance_count=1,\n",
1033-
" instance_type='ml.m4.xlarge',\n",
1059+
" instance_type='ml.m5.large',\n",
10341060
" predictor_cls=DeepARPredictor)"
10351061
]
10361062
},
@@ -1115,9 +1141,9 @@
11151141
],
11161142
"metadata": {
11171143
"kernelspec": {
1118-
"display_name": "Python 3",
1144+
"display_name": "Python 3 (Data Science)",
11191145
"language": "python",
1120-
"name": "python3"
1146+
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
11211147
},
11221148
"language_info": {
11231149
"codemirror_mode": {

0 commit comments

Comments
 (0)