Skip to content

training a sequential keras model fails #39

Closed

Description

@jsaedtler

I'm trying to run the model training for a keras sequential model on sagemaker and get this error message. Am I doing something wrong?

Traceback (most recent call last):
  File "./train_and_deploy.py", line 21, in <module>
    if __name__ == "__main__": main()
  File "./train_and_deploy.py", line 18, in main
    estimator.fit(TRAING_DATA_BUCKET)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/tensorflow/estimator.py", line 166, in fit
    fit_super()
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/tensorflow/estimator.py", line 154, in fit_super
    super(TensorFlow, self).fit(inputs, wait, logs, job_name)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/estimator.py", line 517, in fit
    super(Framework, self).fit(inputs, wait, logs, self._current_job_name)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/estimator.py", line 154, in fit
    self.latest_training_job.wait(logs=logs)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/estimator.py", line 323, in wait
    self.sagemaker_session.logs_for_job(self.job_name, wait=True)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/session.py", line 647, in logs_for_job
    self._check_job_status(job_name, description)
  File "/ANONYMIZED/venv/lib/python2.7/site-packages/sagemaker/session.py", line 390, in _check_job_status
    raise ValueError('Error training {}: {} Reason: {}'.format(job, status, reason))
ValueError: Error training binary-classification-sample-2018-01-10-10-24-07-871: Failed Reason: AlgorithmError: 
Exception during training:
Unsuccessful TensorSliceReader constructor: Failed to find any matching files for s3://sagemaker-eu-west-1-ANONYMIZED/binary-classification-sample-2018-01-10-10-24-07-871/checkpoints/.
	 [[Node: save/RestoreV2_2 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_2/tensor_names, save/RestoreV2_2/shape_and_slices)]]

Caused by op u'save/RestoreV2_2', defined at:
  File "/opt/amazon/bin/entry.py", line 32, in <module>
    modes[mode]()
  File "/opt/amazon/lib/python2.7/site-packages/container_support/training.py", line 15, in start
    fw.train()
  File "/opt/amazon/lib/python2.7/site-packages/tf_container/train.py", line 104, in train
    run.train_and_log_exceptions(train_wrapper, env.output_dir)
  File "/opt/amazon/lib/python2.7/site-packages/tf_container/run.py", line 20, in train_and_log_exceptions
    test_wrapper.train()
  File "/opt/amazon/lib/python2.7/site-packages/tf_container/trainer.

This is the model code, using the binary classification keras sample from here: https://keras.io/getting-started/sequential-model-guide/

import numpy as np
import tensorflow as tf

INPUT_TENSOR_NAME = 'inputs_input' # needs to match the name of the first layer + "_input"

def keras_model_fn(hyperparameters):
    model = tf.keras.models.Sequential()
    model.add(tf.keras.layers.Dense(64, input_dim=20, activation='relu', name='inputs'))
    model.add(tf.keras.layers.Dropout(0.5))
    model.add(tf.keras.layers.Dense(64, activation='relu'))
    model.add(tf.keras.layers.Dropout(0.5))
    model.add(tf.keras.layers.Dense(1, activation='sigmoid', name='output'))

    model.compile(loss='binary_crossentropy',
                  optimizer='rmsprop',
                  metrics=['accuracy'])
    return model

def train_input_fn(training_dir = None, hyperparameters = None):
    return _input_fn()

def eval_input_fn(training_dir = None, hyperparameters = None):
    return _input_fn()


def _load_data():
    # Generate dummy data
    X = np.random.random((1000, 20))
    y = np.random.randint(2, size=(1000, 1))

    return X.astype(np.float32), y.astype(np.float32)

def _input_fn():
    X, y = _load_data()

    return tf.estimator.inputs.numpy_input_fn(
        x={INPUT_TENSOR_NAME: X},
        y=y,
        num_epochs=None,
        shuffle=True)()

I start the training with this script:

#!/usr/bin/env python
import sagemaker
from sagemaker.tensorflow import TensorFlow

TRAING_DATA_BUCKET = 's3://ANONYMIZED'

def main():
    estimator = TensorFlow(
        entry_point='binary_classification_sample.py',
        role='SageMakeFullAccess',
        training_steps=1000,
        evaluation_steps=1000,
        hyperparameters={'learning_rate': 1e-04},
        train_instance_count=1,
        train_instance_type='ml.m4.xlarge',
        base_job_name='binary-classification-sample')

    estimator.fit(TRAING_DATA_BUCKET)


if __name__ == "__main__": main()

Local training works:

#!/usr/bin/env python
import tensorflow as tf
from binary_classification_sample import keras_model_fn, _load_data

EPOCHS = 10000

def main():
    estimator = keras_model_fn({})
    X, y = _load_data()
    tensor_board_callback = tf.keras.callbacks.TensorBoard(log_dir='./graph_logs', histogram_freq=0,
          write_graph=True, write_images=True)

    estimator.fit(X,y, epochs=EPOCHS, callbacks=[tensor_board_callback])


if __name__ == "__main__": main()

Activity

  1. mvsusp commented on Jan 15, 2018

    @mvsusp
    Contributor

    Hi @jsaedtler,

    I am investigating your issue. I will start by reproducing it.

    I will keep you updated.

  2. mvsusp commented on Jan 29, 2018

    @mvsusp
    Contributor

    Hi @jsaedtler,

    The issue happens because the TensorFlow had bug to export a Keras module to a TF Serving SavedModel. They pushed a fix in November only for the next version (1.5.0). I applied the fix in the current container (1.4.0) and it is working know. The original fix is tensorflow/tensorflow#14354

    Thanks for the patience.

  3. added a commit that references this issue on Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions