Skip to content

Commit

Permalink
Added more info on debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
neubig committed Feb 17, 2017
1 parent bb1bfda commit 5b37cd7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions doc/source/debugging.rst
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
Debugging
==============
To make debugging simpler, you can use immediate computing mode in dynet. In this mode, every line of code gets executed immediately, just like imperative programming, so that you can find exactly where goes wrong.

Further, dynet can automatically check validity of your model, i.e., detecting Inf/NaN, if it is in immediate computing mode.
There are a number of tools to make debugging easier in DyNet.

C++
--------------
Visualization
-------------

You can switch to the immediate computing mode by calling ComputationGraph::set_immediate_compute as follows:
It is possible to create visualizations of the computation graph by calling the ``print_graphviz()`` function, which can be helpful to debug. When this functionality is used in Python, it is necessary to add the command line argument ``--dynet-viz``.

Immediate Computation
---------------------

In general, DyNet performs symbolic execution. This means that you first create the computation graph, then the computation will actually be performed when you request a value using functions such as ``forward()`` or ``value()``. However, if an error occurs during calculation, this can be hard to debug because the error doesn't occur immediately where the offending graph node is created. To make debugging simpler, you can use immediate computing mode in dynet. In this mode, every computation gets executed immediately, just like imperative programming, so that you can find exactly where goes wrong.

In C++, you can switch to the immediate computing mode by calling ComputationGraph::set_immediate_compute as follows:

.. code:: cpp
ComputationGraph cg;
cg.set_immediate_compute(true);
To activate checking validity, you can add the following code after switching to immediate computing mode.
Further, dynet can automatically check validity of your model, i.e., detecting Inf/NaN, if it is in immediate computing mode. To activate checking validity, you can add the following code after switching to immediate computing mode.

.. code:: cpp
cg.set_check_validity(true);
Python
--------------
These features in python are in progress.
These features are still in progress for Python (`contributions are welcome! <https://github.com/clab/dynet/issues/315>`_).

0 comments on commit 5b37cd7

Please sign in to comment.