Skip to content

Commit 614cfb8

Browse files
authored
Merge branch 'main' into atqy/tensorflow2-california-housing
2 parents 730691b + 7299aa1 commit 614cfb8

File tree

2 files changed

+36
-42
lines changed

2 files changed

+36
-42
lines changed

introduction_to_applying_machine_learning/gluon_recommender_system/gluon_recommender_system.ipynb

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,15 @@
684684
"metadata": {},
685685
"outputs": [],
686686
"source": [
687-
"boto3.client(\"s3\").copy(\n",
688-
" {\n",
689-
" \"Bucket\": \"amazon-reviews-pds\",\n",
690-
" \"Key\": \"tsv/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n",
691-
" },\n",
692-
" bucket,\n",
693-
" prefix + \"/train/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n",
687+
"s3 = boto3.client(\"s3\")\n",
688+
"s3.download_file(\n",
689+
" f\"amazon-reviews-pds\",\n",
690+
" \"tsv/amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n",
691+
" \"amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\",\n",
692+
")\n",
693+
"\n",
694+
"sagemaker.Session().upload_data(\n",
695+
" \"amazon_reviews_us_Digital_Video_Download_v1_00.tsv.gz\", key_prefix=prefix + \"/train\"\n",
694696
")"
695697
]
696698
},
@@ -753,8 +755,7 @@
753755
"metadata": {},
754756
"outputs": [],
755757
"source": [
756-
"predictor = m.deploy(initial_instance_count=1, instance_type=\"ml.m4.xlarge\")\n",
757-
"predictor.serializer = None"
758+
"predictor = m.deploy(initial_instance_count=1, instance_type=\"ml.m4.xlarge\")"
758759
]
759760
},
760761
{
@@ -773,14 +774,10 @@
773774
"outputs": [],
774775
"source": [
775776
"predictor.predict(\n",
776-
" json.dumps(\n",
777-
" {\n",
778-
" \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n",
779-
" \"customer_id\"\n",
780-
" ].values.tolist(),\n",
781-
" \"product_id\": [\"B00KH1O9HW\", \"B00M5KODWO\"],\n",
782-
" }\n",
783-
" )\n",
777+
" {\n",
778+
" \"customer_id\": customer_index[customer_index[\"user\"] == 6][\"customer_id\"].values.tolist(),\n",
779+
" \"product_id\": [\"B00KH1O9HW\", \"B00M5KODWO\"],\n",
780+
" }\n",
784781
")"
785782
]
786783
},
@@ -829,7 +826,7 @@
829826
"test_preds = []\n",
830827
"for array in np.array_split(test_df[[\"customer_id\", \"product_id\"]].values, 40):\n",
831828
" test_preds += predictor.predict(\n",
832-
" json.dumps({\"customer_id\": array[:, 0].tolist(), \"product_id\": array[:, 1].tolist()})\n",
829+
" {\"customer_id\": array[:, 0].tolist(), \"product_id\": array[:, 1].tolist()}\n",
833830
" )\n",
834831
"\n",
835832
"test_preds = np.array(test_preds)\n",
@@ -872,15 +869,13 @@
872869
"predictions = []\n",
873870
"for array in np.array_split(product_index[\"product_id\"].values, 40):\n",
874871
" predictions += predictor.predict(\n",
875-
" json.dumps(\n",
876-
" {\n",
877-
" \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n",
878-
" \"customer_id\"\n",
879-
" ].values.tolist()\n",
880-
" * array.shape[0],\n",
881-
" \"product_id\": array.tolist(),\n",
882-
" }\n",
883-
" )\n",
872+
" {\n",
873+
" \"customer_id\": customer_index[customer_index[\"user\"] == 6][\n",
874+
" \"customer_id\"\n",
875+
" ].values.tolist()\n",
876+
" * array.shape[0],\n",
877+
" \"product_id\": array.tolist(),\n",
878+
" }\n",
884879
" )\n",
885880
"\n",
886881
"predictions = pd.DataFrame({\"product_id\": product_index[\"product_id\"], \"prediction\": predictions})"
@@ -917,15 +912,13 @@
917912
"predictions_user7 = []\n",
918913
"for array in np.array_split(product_index[\"product_id\"].values, 40):\n",
919914
" predictions_user7 += predictor.predict(\n",
920-
" json.dumps(\n",
921-
" {\n",
922-
" \"customer_id\": customer_index[customer_index[\"user\"] == 7][\n",
923-
" \"customer_id\"\n",
924-
" ].values.tolist()\n",
925-
" * array.shape[0],\n",
926-
" \"product_id\": array.tolist(),\n",
927-
" }\n",
928-
" )\n",
915+
" {\n",
916+
" \"customer_id\": customer_index[customer_index[\"user\"] == 7][\n",
917+
" \"customer_id\"\n",
918+
" ].values.tolist()\n",
919+
" * array.shape[0],\n",
920+
" \"product_id\": array.tolist(),\n",
921+
" }\n",
929922
" )\n",
930923
"plt.scatter(predictions[\"prediction\"], np.array(predictions_user7))\n",
931924
"plt.show()"
@@ -964,16 +957,18 @@
964957
"metadata": {},
965958
"outputs": [],
966959
"source": [
967-
"sagemaker.Session().delete_endpoint(predictor.endpoint)"
960+
"predictor.delete_model()\n",
961+
"predictor.delete_endpoint()"
968962
]
969963
}
970964
],
971965
"metadata": {
972966
"celltoolbar": "Tags",
967+
"instance_type": "ml.g4dn.xlarge",
973968
"kernelspec": {
974-
"display_name": "conda_mxnet_p36",
969+
"display_name": "Python 3 (MXNet 1.6 Python 3.6 GPU Optimized)",
975970
"language": "python",
976-
"name": "conda_mxnet_p36"
971+
"name": "python3__SAGEMAKER_INTERNAL__arn:aws:sagemaker:us-west-2:236514542706:image/mxnet-1.6-gpu-py36"
977972
},
978973
"language_info": {
979974
"codemirror_mode": {
@@ -985,7 +980,7 @@
985980
"name": "python",
986981
"nbconvert_exporter": "python",
987982
"pygments_lexer": "ipython3",
988-
"version": "3.6.10"
983+
"version": "3.6.13"
989984
},
990985
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
991986
},

sagemaker-debugger/tensorflow_profiling/tf-resnet-profiling-single-gpu-single-node.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"if install_needed:\n",
3030
" print(\"installing deps and restarting kernel\")\n",
3131
" !{sys.executable} -m pip install -U sagemaker\n",
32-
" !{sys.executable} -m pip install -U smdebug\n",
33-
" IPython.Application.instance().kernel.do_shutdown(True)"
32+
" !{sys.executable} -m pip install -U smdebug"
3433
]
3534
},
3635
{

0 commit comments

Comments
 (0)