提交 02ccf5bd authored 作者: Frederic's avatar Frederic

Add function_dump() to help user give us reproducable example.

上级 5f2ed7aa
......@@ -410,3 +410,29 @@ the function itself (a "thunk" is a concept related to closures). Here, to
get the current node's first input's shape, you'd therefore do "p
thunk.inputs[0][0].shape", which prints out "(3, 4)".
.. _faq_dump_fct:
Dumping a Function to help debug
--------------------------------
If you are reading this, there is high chance that you emailed our
mailing list and we asked you to read this section. This section
explain how to dump all the parameter passed to
``theano.function()``. This is useful to help us reproduce a problem
during compilation and it don't request you to make a self contained
example.
For this to work, we need to be able to import the code for all Op in
the graph. So if you create your own Op, we will need this
code. Otherwise, we won't be able to unpickle it. We already have all
the Ops from Theano and Pylearn2.
.. code-block:: python
# Replace this line:
theano.function(...)
# with
theano.function_dump(filename, ...)
# Where filename is a string to a file that we will write to.
Then send us filename.
......@@ -57,7 +57,7 @@ from theano.compile import \
SymbolicOutput, Out, \
Mode, \
predefined_modes, predefined_linkers, predefined_optimizers, \
FunctionMaker, function, OpFromGraph, \
FunctionMaker, function, function_dump, OpFromGraph, \
Component, External, Member, Method, \
Composite, ComponentList, ComponentDict, Module, \
ProfileMode, ProfileStats, \
......
......@@ -28,4 +28,4 @@ from theano.compile.pfunc import pfunc, Param, rebuild_collect_shared
from theano.compile.builders import *
from theano.compile.function import function
from theano.compile.function import function, function_dump
......@@ -2,6 +2,7 @@
"""
__docformat__ = "restructuredtext en"
import cPickle
import logging
_logger = logging.getLogger('theano.compile.function')
......@@ -12,6 +13,27 @@ from numpy import any # to work in python 2.4
import warnings
from theano import gof
def function_dump(filename, inputs, outputs=None, mode=None, updates=None,
givens=None,
no_default_updates=False, accept_inplace=False, name=None,
rebuild_strict=True, allow_input_downcast=None, profile=None,
on_unused_input=None):
"""This is helpful to make a reproducable case for problem during
Theano compilation.
"""
assert isinstance(filename, basestring)
d = dict(inputs=inputs, outputs=outputs, mode=mode, updates=updates,
givens=givens, no_default_updates=no_default_updates,
accept_inplace=accept_inplace, name=name,
rebuild_strict=rebuild_strict,
allow_input_downcast=allow_input_downcast, profile=profile,
on_unused_input=on_unused_input)
with open(filename, 'wb') as f:
cPickle.dump(d, f, -1)
def function(inputs, outputs=None, mode=None, updates=None, givens=None,
no_default_updates=False, accept_inplace=False, name=None,
rebuild_strict=True, allow_input_downcast=None, profile=None,
......
import cPickle
import os
import shutil
import tempfile
import numpy
import theano
def test_function_dump():
v = theano.tensor.vector()
fct1 = theano.function([v], v + 1)
try:
tmpdir = tempfile.mkdtemp()
fname = os.path.join(tmpdir, 'test_function_dump.pkl')
theano.function_dump(fname, [v], v + 1)
f = open(fname, 'rb')
l = cPickle.load(f)
f.close()
finally:
if tmpdir is not None:
shutil.rmtree(tmpdir)
fct2 = theano.function(**l)
x = [1, 2, 3]
assert numpy.allclose(fct1(x), fct2(x))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论