提交 f0f426ce authored 作者: James Bergstra's avatar James Bergstra

fixing links in debugmode docs

上级 cb315e22
...@@ -38,12 +38,12 @@ Theano provides a 'Print' Op to do this. ...@@ -38,12 +38,12 @@ Theano provides a 'Print' Op to do this.
Since Theano runs your program in a topological order, you won't have precise 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 control over the order in which multiple Print() Ops are evaluted. For a more
precise inspection of what's being computed where, when, and how, see the precise inspection of what's being computed where, when, and how, see the
:ref:`wraplinker_faq`. :ref:`faq_wraplinker`.
.. _wraplinker_faq: .. _faq_wraplinker:
How do I step through a compiled function with the WrapLinker? How do I step through a compiled function with the WrapLinker?
-------------------------------------------------------------- --------------------------------------------------------------
...@@ -81,7 +81,7 @@ The function I compiled is too slow, what's up? ...@@ -81,7 +81,7 @@ The function I compiled is too slow, what's up?
First, make sure you're running in FAST_RUN mode, by passing ``mode='FAST_RUN'`` First, make sure you're running in FAST_RUN mode, by passing ``mode='FAST_RUN'``
to ``theano.function`` or ``theano.make``. to ``theano.function`` or ``theano.make``.
Second, try the theano :ref:`profiler`. This will tell you which Apply nodes, Second, try the theano :ref:`profilemode`. This will tell you which Apply nodes,
and which Ops are eating up your CPU cycles. and which Ops are eating up your CPU cycles.
...@@ -70,14 +70,14 @@ For detailed documentation see :api:`BadOptimization`. ...@@ -70,14 +70,14 @@ For detailed documentation see :api:`BadOptimization`.
BadDestroyMap BadDestroyMap
------------- -------------
This happens when an Op's perform() or c_code() modifies an input that it wasn't This happens when an Op's ``perform()`` or ``c_code()`` modifies an input that it wasn't
supposed to. If either the ``perform`` or ``c_code`` implementation of an Op supposed to. If either the ``perform`` or ``c_code`` implementation of an Op
might modify any input, it has to advertise that fact via the ``destroy_map`` might modify any input, it has to advertise that fact via the ``destroy_map``
attribute. attribute.
For detailed documentation on the Exception see :api:`BadDestroyMap`. For detailed documentation on the Exception, see :api:`BadDestroyMap`.
For detailed documentation on the ``destroy_map`` attribute :ref:`destroymap`. For detailed documentation on the ``destroy_map`` attribute, see :ref:`_inplace`.
BadViewMap BadViewMap
...@@ -87,9 +87,9 @@ This happens when an Op's perform() or c_code() creates an alias or alias-like ...@@ -87,9 +87,9 @@ This happens when an Op's perform() or c_code() creates an alias or alias-like
dependency between an input and an output... and it didn't warn the dependency between an input and an output... and it didn't warn the
optimization system via the ``view_map`` attribute. optimization system via the ``view_map`` attribute.
For detailed documentation on the Exception see :api:`BadViewMap`. For detailed documentation on the Exception, see :api:`BadViewMap`.
For detailed documentation on the ``view_map`` attribute :ref:`destroymap`. For detailed documentation on the ``view_map`` attribute, see :ref:`_views`.
StochasticOrder StochasticOrder
......
.. _profilemode:
========================================= =========================================
ProfileMode ProfileMode
========================================= =========================================
......
.. _views_and_inplace:
============================ ============================
Views and inplace operations Views and inplace operations
...@@ -19,6 +20,7 @@ floats are immutable). Therefore, we can't make examples of these ...@@ -19,6 +20,7 @@ floats are immutable). Therefore, we can't make examples of these
concepts out of what we've just built. Nonetheless, we will present concepts out of what we've just built. Nonetheless, we will present
the concepts: the concepts:
.. _views:
Views Views
===== =====
...@@ -77,6 +79,8 @@ unsupported. Here are more examples: ...@@ -77,6 +79,8 @@ unsupported. Here are more examples:
myop.view_map = {0: [0, 1]} # THIS IS NOT SUPPORTED! Only put a single input number in the list! myop.view_map = {0: [0, 1]} # THIS IS NOT SUPPORTED! Only put a single input number in the list!
.. _inplace:
Inplace operations Inplace operations
================== ==================
...@@ -186,6 +190,9 @@ input(s)'s memory). From there, go to the previous section. ...@@ -186,6 +190,9 @@ input(s)'s memory). From there, go to the previous section.
the addition, the original x that we wanted to take the logarithm the addition, the original x that we wanted to take the logarithm
of is gone). If Theano does not know that ``add_inplace`` changes of is gone). If Theano does not know that ``add_inplace`` changes
the value of ``x`` it might invert the order and that will the value of ``x`` it might invert the order and that will
certainly lead to erroneous computations and be a headache to certainly lead to erroneous computations.
debug.
You can often identify an incorrect view_map or destroy_map by using
:ref:`DebugMode`. *Be sure to use DebugMode when developing a new Op that
uses view_map and/or destroy_map.*
...@@ -31,7 +31,7 @@ class DebugModeError(Exception): ...@@ -31,7 +31,7 @@ class DebugModeError(Exception):
"""Generic Exception raised to indicate an internal theano problem""" """Generic Exception raised to indicate an internal theano problem"""
pass pass
class BadClinkerOutput(DebugModeError): class BadCLinkerOutput(DebugModeError):
"""Exception: an Op's c_code and perform implementations don't agree.""" """Exception: an Op's c_code and perform implementations don't agree."""
r = None r = None
...@@ -45,7 +45,7 @@ class BadClinkerOutput(DebugModeError): ...@@ -45,7 +45,7 @@ class BadClinkerOutput(DebugModeError):
def __init__(self, r, val_py, val_c): def __init__(self, r, val_py, val_c):
"""Initialize members""" """Initialize members"""
super(BadClinkerOutput, self).__init__() super(BadCLinkerOutput, self).__init__()
self.r = r self.r = r
self.val_py = val_py self.val_py = val_py
self.val_c = val_c self.val_c = val_c
...@@ -861,7 +861,7 @@ class _Linker(gof.link.LocalLinker): ...@@ -861,7 +861,7 @@ class _Linker(gof.link.LocalLinker):
# compares the version from thunk_py (in r_vals) # compares the version from thunk_py (in r_vals)
# to the version produced by thunk_c (in storage_map) # to the version produced by thunk_c (in storage_map)
if not r.type.values_eq_approx(r_vals[r], storage_map[r][0]): if not r.type.values_eq_approx(r_vals[r], storage_map[r][0]):
raise BadClinkerOutput(r, val_py=r_vals[r], val_c=storage_map[r][0]) raise BadCLinkerOutput(r, val_py=r_vals[r], val_c=storage_map[r][0])
else: else:
#retrieve each output from the storage_map #retrieve each output from the storage_map
r_vals[r] = storage_map[r][0] r_vals[r] = storage_map[r][0]
...@@ -1128,7 +1128,7 @@ class DebugMode(Mode): ...@@ -1128,7 +1128,7 @@ class DebugMode(Mode):
This mode catches several kinds of internal error: This mode catches several kinds of internal error:
- inconsistent c_code and perform implementations (see `BadClinkerOutput`) - inconsistent c_code and perform implementations (see `BadCLinkerOutput`)
- a variable replacing another when their runtime values don't match. This is a symptom of - a variable replacing another when their runtime values don't match. This is a symptom of
an incorrect optimization step, or faulty Op implementation (raises `BadOptimization`) an incorrect optimization step, or faulty Op implementation (raises `BadOptimization`)
......
...@@ -268,7 +268,7 @@ def test_badclinkeroutput(): ...@@ -268,7 +268,7 @@ def test_badclinkeroutput():
[0,1,2,3], [0,1,2,3],
3, 3,
numpy.asarray([[0.,1.,2.],[3.,4.,5.],[6.,7.,8.]])) numpy.asarray([[0.,1.,2.],[3.,4.,5.],[6.,7.,8.]]))
except debugmode.BadClinkerOutput, e: except debugmode.BadCLinkerOutput, e:
print repr(e) print repr(e)
assert e.r.owner.op is inconsistent assert e.r.owner.op is inconsistent
return #TEST PASS return #TEST PASS
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论