Skip to content Skip to sidebar Skip to footer

How To Add Report_tensor_allocations_upon_oom To Runoptions In Keras

I'm trying to train a neural net on a GPU using Keras and am getting a 'Resource exhausted: OOM when allocating tensor' error. The specific tensor it's trying to allocate isn't ve

Solution 1:

TF1 solution:

Its not as hard as it seems, what you need to know is that according to the documentation, the **kwargs parameter passed to model.compile will be passed to session.run

So you can do something like:

import tensorflow as tf
run_opts = tf.RunOptions(report_tensor_allocations_upon_oom = True)

model.compile(loss = "...", optimizer = "...", metrics = "..", options = run_opts)

And it should be passed directly each time session.run is called.

TF2:

The solution above works only for tf1. For tf2, unfortunately, it appears there is no easy solution yet.

Solution 2:

Currently, it is not possible to add the options to model.compile. See: https://github.com/tensorflow/tensorflow/issues/19911

Solution 3:

OOM means out of memory. May be it is using more memory at that time. Decrease batch_size significantly. I set to 16, then it worked fine

Solution 4:

Got the same error, but only in case, the training dataset was about the same as my GPU memory. For example, with 4 Gb video card memory I can train the model with the ~3,5 GB dataset. The workaround for me was to create the data_generator custom function, with yield, indices, and lookback. The other way I was suggested was to start learning true tensorflow framework and with tf.Session (example).

Post a Comment for "How To Add Report_tensor_allocations_upon_oom To Runoptions In Keras"