How can I use GPU for LSTM

I used Jupyter, and it can detect the GPU :Num GPUs Available: 1 .

the demo code with tf.device(‘/GPU:0’):
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
print(c)
can print c tf.Tensor(
[[22. 28.]
[49. 64.]], shape=(2, 2), dtype=float32)

the problem is when I’m trying running the code history = model.fit(X_train, y_train, epochs=100, batch_size=32, validation_data=(X_test, y_test))
plt.plot(history.history[‘loss’], label=‘Train Loss’)
plt.plot(history.history[‘val_loss’], label=‘Validation Loss’)
plt.title(‘Model Loss’)
plt.ylabel(‘Loss’)
plt.xlabel(‘Epoch’)
plt.legend()
plt.show()

it has an unknown error
UnknownError Traceback (most recent call last)
in
----> 1 history = model.fit(X_train, y_train, epochs=100, batch_size=32, validation_data=(X_test, y_test))
2 plt.plot(history.history[‘loss’], label=‘Train Loss’)
3 plt.plot(history.history[‘val_loss’], label=‘Validation Loss’)
4 plt.title(‘Model Loss’)
5 plt.ylabel(‘Loss’)

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
726 max_queue_size=max_queue_size,
727 workers=workers,
→ 728 use_multiprocessing=use_multiprocessing)
729
730 def evaluate(self,

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
322 mode=ModeKeys.TRAIN,
323 training_context=training_context,
→ 324 total_epochs=epochs)
325 cbks.make_logs(model, epoch_logs, training_result, ModeKeys.TRAIN)
326

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in run_one_epoch(model, iterator, execution_function, dataset_size, batch_size, strategy, steps_per_epoch, num_samples, mode, training_context, total_epochs)
121 step=step, mode=mode, size=current_batch_size) as batch_logs:
122 try:
→ 123 batch_outs = execution_function(iterator)
124 except (StopIteration, errors.OutOfRangeError):
125 # TODO(kaftan): File bug about tf function and errors.OutOfRangeError?

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in execution_function(input_fn)
84 # numpy translates Tensors to values in Eager mode.
85 return nest.map_structure(_non_none_constant_value,
—> 86 distributed_function(input_fn))
87
88 return execution_function

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py in call(self, *args, **kwds)
455
456 tracing_count = self._get_tracing_count()
→ 457 result = self._call(*args, **kwds)
458 if tracing_count == self._get_tracing_count():
459 self._call_counter.called_without_tracing()

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\def_function.py in _call(self, *args, **kwds)
485 # In this case we have created variables on the first call, so we run the
486 # defunned version which is guaranteed to never create variables.
→ 487 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
488 elif self._stateful_fn is not None:
489 # Release the lock early so that multiple threads can perform the call

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in call(self, *args, **kwargs)
1821 “”“Calls a graph function specialized to the inputs.”“”
1822 graph_function, args, kwargs = self._maybe_define_function(args, kwargs)
→ 1823 return graph_function._filtered_call(args, kwargs) # pylint: disable=protected-access
1824
1825 @property

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in _filtered_call(self, args, kwargs)
1139 if isinstance(t, (ops.Tensor,
1140 resource_variable_ops.BaseResourceVariable))),
→ 1141 self.captured_inputs)
1142
1143 def _call_flat(self, args, captured_inputs, cancellation_manager=None):

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
1222 if executing_eagerly:
1223 flat_outputs = forward_function.call(
→ 1224 ctx, args, cancellation_manager=cancellation_manager)
1225 else:
1226 gradient_name = self._delayed_rewrite_functions.register()

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\function.py in call(self, ctx, args, cancellation_manager)
509 inputs=args,
510 attrs=(“executor_type”, executor_type, “config_proto”, config),
→ 511 ctx=ctx)
512 else:
513 outputs = execute.execute_with_cancellation(

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
65 else:
66 message = e.message
—> 67 six.raise_from(core._status_to_exception(e.code, message), None)
68 except TypeError as e:
69 keras_symbolic_tensors = [

C:\ProgramData\anaconda3\envs\tensorflow\lib\site-packages\six.py in raise_from(value, from_value)

UnknownError: [Derived] Fail to find the dnn implementation.
[[{{node CudnnRNN}}]]
[[sequential/lstm/StatefulPartitionedCall]] [Op:__inference_distributed_function_5913]

Function call stack:
distributed_function → distributed_function → distributed_function

my CUDA is 10.0, tensorflow_gpu 2.0.0, cudnn 7.6

Hi @Yiyao_Luo, As per test build configuration the cuDNN supported version is 7.4. Could please try with cuDNN 7.4. Also could you please try enabling the memory growth by using

tf.config.experimental.set_memory_growth(physical_devices[0], enable=True)

Note: As you are using tensorflow 2.0.0 which is an older version. I recommend you to use the latest stable version. Thank You.

Thx mate, I’ve solved that problem by enabling the memory growth! have a nice day