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

Merge pull request #822 from delallea/minor

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