Skip to content

Commit 513a808

Browse files
author
Andre Moeller
committed
change output data dir for chainer
1 parent 971bcfd commit 513a808

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

sagemaker-python-sdk/chainer_cifar10/chainer_single_machine_cifar10.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
"* `SM_MODEL_DIR`: A string representing the path to the directory to write model artifacts to.\n",
122122
" These artifacts are uploaded to S3 for model hosting.\n",
123123
"* `SM_NUM_GPUS`: An integer representing the number of GPUs available to the host.\n",
124-
"* `SM_OUTPUT_DATA_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
124+
"* `SM_OUTPUT_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
125125
" include checkpoints, graphs, and other files to save, not including model artifacts. These artifacts are compressed\n",
126126
" and uploaded to S3 to the same S3 prefix as the model artifacts.\n",
127127
"\n",
@@ -291,10 +291,10 @@
291291
"from IPython.display import Image\n",
292292
"from IPython.display import display\n",
293293
"\n",
294-
"accuracy_graph = Image(filename=\"output/single_machine_cifar/algo-1/accuracy.png\",\n",
294+
"accuracy_graph = Image(filename=\"output/single_machine_cifar/accuracy.png\",\n",
295295
" width=800,\n",
296296
" height=800)\n",
297-
"loss_graph = Image(filename=\"output/single_machine_cifar/algo-1/loss.png\",\n",
297+
"loss_graph = Image(filename=\"output/single_machine_cifar/loss.png\",\n",
298298
" width=800,\n",
299299
" height=800)\n",
300300
"\n",
@@ -449,7 +449,7 @@
449449
"name": "python",
450450
"nbconvert_exporter": "python",
451451
"pygments_lexer": "ipython3",
452-
"version": "3.6.4"
452+
"version": "3.6.5"
453453
}
454454
},
455455
"nbformat": 4,

sagemaker-python-sdk/chainer_cifar10/chainermn_distributed_cifar10.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
"* `SM_MODEL_DIR`: A string representing the path to the directory to write model artifacts to.\n",
123123
" These artifacts are uploaded to S3 for model hosting.\n",
124124
"* `SM_NUM_GPUS`: An integer representing the number of GPUs available to the host.\n",
125-
"* `SM_OUTPUT_DATA_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
125+
"* `SM_OUTPUT_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
126126
" include checkpoints, graphs, and other files to save, not including model artifacts. These artifacts are compressed\n",
127127
" and uploaded to S3 to the same S3 prefix as the model artifacts.\n",
128128
"\n",
@@ -298,10 +298,10 @@
298298
"from IPython.display import Image\n",
299299
"from IPython.display import display\n",
300300
"\n",
301-
"accuracy_graph = Image(filename=\"output/distributed_cifar/algo-1/accuracy.png\",\n",
301+
"accuracy_graph = Image(filename=\"output/distributed_cifar/accuracy.png\",\n",
302302
" width=800,\n",
303303
" height=800)\n",
304-
"loss_graph = Image(filename=\"output/distributed_cifar/algo-1/loss.png\",\n",
304+
"loss_graph = Image(filename=\"output/distributed_cifar/loss.png\",\n",
305305
" width=800,\n",
306306
" height=800)\n",
307307
"\n",
@@ -456,7 +456,7 @@
456456
"name": "python",
457457
"nbconvert_exporter": "python",
458458
"pygments_lexer": "ipython3",
459-
"version": "3.6.4"
459+
"version": "3.6.5"
460460
},
461461
"notice": "Copyright 2018 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."
462462
},

sagemaker-python-sdk/chainer_cifar10/src/chainer_cifar_vgg_distributed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
parser.add_argument('--communicator', type=str, default='pure_nccl' if num_gpus > 0 else 'naive')
4444

4545
# Data, model, and output directories. These are required.
46-
parser.add_argument('--output-data-dir', type=str, default=os.environ['SM_OUTPUT_DATA_DIR'])
46+
parser.add_argument('--output-dir', type=str, default=os.environ['SM_OUTPUT_DIR'])
4747
parser.add_argument('--model-dir', type=str, default=os.environ['SM_MODEL_DIR'])
4848
parser.add_argument('--train', type=str, default=os.environ['SM_CHANNEL_TRAIN'])
4949
parser.add_argument('--test', type=str, default=os.environ['SM_CHANNEL_TEST'])
@@ -91,7 +91,8 @@
9191

