Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Overview

...

This guide will show our users how to use the TensorFlow Profiler to profile the execution of your TensorFlow code.

Code example

Copy and paste the following code into `tftf-profile.py`py.

Code Block
languagepy
from datetime import datetime
import os
import tensorflow

from tensorflow.keras.datasets import mnist
from tensorflow import keras
from tensorflow.keras import layers

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

model = keras.Sequential([
    layers.Dense(512, activation="relu"),
    layers.Dense(10, activation="softmax")
])

model.compile(optimizer="rmsprop",
              loss="sparse_categorical_crossentropy",
              metrics=["accuracy"])

train_images = train_images.reshape((60000, 28 * 28))
train_images = train_images.astype("float32") / 255
test_images = test_images.reshape((10000, 28 * 28))
test_images = test_images.astype("float32") / 255

# Create a TensorBoard callback
logs = "logs/" + datetime.now().strftime("%Y%m%d-%H%M%S")

tboard_callback = tensorflow.keras.callbacks.TensorBoard(log_dir = logs,
                                                 histogram_freq = 1,
                                                 profile_batch = '10,20')

model.fit(train_images, 
          train_labels, 
          epochs=10, 
          batch_size=128, 
          callbacks = [tboard_callback])

Local Profiling

...

The tensorflow.keras.callbacks.TensorBoard command will create a tensorboard callback and profile_batch will pick batch number 10 to batch number 20.

Local profiling on your own computer

  1. Run the code with command 

    Code Block
    languagebash
    python tf-profile.py


  2. Compress the logs folder 

    Code Block
    languagebash
    tar -zcvf ./logs.tar.gz ./logs


  3. Download the tarball file with sftp and/or hal-ondemand.

  4. Decompress the tarball file

    Code Block
    languagebash
    tar -zxvf ./logs.tar.gz


  5. Install the tensorboard profile plugin in your python environment.

    Code Block
    languagebash
    pip install tensorboard_plugin_profile


  6. Launch the tensorboard with profiler installed.

    Code Block
    languagebash
    tensorboard --logdir ./logs


  7. Open the tensorboard dashboard in your web browser. (Google Chrome is strongly recommended)Image Added

Remote Profiling on HAL system

Coming soon...