# Using tfdbg for debugging Edward models

**URL:** <https://discourse.edwardlib.org/t/using-tfdbg-for-debugging-edward-models/394>\
**Category:** General\
**Created:** [October 4, 2017, 11:53pm UTC](https://discourse.edwardlib.org/t/using-tfdbg-for-debugging-edward-models/394 "2017-10-04T23:53:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://avatars.discourse-cdn.com/v4/letter/d/eada6e/32.png) [@dan](https://discourse.edwardlib.org/u/dan)\
**Post date:** [October 4, 2017, 11:53pm UTC](https://discourse.edwardlib.org/t/using-tfdbg-for-debugging-edward-models/394/1 "2017-10-04T23:53:11Z")

</div>

I am having problems with loss functions in Edward evaluating to nans. This problem is tricky to debug because of how Tensorflow evaluates computational graphs. There is a debugger for tensorflow called [tfdbg](https://www.tensorflow.org/programmers_guide/debugger). tfdbg has a useful filter to search for infs and nans. It took me a while to figure out how to use it with Edward and there’s no example on the forum yet, so I’ll post the solution here in case others also find it useful.

```auto
import edward as ed
from tensorflow.python import debug as tf_debug

sess = tf_debug.LocalCLIDebugWrapperSession(ed.util.get_session(), ui_type="curses")
sess.add_tensor_filter("has_inf_or_nan", tf_debug.has_inf_or_nan)
...
with sess.as_default():
    ...
    inference = ed.KLqp(...)
    inference.run(...)
    ....

```

Launching your code from the command line will start the tfdbg command-line debugger. From there, you can run until the filter detects an inf or nan value with:  
`run -f has_inf_or_nan`

---

<div class="post-metadata">

**Author:** ![dustin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/dustin/32/134_2.png) [@dustin](https://discourse.edwardlib.org/u/dustin)\
**Post date:** [October 5, 2017, 4:05am UTC](https://discourse.edwardlib.org/t/using-tfdbg-for-debugging-edward-models/394/2 "2017-10-05T04:05:59Z")

</div>

Nice work! This would be really neat to have as a snippet somewhere in [http://edwardlib.org/tutorials/](http://edwardlib.org/tutorials/). Contributions welcome.
