Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Certain kind of layers breaks: No MLCTrainingGraph has been found. #23

Open
Willian-Zhang opened this issue Nov 20, 2020 · 3 comments
Open

Comments

@Willian-Zhang
Copy link

Adding tf.keras.layers.Dropout to model results the following error:

tensorflow.python.framework.errors_impl.AbortedError: Compute: Operation received an exception: Compute: No MLCTrainingGraph has been found.
         [[{{node gradients/dropout_grad/MLCDropoutGrad}}]]

Expected behavior:
Running .fit on model success

Example model configuration:

model = tf.keras.models.Sequential([
  tf.keras.layers.Conv2D(32, kernel_size=(3, 3),
                 activation='relu'),
  tf.keras.layers.Conv2D(64, kernel_size=(3, 3),
                 activation='relu'),
  tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
#   tf.keras.layers.Dropout(0.25),
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(128, activation='relu'),
#   tf.keras.layers.Dropout(0.5),
  tf.keras.layers.Dense(10, activation='softmax')
])
@Willian-Zhang Willian-Zhang changed the title Certain kinds of breaks during training: No MLCTrainingGraph has been found. Certain kind of layers breaks: No MLCTrainingGraph has been found. Nov 20, 2020
@anna-tikhonova
Copy link
Collaborator

@Willian-Zhang Thank you for reporting this failure and providing a reproducible test case. We will investigate.

@anna-tikhonova
Copy link
Collaborator

@Willian-Zhang, could you try the updated wheel and let us know if you still see the crash? Thank you!

@chaosconst
Copy link

chaosconst commented Mar 5, 2021

I can use tf.keras.layers.Dropout now, but I found a Weird bug: "dropout can not work on CPU mode".

use CPU, can only get loss > 1000, and accuracy around 0.82 on test set and 0.90 on validation set after 3 epochs,

469/469 [==============================] - 18s 35ms/step - loss: 337.7770 - sparse_categorical_accuracy: 0.6640 - val_loss: 956.9423 - val_sparse_categorical_accuracy: 0.9067
Epoch 2/60
469/469 [==============================] - 16s 35ms/step - loss: 2547.7716 - sparse_categorical_accuracy: 0.7927 - val_loss: 581.1567 - val_sparse_categorical_accuracy: 0.9197
Epoch 3/60
469/469 [==============================] - 16s 35ms/step - loss: 1371.1409 - sparse_categorical_accuracy: 0.8203 - val_loss: 489.0378 - val_sparse_categorical_accuracy: 0.8921

but same code use GPU can get loss less than 0.2 and accuracy around 0.95 on test set and 0.99 on validation set after 3 epochs.

469/469 [==============================] - 26s 52ms/step - loss: 1.5316 - sparse_categorical_accuracy: 0.6025 - val_loss: 0.2223 - val_sparse_categorical_accuracy: 0.9504
Epoch 2/60
469/469 [==============================] - 24s 51ms/step - loss: 0.2544 - sparse_categorical_accuracy: 0.9356 - val_loss: 0.1293 - val_sparse_categorical_accuracy: 0.9691
Epoch 3/60
469/469 [==============================] - 24s 51ms/step - loss: 0.1716 - sparse_categorical_accuracy: 0.9553 - val_loss: 0.0920 - val_sparse_categorical_accuracy: 0.9748

and if we remove dropout layer, everything works fine.

the code is here:

import tensorflow as tf
import tensorflow_datasets as tfds

from tensorflow.python.compiler.mlcompute import mlcompute
#mlcompute.set_mlc_device(device_name='gpu')
mlcompute.set_mlc_device(device_name='cpu')

(ds_train, ds_test), ds_info = tfds.load(
    'mnist',
    split=['train', 'test'],
    shuffle_files=True,
    as_supervised=True,
    with_info=True,
)
def normalize_img(image, label):
  """Normalizes images: `uint8` -> `float32`."""
  return tf.cast(image, tf.float32) / tf.constant(255., dtype=tf.float32), label

ds_train = ds_train.map(
    normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
ds_train = ds_train.cache()
ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples)
ds_train = ds_train.batch(128)
ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE)

ds_test = ds_test.map(
    normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE)
ds_test = ds_test.batch(128)
ds_test = ds_test.cache()
ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE)


#model = tf.keras.models.Sequential([
#  tf.keras.layers.Flatten(input_shape=(28, 28)),
#  tf.keras.layers.Dense(128,activation='relu'),
#  tf.keras.layers.Dense(10)
#])
model = tf.keras.models.Sequential([
  tf.keras.layers.Conv2D(32, kernel_size=(3, 3),
                 activation='relu'),
  tf.keras.layers.Conv2D(64, kernel_size=(3, 3),
                 activation='relu'),
  tf.keras.layers.MaxPooling2D(pool_size=(2, 2)),
  tf.keras.layers.Dropout(0.25),
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dropout(0.5),
  tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(
    optimizer=tf.keras.optimizers.Adam(0.001),
    loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
    metrics=[tf.keras.metrics.SparseCategoricalAccuracy()],
)

model.fit(
    ds_train,
    epochs=60,
    validation_data=ds_test,
)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants