提交 12886abb authored 作者: Frederic Bastien's avatar Frederic Bastien

flake8 and better doc

上级 2348c3c2
...@@ -443,6 +443,6 @@ def test_reallocation(): ...@@ -443,6 +443,6 @@ def test_reallocation():
def test_no_recycling(): def test_no_recycling():
x = theano.tensor.vector() x = theano.tensor.vector()
mode = theano.Mode(optimizer='fast_compile') mode = theano.Mode(optimizer='fast_compile')
f=theano.function([x], x+1, mode=mode) f = theano.function([x], x + 1, mode=mode)
f2=theano.function([x], (x+1)*2, mode=mode) f2 = theano.function([x], (x + 1) * 2, mode=mode)
theano.printing.debugprint([f, f2]) theano.printing.debugprint([f, f2])
...@@ -748,8 +748,7 @@ class VM_Linker(link.LocalLinker): ...@@ -748,8 +748,7 @@ class VM_Linker(link.LocalLinker):
self.schedule = schedule self.schedule = schedule
def accept(self, fgraph, no_recycling=None, profile=None): def accept(self, fgraph, no_recycling=None, profile=None):
""" """Check if fgraph is the first FunctionGraph that has ever been
Check if fgraph is the first FunctionGraph that has ever been
associated to self, else, create a new VM_Linker associated to self, else, create a new VM_Linker
associated to fgraph associated to fgraph
...@@ -758,8 +757,33 @@ class VM_Linker(link.LocalLinker): ...@@ -758,8 +757,33 @@ class VM_Linker(link.LocalLinker):
fgraph fgraph
A PerformLinker can have accepted one FunctionGraph instance A PerformLinker can have accepted one FunctionGraph instance
at a time. at a time.
no_recycling no_recycling
WRITEME
no_recycling is a list of storage (list of 1 element, the
value corresponding to one variable). Those variable
storage should not be reused after the call that created
them.
This happen for example for output of the graph that we
give to the user. We don't want to reuse those object in
case the user have kept it.
VM_Linker make sure this happen by setting the list
element to None at the start of each call.
Older Linker use not exactly the same mechanism. They will
also modify the c code to don't look up the value in the
storage. This cause duplicate c code compilation for the
same op if they are in the middle of the graph or in the
no_recycling. We don't want that, so compile all c code
the same (middle of the graph vs output).
TODO: change the logic to remove the reference at the end
of the call instead of the start. This will request all VM
implementation (Loop, LoopGC, Stack, CVM).__call__ to
return the user outputs as Function.__call__ won't be able
to find them anymore.
Returns Returns
------- -------
...@@ -1021,7 +1045,6 @@ class VM_Linker(link.LocalLinker): ...@@ -1021,7 +1045,6 @@ class VM_Linker(link.LocalLinker):
): ):
fgraph = self.fgraph fgraph = self.fgraph
order = self.schedule(fgraph) order = self.schedule(fgraph)
no_recycling = self.no_recycling
input_storage, output_storage, storage_map = link.map_storage( input_storage, output_storage, storage_map = link.map_storage(
fgraph, order, input_storage, output_storage, storage_map) fgraph, order, input_storage, output_storage, storage_map)
...@@ -1051,13 +1074,12 @@ class VM_Linker(link.LocalLinker): ...@@ -1051,13 +1074,12 @@ class VM_Linker(link.LocalLinker):
for node in order: for node in order:
try: try:
thunk_start = time.time() thunk_start = time.time()
# no-recycling is done at each VM.__call__ So there is
# no need to cause duplicate c code by passing
# no_recycling here.
thunks.append(node.op.make_thunk(node, thunks.append(node.op.make_thunk(node,
storage_map, storage_map,
compute_map, compute_map,
# The no recycling is done at the VM.__call__
# implementation at the next call with the
# pre_call_clear. So there is no need to cause
# duplicate c code by passing no_recycling here.
no_recycling=[], no_recycling=[],
impl=impl)) impl=impl))
linker_make_thunk_time[node] = time.time() - thunk_start linker_make_thunk_time[node] = time.time() - thunk_start
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论