|
16 | 16 | "* Make requests to the deployed model to obtain forecasts interactively\n",
|
17 | 17 | "* Illustrate advanced features of DeepAR: missing values, additional time features, non-regular frequencies and category information\n",
|
18 | 18 | "\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", |
20 | 22 | "\n",
|
21 | 23 | "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), "
|
22 | 24 | ]
|
23 | 25 | },
|
| 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 | + }, |
24 | 36 | {
|
25 | 37 | "cell_type": "code",
|
26 | 38 | "execution_count": null,
|
|
116 | 128 | {
|
117 | 129 | "cell_type": "code",
|
118 | 130 | "execution_count": null,
|
119 |
| - "metadata": {}, |
| 131 | + "metadata": { |
| 132 | + "scrolled": false |
| 133 | + }, |
120 | 134 | "outputs": [],
|
121 | 135 | "source": [
|
122 | 136 | "image_name = sagemaker.amazon.amazon_estimator.get_image_uri(region, \"forecasting-deepar\", \"latest\")"
|
|
424 | 438 | "outputs": [],
|
425 | 439 | "source": [
|
426 | 440 | "estimator = sagemaker.estimator.Estimator(\n",
|
| 441 | + " image_uri=image_name,\n", |
427 | 442 | " sagemaker_session=sagemaker_session,\n",
|
428 |
| - " image_name=image_name,\n", |
429 | 443 | " role=role,\n",
|
430 | 444 | " train_instance_count=1,\n",
|
431 | 445 | " train_instance_type='ml.c4.2xlarge',\n",
|
|
530 | 544 | "metadata": {},
|
531 | 545 | "outputs": [],
|
532 | 546 | "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", |
534 | 557 | " \n",
|
535 | 558 | " 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", |
537 | 563 | " \n",
|
538 | 564 | " def predict(self, ts, cat=None, dynamic_feat=None, \n",
|
539 | 565 | " num_samples=100, return_samples=False, quantiles=[\"0.1\", \"0.5\", \"0.9\"]):\n",
|
|
556 | 582 | " \n",
|
557 | 583 | " def __encode_request(self, ts, cat, dynamic_feat, num_samples, return_samples, quantiles):\n",
|
558 | 584 | " 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", |
560 | 586 | " configuration = {\n",
|
561 | 587 | " \"num_samples\": num_samples,\n",
|
562 | 588 | " \"output_types\": [\"quantiles\", \"samples\"] if return_samples else [\"quantiles\"],\n",
|
|
619 | 645 | "source": [
|
620 | 646 | "predictor = estimator.deploy(\n",
|
621 | 647 | " initial_instance_count=1,\n",
|
622 |
| - " instance_type='ml.m4.xlarge',\n", |
| 648 | + " instance_type='ml.m5.large',\n", |
623 | 649 | " predictor_cls=DeepARPredictor)"
|
624 | 650 | ]
|
625 | 651 | },
|
|
984 | 1010 | "source": [
|
985 | 1011 | "%%time\n",
|
986 | 1012 | "estimator_new_features = sagemaker.estimator.Estimator(\n",
|
| 1013 | + " image_uri=image_name,\n", |
987 | 1014 | " sagemaker_session=sagemaker_session,\n",
|
988 |
| - " image_name=image_name,\n", |
989 | 1015 | " role=role,\n",
|
990 | 1016 | " train_instance_count=1,\n",
|
991 | 1017 | " train_instance_type='ml.c4.2xlarge',\n",
|
|
1030 | 1056 | "%%time\n",
|
1031 | 1057 | "predictor_new_features = estimator_new_features.deploy(\n",
|
1032 | 1058 | " initial_instance_count=1,\n",
|
1033 |
| - " instance_type='ml.m4.xlarge',\n", |
| 1059 | + " instance_type='ml.m5.large',\n", |
1034 | 1060 | " predictor_cls=DeepARPredictor)"
|
1035 | 1061 | ]
|
1036 | 1062 | },
|
|
1115 | 1141 | ],
|
1116 | 1142 | "metadata": {
|
1117 | 1143 | "kernelspec": {
|
1118 |
| - "display_name": "Python 3", |
| 1144 | + "display_name": "Python 3 (Data Science)", |
1119 | 1145 | "language": "python",
|
1120 |
| - "name": "python3" |
| 1146 | + "name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0" |
1121 | 1147 | },
|
1122 | 1148 | "language_info": {
|
1123 | 1149 | "codemirror_mode": {
|
|
0 commit comments