|
| 1 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | +"""Templates module.""" |
| 14 | +from __future__ import absolute_import |
| 15 | + |
| 16 | +TRAIN_SCRIPT_TEMPLATE = """ |
| 17 | +#!/bin/bash |
| 18 | +echo "Starting training script" |
| 19 | +
|
| 20 | +echo "/opt/ml/input/config/resourceconfig.json:" |
| 21 | +cat /opt/ml/input/config/resourceconfig.json |
| 22 | +echo |
| 23 | +
|
| 24 | +echo "/opt/ml/input/config/inputdataconfig.json:" |
| 25 | +cat /opt/ml/input/config/inputdataconfig.json |
| 26 | +echo |
| 27 | +
|
| 28 | +echo "/opt/ml/input/config/hyperparameters.json:" |
| 29 | +cat /opt/ml/input/config/hyperparameters.json |
| 30 | +echo |
| 31 | +
|
| 32 | +python --version |
| 33 | +{working_dir} |
| 34 | +{install_requirements} |
| 35 | +CMD="{command}" |
| 36 | +echo "Running command: $CMD" |
| 37 | +eval $CMD |
| 38 | +EXIT_STATUS=$? |
| 39 | +
|
| 40 | +if [ $EXIT_STATUS -ne 0 ]; then |
| 41 | + echo "Command failed with exit status $EXIT_STATUS" |
| 42 | + if [ ! -s /opt/ml/output/failure ]; then |
| 43 | + echo "Command failed with exit code $EXIT_STATUS. |
| 44 | +For more details, see CloudWatch logs at 'aws/sagemaker/TrainingJobs'. |
| 45 | +TrainingJob - $TRAINING_JOB_NAME" >> /opt/ml/output/failure |
| 46 | + fi |
| 47 | + exit $EXIT_STATUS |
| 48 | +else |
| 49 | + echo "Command succeeded" |
| 50 | +fi |
| 51 | +""" |
0 commit comments