9292
# Set up a trainer
9393
updater = training.StandardUpdater(train_iter, optimizer, device=device)
94-
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=args.output_data_dir)
94+
output_data_dir = os.path.join(args.output_dir, 'data')
95+
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=output_data_dir)
9596

9697
# Evaluate the model with the test dataset for each epoch
9798

sagemaker-python-sdk/chainer_cifar10/src/chainer_cifar_vgg_single_machine.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
parser.add_argument('--learning-rate', type=float, default=0.05)
3838

3939
# Data, model, and output directories These are required.
40-
parser.add_argument('--output-data-dir', type=str, default=os.environ['SM_OUTPUT_DATA_DIR'])
40+
parser.add_argument('--output-dir', type=str, default=os.environ['SM_OUTPUT_DIR'])
4141
parser.add_argument('--model-dir', type=str, default=os.environ['SM_MODEL_DIR'])
4242
parser.add_argument('--train', type=str, default=os.environ['SM_CHANNEL_TRAIN'])
4343
parser.add_argument('--test', type=str, default=os.environ['SM_CHANNEL_TEST'])
@@ -82,7 +82,9 @@
8282
updater = training.updater.StandardUpdater(train_iter, optimizer, device=device)
8383

8484
stop_trigger = (args.epochs, 'epoch')
85-
trainer = training.Trainer(updater, stop_trigger, out=args.output_data_dir)
85+
86+
output_data_dir = os.path.join(args.output_dir, 'data')
87+
trainer = training.Trainer(updater, stop_trigger, out=output_data_dir)
8688
# Evaluate the model with the test dataset for each epoch
8789
trainer.extend(extensions.Evaluator(test_iter, model, device=device))
8890

sagemaker-python-sdk/chainer_mnist/chainer_mnist_local_mode.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"* `SM_MODEL_DIR`: A string representing the path to the directory to write model artifacts to.\n",
138138
" These artifacts are uploaded to S3 for model hosting.\n",
139139
"* `SM_NUM_GPUS`: An integer representing the number of GPUs available to the host.\n",
140-
"* `SM_OUTPUT_DATA_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
140+
"* `SM_OUTPUT_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
141141
" include checkpoints, graphs, and other files to save, not including model artifacts. These artifacts are compressed\n",
142142
" and uploaded to S3 to the same S3 prefix as the model artifacts.\n",
143143
"\n",
@@ -501,7 +501,7 @@
501501
"name": "python",
502502
"nbconvert_exporter": "python",
503503
"pygments_lexer": "ipython3",
504-
"version": "3.6.4"
504+
"version": "3.6.5"
505505
}
506506
},
507507
"nbformat": 4,

sagemaker-python-sdk/chainer_mnist/chainer_mnist_single_machine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __call__(self, x):
4949
parser.add_argument('--batch-size', type=int, default=64)
5050

5151
# Data, model, and output directories. These are required.
52-
parser.add_argument('--output-data-dir', type=str, default=os.environ['SM_OUTPUT_DATA_DIR'])
52+
parser.add_argument('--output-dir', type=str, default=os.environ['SM_OUTPUT_DIR'])
5353
parser.add_argument('--model-dir', type=str, default=os.environ['SM_MODEL_DIR'])
5454
parser.add_argument('--train', type=str, default=os.environ['SM_CHANNEL_TRAIN'])
5555
parser.add_argument('--test', type=str, default=os.environ['SM_CHANNEL_TEST'])
@@ -96,7 +96,7 @@ def __call__(self, x):
9696
updater = training.StandardUpdater(train_iter, optimizer, device=device)
9797

9898
# Write output files to output_data_dir. These are zipped and uploaded to S3 output path as output.tar.gz.
99-
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=args.output_data_dir)
99+
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=args.output_dir)
100100

101101
# Evaluate the model with the test dataset for each epoch
102102
trainer.extend(extensions.Evaluator(test_iter, model, device=device))

