提交 c8460fbb authored 作者: nouiz's avatar nouiz

Merge pull request #822 from delallea/minor

Minor stuff (typos & PEP8)
......@@ -120,10 +120,10 @@ del dummy_stdin
#Keep the default optimizer the same as the one for the mode FAST_RUN
AddConfigVar('allow_gc',
"Do we default to delete intermediate results during Theano"
" function call? Doing so lower the memory requirement, but ask"
" that we reallocate memory at the next function call."
" This is implemented for the default linker, but not work all"
" linker",
" function calls? Doing so lowers the memory requirement, but"
" asks that we reallocate memory at the next function call."
" This is implemented for the default linker, but may not work"
" for all linkers.",
BoolParam(True),
in_c_key=False)
......@@ -340,13 +340,13 @@ AddConfigVar('warn.gpu_set_subtensor1',
in_c_key=False)
AddConfigVar('warn.vm_gc_bug',
"There was a bug that existed in the default Theano configuration"
" just in the development version between July 5 2012"
" and July 30 2012. This was not in a released version."
"There was a bug that existed in the default Theano configuration,"
" only in the development version between July 5th 2012"
" and July 30th 2012. This was not in a released version."
" If your code was affected by this bug, a warning"
" will be printed during the code execution if you use the"
"`linker=vm,vm.lazy=True,warn.vm_gc_bug=True` Theano flags."
"This warning is disabled by default as the bug was not released.",
" `linker=vm,vm.lazy=True,warn.vm_gc_bug=True` Theano flags."
" This warning is disabled by default as the bug was not released.",
BoolParam(False),
in_c_key=False)
......
......@@ -181,8 +181,8 @@ def test_speed_lazy():
run_memory_usage_tests = False
if run_memory_usage_tests:
# these are not normal unit tests, do not run them as part of standard
# suite. I ran them while looking at top, and stopped when memory usage was
# stable.
# suite. I ran them while looking at top, and stopped when memory usage
# was stable.
def test_leak2():
import theano.sandbox.cuda as cuda
for i in xrange(1000000):
......@@ -199,13 +199,13 @@ if run_memory_usage_tests:
def test_no_leak_many_graphs():
# Verify no memory leaks when creating and deleting a lot of functions
# This isn't really a unit test, you have to run it and look at top to see
# if there's a leak
# This isn't really a unit test, you have to run it and look at top to
# see if there's a leak
for i in xrange(10000):
x = tensor.vector()
z = x
for d in range(10):
z = tensor.sin(-z+ 1)
z = tensor.sin(-z + 1)
f = function([x], z, mode=Mode(optimizer=None, linker='cvm'))
if not i % 100:
......@@ -222,13 +222,13 @@ if run_memory_usage_tests:
def test_no_leak_many_call_lazy():
# Verify no memory leaks when calling a function a lot of times
# This isn't really a unit test, you have to run it and look at top to see
# if there's a leak
# This isn't really a unit test, you have to run it and look at top to
# see if there's a leak
def build_graph(x, depth=5):
z = x
for d in range(depth):
z = ifelse(z> 0, -z, z)
z = ifelse(z > 0, -z, z)
return z
def time_linker(name, linker):
......@@ -250,24 +250,25 @@ if run_memory_usage_tests:
print pre.ru_idrss, post.ru_idrss
print pre.ru_maxrss, post.ru_maxrss
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False, use_cloop=True))
time_linker('vmLinker_C',
lambda: vm.VM_Linker(allow_gc=False, use_cloop=True))
def test_no_leak_many_call_nonlazy():
# Verify no memory leaks when calling a function a lot of times
# This isn't really a unit test, you have to run it and look at top to see
# if there's a leak
# This isn't really a unit test, you have to run it and look at top to
# see if there's a leak.
def build_graph(x, depth=5):
z = x
for d in range(depth):
z = tensor.sin(-z+1)
z = tensor.sin(-z + 1)
return z
def time_linker(name, linker):
steps_a = 10
x = tensor.vector()
a = build_graph(x,steps_a)
a = build_graph(x, steps_a)
f_a = function([x], a,
mode=Mode(optimizer=None,
......@@ -276,7 +277,8 @@ if run_memory_usage_tests:
for i in xrange(500000):
f_a([2.0])
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False, use_cloop=True))
time_linker('vmLinker_C',
lambda: vm.VM_Linker(allow_gc=False, use_cloop=True))
class RunOnce(theano.Op):
......@@ -295,11 +297,10 @@ class RunOnce(theano.Op):
def test_vm_gc():
"""This already caused a bug in the trunk of Theano.
The bug was introduced in the trunk the July 5, 2012 and fixed the
July 30
The bug was introduced in the trunk on July 5th, 2012 and fixed on
July 30th.
"""
pass
x = theano.tensor.vector()
p = RunOnce()(x)
mode = theano.Mode(linker=theano.gof.vm.VM_Linker(lazy=True))
......
......@@ -40,7 +40,7 @@ def filter_vm_lazy(val):
AddConfigVar('vm.lazy',
"Useful only for the vm linkers. When lazy is None,"
" auto detect if lazy evaluation is needed and use the apropriate"
" version. If lazy it True/False, force the version used between"
" version. If lazy is True/False, force the version used between"
" Loop/LoopGC and Stack.",
ConfigParam('None', filter_vm_lazy))
......@@ -396,7 +396,7 @@ class Stack(VM):
#current_apply is still in the
#stack, this will cause it to be
#recomputed! This can cause wrong value
#with some combiation of inplace op.
#with some combination of inplace op.
compute_map[i][0] = 2
if (config.warn.vm_gc_bug and
current_apply in apply_stack and
......@@ -404,10 +404,10 @@ class Stack(VM):
'destroy_map',
False)):
warnings.warn(
"There was a bug that existed in the default Theano configuration"
" just in the development version between July 5 2012"
" and July 30 2012. This was not in a released version."
"The bug was affecting this script.",
"There was a bug that existed in the default Theano configuration,"
" only in the development version between July 5th 2012"
" and July 30th 2012. This was not in a released version."
" The bug was affecting this script.",
#The stack level is not good when inside a Scan.
stacklevel=3
)
......@@ -471,7 +471,7 @@ class Stack(VM):
if empty_storage_map:
storage_map[i][0] = None
#See the not lazy gc code for explanations
#Of compute_map change
#of compute_map change
compute_map[i][0] = 2
# Hacky coarse gc final pass
......@@ -507,12 +507,13 @@ class VM_Linker(link.LocalLinker):
Class that satisfies the Linker interface by acting as a VM factory.
"""
def __init__(self, allow_gc=None, use_cloop=False, callback=None, lazy=None):
def __init__(self, allow_gc=None, use_cloop=False, callback=None,
lazy=None):
"""
allow_gc - force the virtual machine to clean up unnecessary
references, in order to allow garbage collection on
intermediate values during computation of a function.
If None use as default the Theano flag allow_gc value.
If None use as default the value of the Theano flag allow_gc.
use_cloop - use the C-based virtual machine if possible
......@@ -521,7 +522,7 @@ class VM_Linker(link.LocalLinker):
'node', 'thunk', 'storage_map', and 'compute_map'.
lazy - Useful only when use_cloop is False. When lazy is None, use the
theano flag vm.lazy value. Then if we have a None(default) we auto
theano flag vm.lazy value. Then if we have a None (default) we auto
detect if lazy evaluation is needed and use the apropriate
version. If lazy is True or False, we force the version used
between Loop/LoopGC and Stack.
......
......@@ -482,7 +482,8 @@ def pydotprint(fct, outfile=None,
print_output_file=True,
assert_nb_all_strings=-1
):
"""print to a file in png format the graph of op of a compile theano fct.
"""
Print to a file (png format) the graph of a compiled theano function's ops.
:param fct: the theano fct returned by theano.function.
:param outfile: the output file where to put the graph.
......@@ -509,10 +510,10 @@ def pydotprint(fct, outfile=None,
:param var_with_name_simple: If true and a variable have a name,
we will print only the variable name.
Otherwise, we concatenate the type to the var name.
:param assert_nb_all_strings: Used for tests. This assert the
number of uniq string node in the dot graph. This is
used in tests to verify that dot won't merge Theano
node.
:param assert_nb_all_strings: Used for tests. If non-negative, assert that
the number of unique string nodes in the dot graph is equal to
this number. This is used in tests to verify that dot won't
merge Theano nodes.
In the graph, ellipses are Apply Nodes (the execution of an op)
and boxes are variables. If variables have names they are used as
......
......@@ -50,9 +50,9 @@ def test_pydotprint_cond_highlight():
def test_pydotprint_long_name():
"""This is a REALLY PARTIAL TEST.
It print a graph where there is variable and apply node that
there too long name is different, but not the shortened name.
We should not merge those node in the dot graph.
It prints a graph where there are variable and apply nodes whose long
names are different, but not the shortened names.
We should not merge those nodes in the dot graph.
"""
......@@ -145,8 +145,8 @@ def test_debugprint():
"""
if s != reference:
print '--'+s+'--'
print '--'+reference+'--'
print '--' + s + '--'
print '--' + reference + '--'
assert s == reference
......@@ -165,12 +165,11 @@ def test_debugprint():
"""
if s != reference:
print '--'+s+'--'
print '--'+reference+'--'
print '--' + s + '--'
print '--' + reference + '--'
assert s == reference
# test ids=CHAR, stop_on_name=True
s = StringIO.StringIO()
debugprint(G, file=s, ids='CHAR', stop_on_name=True)
......@@ -184,12 +183,11 @@ def test_debugprint():
"""
if s != reference:
print '--'+s+'--'
print '--'+reference+'--'
print '--' + s + '--'
print '--' + reference + '--'
assert s == reference
# test ids=
s = StringIO.StringIO()
debugprint(G, file=s, ids='')
......@@ -204,7 +202,7 @@ def test_debugprint():
|E
"""
if s != reference:
print '--'+s+'--'
print '--'+reference+'--'
print '--' + s + '--'
print '--' + reference + '--'
assert s == reference
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论