Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4147fa5
提交
c4147fa5
authored
7月 23, 2015
作者:
Iban Harlouchet
提交者:
Arnaud Bergeron
9月 08, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
testcode for doc/tutorial/debug_faq.txt
上级
762cb0d1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
33 行增加
和
25 行删除
+33
-25
debug_faq.txt
doc/tutorial/debug_faq.txt
+33
-25
没有找到文件。
doc/tutorial/debug_faq.txt
浏览文件 @
c4147fa5
...
...
@@ -23,7 +23,7 @@ Interpreting Error Messages
Even in its default configuration, Theano tries to display useful error
messages. Consider the following faulty code.
..
code-block:: python
..
testcode::
import numpy as np
import theano
...
...
@@ -38,7 +38,7 @@ messages. Consider the following faulty code.
Running the code above we see:
..
code-block:: bash
..
testoutput::
Traceback (most recent call last):
File "test0.py", line 10, in <module>
...
...
@@ -71,7 +71,7 @@ the faulty line, while ``exception_verbosity=high`` will display a
debugprint of the apply node. Using these hints, the end of the error
message becomes :
..
code-block:: bash
..
testoutput::
Backtrace when the node is created:
File "test0.py", line 8, in <module>
...
...
@@ -101,7 +101,7 @@ following example. Here, we use ``exception_verbosity=high`` and
``optimizer=None`` would and it could therefore be used instead of test values.
..
code-block:: python
..
testcode:: testvalues
import numpy
import theano
...
...
@@ -137,7 +137,7 @@ following example. Here, we use ``exception_verbosity=high`` and
Running the above code generates the following error message:
..
code-block:: bash
..
testoutput:: testvalues
Traceback (most recent call last):
File "test1.py", line 31, in <module>
...
...
@@ -166,7 +166,7 @@ Running the above code generates the following error message:
If the above is not informative enough, by instrumenting the code ever
so slightly, we can get Theano to reveal the exact source of the error.
..
code-block:: python
..
testcode:: testvalues
# enable on-the-fly graph computations
theano.config.compute_test_value = 'warn'
...
...
@@ -185,7 +185,7 @@ of error can thus be identified with much more precision and much earlier in
the compilation pipeline. For example, running the above code yields the
following error message, which properly identifies *line 24* as the culprit.
..
code-block:: bash
..
testoutput:: testvalues
Traceback (most recent call last):
File "test2.py", line 24, in <module>
...
...
@@ -228,7 +228,10 @@ The ``compute_test_value`` mechanism works as follows:
Theano provides a 'Print' op to do this.
.. code-block:: python
.. testcode::
import numpy
import theano
x = theano.tensor.dvector('x')
...
...
@@ -243,6 +246,9 @@ Theano provides a 'Print' op to do this.
#this runs the graph with the message, and value printed
assert numpy.all( f_with_print([1, 2, 3]) == [5, 10, 15])
.. testoutput::
this is a very important value __str__ = [ 1. 2. 3.]
Since Theano runs your program in a topological order, you won't have precise
control over the order in which multiple ``Print()`` ops are evaluted. For a more
...
...
@@ -324,7 +330,7 @@ You can use ``MonitorMode`` to inspect the inputs and outputs of each
node being executed when the function is called. The code snipped below
shows how to print all inputs and outputs:
..
code-block:: python
..
testcode::
import theano
...
...
@@ -341,8 +347,9 @@ shows how to print all inputs and outputs:
post_func=inspect_outputs))
f(3)
# The code will print the following:
# 0 Elemwise{mul,no_inplace}(TensorConstant{5.0}, x) input(s) value(s): [array(5.0), array(3.0)] output(s) value(s): [array(15.0)]
.. testoutput::
0 Elemwise{mul,no_inplace}(TensorConstant{5.0}, x) input(s) value(s): [array(5.0), array(3.0)] output(s) value(s): [array(15.0)]
When using these ``inspect_inputs`` and ``inspect_outputs`` functions
with ``MonitorMode``, you should see [potentially a lot of] printed output.
...
...
@@ -357,7 +364,7 @@ position, or only if a particular value showed up in one of the inputs or output
A typical example is to detect when NaN values are added into computations, which
can be achieved as follows:
..
code-block:: python
..
testcode:: compiled
import numpy
...
...
@@ -385,12 +392,13 @@ can be achieved as follows:
post_func=detect_nan))
f(0) # log(0) * 0 = -inf * 0 = NaN
# The code above will print:
# *** NaN detected ***
# Elemwise{Composite{[mul(log(i0), i0)]}} [@A] ''
# |x [@B]
# Inputs : [array(0.0)]
# Outputs: [array(nan)]
.. testoutput:: compiled
*** NaN detected ***
Elemwise{Composite{(log(i0) * i0)}} [@A] ''
|x [@B]
Inputs : [array(0.0)]
Outputs: [array(nan)]
To help understand what is happening in your graph, you can
disable the ``local_elemwise_fusion`` and all ``inplace``
...
...
@@ -402,12 +410,12 @@ will not be able to see the input that was overwriten in the ``post_func``
function. To disable those optimizations (with a Theano version after
0.6rc3), define the MonitorMode like this:
..
code-block:: python
..
testcode:: compiled
mode = theano.compile.MonitorMode(post_func=detect_nan).excluding(
'local_elemwise_fusion', 'inplace)
f = theano.function([x], [theano.tensor.log(x) * x],
mode=mode)
'local_elemwise_fusion', 'inplace
'
)
f = theano.function([x], [theano.tensor.log(x) * x],
mode=mode)
.. note::
...
...
@@ -422,7 +430,7 @@ the execution of the node can garbage collect its inputs that aren't
needed anymore by the Theano function. This can be done with the Theano
flag:
..
code-block:: cfg
..
testcode:: compiled
allow_gc=False
...
...
@@ -443,7 +451,7 @@ functions.
Consider this example script ("ex.py"):
..
code-block:: python
..
testcode::
import theano
import numpy
...
...
@@ -464,7 +472,7 @@ This is actually so simple the debugging could be done easily, but it's for
illustrative purposes. As the matrices can't be multiplied element-wise
(unsuitable shapes), we get the following exception:
..
code-block:: text
..
testoutput::
File "ex.py", line 14, in <module>
f(mat1, mat2)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论