Skip to content

Commit

Permalink
Add installation of patches to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jdehning committed Mar 1, 2021
1 parent bf42873 commit a6f26e9
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions docs/source/doc/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,59 @@ Debugging

This is a small list of debug code snippets.

Enable tensorflow eager execution
Debugging nans with tensorflow
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It is a little problematic, because some nans occur during the
runtime without being an error. Often these are cases where an
operation has different implementations based on the value of the
input, because it would otherwise lead to a loss of precision.

Therefore we wrote some patches, which put try-except blocks
around these code parts and if a error occurs, disable check_numeric
for this part.

For patching tensorflow_probability
(replace the variables by the correct path):

::

cd scripts/debugging_patches
patch -d {$CONDA_PATH}/envs/{$ENVIRONMENT_NAME}/ -p 0 < filter_nan_errors1.patch
patch -d {$CONDA_PATH}/envs/{$ENVIRONMENT_NAME}/ -p 0 < filter_nan_errors2.patch
patch -d {$CONDA_PATH}/envs/{$ENVIRONMENT_NAME}/ -p 0 < filter_nan_errors3.patch

And then uncomment these line of codes in the run_script. Check_numerics
has to enabled only before the optimization, not before the initial
sampling, because the nan occuring during the sampling of the gamma
distribution hasn't been patched.

::

tf.config.run_functions_eagerly(True)
tf.debugging.enable_check_numerics(stack_height_limit=30, path_length_limit=50)
tf.config.run_functions_eagerly(True)
tf.debugging.enable_check_numerics(stack_height_limit=30, path_length_limit=50)

For debugging the VI, it is reasonable to increase the step size, to run
more quickly into errors


Basic usage of logger
^^^^^^^^^^^^^^^^^^^^^

::

# Change to debug mode i.e all log.debug is printed
logging.basicConfig(level=logging.DEBUG)
# Change to debug mode i.e all log.debug is printed
logging.basicConfig(level=logging.DEBUG)

# Use log.debug instead of print
log.debug(f"My var {var}")
# Use log.debug instead of print
log.debug(f"My var {var}")


Force cpu or other device
^^^^^^^^^^^^^^^^^^^^^^^^^

::

my_devices = tf.config.experimental.list_physical_devices(device_type="CPU")
tf.config.experimental.set_visible_devices(devices=my_devices, device_type="CPU")
tf.config.set_visible_devices([], "GPU")
my_devices = tf.config.experimental.list_physical_devices(device_type="CPU")
tf.config.experimental.set_visible_devices(devices=my_devices, device_type="CPU")
tf.config.set_visible_devices([], "GPU")

0 comments on commit a6f26e9

Please sign in to comment.