sagemaker-python-sdk/chainer_sentiment_analysis/chainer_sentiment_analysis.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"* `SM_MODEL_DIR`: A string representing the path to the directory to write model artifacts to.\n",
125125
" These artifacts are uploaded to S3 for model hosting.\n",
126126
"* `SM_NUM_GPUS`: An integer representing the number of GPUs available to the host.\n",
127-
"* `SM_OUTPUT_DATA_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
127+
"* `SM_OUTPUT_DIR`: A string representing the filesystem path to write output artifacts to. Output artifacts may\n",
128128
" include checkpoints, graphs, and other files to save, not including model artifacts. These artifacts are compressed\n",
129129
" and uploaded to S3 to the same S3 prefix as the model artifacts.\n",
130130
"\n",
@@ -289,10 +289,10 @@
289289
"from IPython.display import Image\n",
290290
"from IPython.display import display\n",
291291
"\n",
292-
"accuracy_graph = Image(filename=\"output/sentiment/algo-1/accuracy.png\",\n",
292+
"accuracy_graph = Image(filename=\"output/sentiment/accuracy.png\",\n",
293293
" width=800,\n",
294294
" height=800)\n",
295-
"loss_graph = Image(filename=\"output/sentiment/algo-1/loss.png\",\n",
295+
"loss_graph = Image(filename=\"output/sentiment/loss.png\",\n",
296296
" width=800,\n",
297297
" height=800)\n",
298298
"\n",
@@ -409,7 +409,7 @@
409409
"name": "python",
410410
"nbconvert_exporter": "python",
411411
"pygments_lexer": "ipython3",
412-
"version": "3.6.4"
412+
"version": "3.6.5"
413413
},
414414
"notice": "Copyright 2018 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."
415415
},

sagemaker-python-sdk/chainer_sentiment_analysis/src/sentiment_analysis.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
parser.add_argument('--model-type', type=str, default='rnn')
3939

4040
# Data, model, and output directories. These are required.
41-
parser.add_argument('--output-data-dir', type=str, default=os.environ['SM_OUTPUT_DATA_DIR'])
41+
parser.add_argument('--output-dir', type=str, default=os.environ['SM_OUTPUT_DIR'])
4242
parser.add_argument('--model-dir', type=str, default=os.environ['SM_MODEL_DIR'])
4343
parser.add_argument('--train', type=str, default=os.environ['SM_CHANNEL_TRAIN'])
4444
parser.add_argument('--test', type=str, default=os.environ['SM_CHANNEL_TEST'])
@@ -103,7 +103,11 @@
103103
test_iter = chainer.iterators.SerialIterator(test, args.batch_size, repeat=False, shuffle=False)
104104
updater = training.updater.StandardUpdater(train_iter, optimizer, converter=convert_seq, device=device)
105105

106-
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=args.output_data_dir)
106+
# SageMaker saves the return value of train() in the `save` function in the resulting
107+
# model artifact model.tar.gz, and the contents of `output_data_dir` in the output
108+
# artifact output.tar.gz.
109+
output_data_dir = os.path.join(args.output_dir, 'data')
110+
trainer = training.Trainer(updater, (args.epochs, 'epoch'), out=output_data_dir)
107111

108112
# Evaluate the model with the test dataset for each epoch
109113
trainer.extend(extensions.Evaluator(test_iter, model, converter=convert_seq, device=device))
@@ -138,15 +142,11 @@
138142
# Run the training
139143
trainer.run()
140144

141-
# SageMaker saves the return value of train() in the `save` function in the resulting
142-
# model artifact model.tar.gz, and the contents of `output_data_dir` in the output
143-
# artifact output.tar.gz.
144-
145145
# load the best model
146-
serializers.load_npz(os.path.join(args.output_data_dir, 'best_model.npz'), model)
146+
serializers.load_npz(os.path.join(output_data_dir, 'best_model.npz'), model)
147147

148148
# remove the best model from output artifacts (since it will be saved as a model artifact)
149-
os.remove(os.path.join(args.output_data_dir, 'best_model.npz'))
149+
os.remove(os.path.join(output_data_dir, 'best_model.npz'))
150150

151151
serializers.save_npz(os.path.join(args.model_dir, 'my_model.npz'), model)
152152
with open(os.path.join(args.model_dir, 'vocab.json'), 'w') as f:

0 commit comments

Comments
 (0)