Profiling (Python generic)

You can use any Python profiler.

Some resources:

Profiling (PyTorch)

Please refer to the PyTorch documentation for PyTorch specific tools.

Some resources:

Profiling (TensorFlow)

Your model training (or inference) is too slow, or takes too much memory? You should profile where the computing time or memory is spend. This is less specific about RETURNN but more about TensorFlow, so please refer to the TensorFlow documentation for more recent details.

Since Tensorflow 2.2, you can use the TensorFlow Profiler integrated in TensorBoard. Set the option store_tf_profile=True to record performance data for all calls. Then open TensorBoard in the model directory, where a “Profile” tab should appear. The official guide describes all available tools that are available here.


There is a bug in TF 2.3 and earlier where the “Memory Profile” view does not show a breakdown of tensors at peak memory usage. This was fixed in TF 2.4.

There is also the option store_metadata_mod_step which has the effect that every Nth step, it will do the with these additional options:

run_metadata = tf.RunMetadata()

That will be written to the TF event file, so you can see additional information about runtime and memory usage in TensorBoard. Also, it will write a timeline in Google Chrome trace format (visit chrome://tracing in Chrome and open that trace file).

See also this for further information: