Advanced: Debugging and Profiling

There are many handy tools implemented in ADCME for analysis, benchmarking, input/output, etc.

Debugging and Printing

Add the following line before Session and change tf.Session to see verbose printing (such as GPU/CPU information)


tf.print can be used for printing tensor values. It must be binded with an executive operator.

# a, b are tensors, and b is executive
op = tf.print(a)
b = bind(b, op)

Debugging Python Codes

If the error comes from Python (through PyCall), we can print out the Python trace with the following commands

debug(sess, o)

where o is a tensor.

The debug function traces back the Python function call. The above code is equivalent to

import traceback
    # Your codes here 
except Exception:

This Python script can be inserted to Julia and use interpolation to invoke Julia functions (in the comment line).

This technique can also be applied to other TensorFlow codes. For example, we can use this trick to debug "NotFoundError" for custom operators

using ADCME, PyCall
import tensorflow as tf
import traceback
except Exception:


Profiling can be done with the help of run_profile and save_profile

a = normal(2000, 5000)
b = normal(5000, 1000)
res = a*b 
run_profile(sess, res)
  • Open Chrome and navigate to chrome://tracing
  • Load the timeline file

Below shows an example of profiling results.

Suppress Debugging Messages

If you want to suppress annoying debugging messages, you can suppress them using the following command

  • Messages originated from Python

By default, ADCME sets the warning level to ERROR only. To set other evels of messages, choose one from the following:

  • Messages originated from C++

In this case, we can set TF_CPP_MIN_LOG_LEVEL in the environment variable. Set TF_CPP_MIN_LOG_LEVEL to 1 to filter out INFO logs, 2 to additionally filter out WARNING, 3 to additionally filter out ERROR (all messages).

For example,

using ADCME # must be called after the above line

Save and Load Diary

We can use TensorBoard to track a scalar value easily

d = Diary("test")
p = placeholder(1.0, dtype=Float64)
b = constant(1.0)+p
s = scalar(b, "variable")
for i = 1:100
    write(d, i, run(sess, s, Dict(p=>Float64(i))))