Skip to content

Commit e5ac7c7

Browse files
committed
upgrade notebook to SDK v2
1 parent dc5dc7c commit e5ac7c7

File tree

2 files changed

+228
-123
lines changed

2 files changed

+228
-123
lines changed

sagemaker-experiments/mnist-handwritten-digits-classification-experiment/mnist-handwritten-digits-classification-experiment.ipynb

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"metadata": {},
4545
"outputs": [],
4646
"source": [
47-
"!{sys.executable} -m pip install sagemaker-experiments"
47+
"!{sys.executable} -m pip install sagemaker-experiments==0.1.24"
4848
]
4949
},
5050
{
@@ -60,8 +60,11 @@
6060
"metadata": {},
6161
"outputs": [],
6262
"source": [
63-
"!{sys.executable} -m pip install torch\n",
64-
"!{sys.executable} -m pip install torchvision"
63+
"# pytorch version needs to be the same in both the notebook instance and the training job container \n",
64+
"# https://github.com/pytorch/pytorch/issues/25214\n",
65+
"!{sys.executable} -m pip install torch==1.1.0\n",
66+
"!{sys.executable} -m pip install torchvision==0.3.0\n",
67+
"!{sys.executable} -m pip install pillow==6.2.2"
6568
]
6669
},
6770
{
@@ -73,7 +76,7 @@
7376
},
7477
{
7578
"cell_type": "code",
76-
"execution_count": null,
79+
"execution_count": 1,
7780
"metadata": {},
7881
"outputs": [],
7982
"source": [
@@ -82,7 +85,7 @@
8285
"import boto3\n",
8386
"import numpy as np\n",
8487
"import pandas as pd\n",
85-
"%config InlineBackend.figure_format = 'retina'\n",
88+
"from IPython.display import set_matplotlib_formats\n",
8689
"from matplotlib import pyplot as plt\n",
8790
"from torchvision import datasets, transforms\n",
8891
"\n",
@@ -94,7 +97,9 @@
9497
"from smexperiments.experiment import Experiment\n",
9598
"from smexperiments.trial import Trial\n",
9699
"from smexperiments.trial_component import TrialComponent\n",
97-
"from smexperiments.tracker import Tracker"
100+
"from smexperiments.tracker import Tracker\n",
101+
"\n",
102+
"set_matplotlib_formats('retina')"
98103
]
99104
},
100105
{
@@ -307,12 +312,13 @@
307312
" # all input configurations, parameters, and metrics specified in estimator \n",
308313
" # definition are automatically tracked\n",
309314
" estimator = PyTorch(\n",
315+
" py_version='py3',\n",
310316
" entry_point='./mnist.py',\n",
311317
" role=role,\n",
312318
" sagemaker_session=sagemaker.Session(sagemaker_client=sm),\n",
313319
" framework_version='1.1.0',\n",
314-
" train_instance_count=1,\n",
315-
" train_instance_type='ml.c4.xlarge',\n",
320+
" instance_count=1,\n",
321+
" instance_type='ml.c4.xlarge',\n",
316322
" hyperparameters={\n",
317323
" 'epochs': 2,\n",
318324
" 'backend': 'gloo',\n",
@@ -470,6 +476,7 @@
470476
" model_data, \n",
471477
" role, \n",
472478
" './mnist.py', \n",
479+
" py_version='py3',\n",
473480
" env=env, \n",
474481
" sagemaker_session=sagemaker.Session(sagemaker_client=sm),\n",
475482
" framework_version='1.1.0',\n",
@@ -497,39 +504,29 @@
497504
"metadata": {},
498505
"outputs": [],
499506
"source": [
500-
"predictor.delete_endpoint()\n",
501-
"\n",
502-
"def cleanup(experiment):\n",
503-
" for trial_summary in experiment.list_trials():\n",
504-
" trial = Trial.load(sagemaker_boto_client=sm, trial_name=trial_summary.trial_name)\n",
505-
" for trial_component_summary in trial.list_trial_components():\n",
506-
" tc = TrialComponent.load(\n",
507-
" sagemaker_boto_client=sm,\n",
508-
" trial_component_name=trial_component_summary.trial_component_name)\n",
509-
" trial.remove_trial_component(tc)\n",
510-
" try:\n",
511-
" # comment out to keep trial components\n",
512-
" tc.delete()\n",
513-
" except:\n",
514-
" # tc is associated with another trial\n",
515-
" continue\n",
516-
" # to prevent throttling\n",
517-
" time.sleep(.5)\n",
518-
" trial.delete()\n",
519-
" experiment.delete()\n",
520-
"\n",
521-
"cleanup(mnist_experiment)"
507+
"predictor.delete_endpoint()"
522508
]
523509
},
524510
{
525511
"cell_type": "code",
526512
"execution_count": null,
527513
"metadata": {},
528514
"outputs": [],
529-
"source": []
515+
"source": [
516+
"mnist_experiment.delete_all(action='--force')"
517+
]
518+
},
519+
{
520+
"cell_type": "markdown",
521+
"metadata": {},
522+
"source": [
523+
"## Contact\n",
524+
"Submit any questions or issues to https://github.com/aws/sagemaker-experiments/issues or mention @aws/sagemakerexperimentsadmin "
525+
]
530526
}
531527
],
532528
"metadata": {
529+
"instance_type": "ml.t3.medium",
533530
"kernelspec": {
534531
"display_name": "Python 3 (Data Science)",
535532
"language": "python",

0 commit comments

Comments
 (0)