TensorFlow provided package timeline by using the import from tensorflow.python.client
from tensorflow.python.client import timeline
This is useful for performance profiling TensorFlow application with graphical visualization similar to the graphs generated from the CUDA Visual Profiler. With a little tweak in the machine learning code, TensorFlow applications can store and report performance metrics of the learning process.
The design of the timeline package made it easy to add profiling by simply adding code below.
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE) run_metadata = tf.RunMetadata()
It is also required to instruct the model to compile with the profiling options:
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'], options=run_options, run_metadata=run_metadata)
With the sample mnist digits classifier for TensorFlow, the output shown Keras history are saved and can be later retrieved to generate reports.
Finally, using the Chrome tracing page ( chrome://tracing/ ), the performance metrics persisted on file system can be opened for verification.