提交 6b5b2534 authored 作者: lamblin's avatar lamblin

Merge pull request #798 from nouiz/vm_gc_follow_up

Vm gc follow up
......@@ -339,6 +339,17 @@ AddConfigVar('warn.gpu_set_subtensor1',
BoolParam(warn_default('0.6')),
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."
" 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.",
BoolParam(False),
in_c_key=False)
AddConfigVar('compute_test_value',
("If 'True', Theano will run each op at graph build time, using "
"Constants, SharedVariables and the tag 'test_value' as inputs "
......
......@@ -306,3 +306,9 @@ def test_vm_gc():
f = theano.function([theano.In(x, mutable=True)], [p + 1, p + 2],
mode=mode)
f([1, 2, 3])
p = RunOnce()(x)
pp = p + p
f = theano.function([x], [pp + pp],
mode=mode)
f([1, 2, 3])
......@@ -3,10 +3,12 @@ VMs that run Theano graph computations.
A VM is not actually different from a Linker, we just decided
VM was a better name at some point
"""
import link
import logging
import sys
import time
import link
import warnings
from theano.gof.python25 import all
import theano
......@@ -396,6 +398,19 @@ class Stack(VM):
#recomputed! This can cause wrong value
#with some combiation of inplace op.
compute_map[i][0] = 2
if (config.warn.vm_gc_bug and
current_apply in apply_stack and
getattr(current_apply.op,
'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.",
#The stack level is not good when inside a Scan.
stacklevel=3
)
elif not computed_ins:
# -- Non-lazy case, need inputs
apply_stack.append(current_apply)
......@@ -505,10 +520,11 @@ class VM_Linker(link.LocalLinker):
the virtual machine. It will be called with four arguments called
'node', 'thunk', 'storage_map', and 'compute_map'.
lazy - Useful only when use_cloop is False. When lazy is None, auto
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
detect if lazy evaluation is needed and use the apropriate
version. If lazy it True/False, force the version used between
Loop/LoopGC and Stack.
version. If lazy is True or False, we force the version used
between Loop/LoopGC and Stack.
"""
if allow_gc is None:
......@@ -712,6 +728,8 @@ class VM_Linker(link.LocalLinker):
assert c0 == sys.getrefcount(node_n_inputs)
else:
lazy = self.lazy
if lazy is None:
lazy = config.vm.lazy
if lazy is None:
lazy = not all([(not th.lazy) for th in thunks])
if not lazy:
......
......@@ -68,8 +68,8 @@ THEANO_FLAGS=${FLAGS},mode=FAST_RUN,floatX=float32 ${NOSETESTS} ${ARGS}
echo "Number of elements in the compiledir:"
ls ${COMPILEDIR}|wc -l
echo "Executing nosetests with mode=vm,vm.lazy=True,floatX=float32"
THEANO_FLAGS=${FLAGS},mode=vm,vm.lazy=True,floatX=float32 ${NOSETESTS} ${ARGS}
echo "Executing nosetests with linker=vm,vm.lazy=True,floatX=float32"
THEANO_FLAGS=${FLAGS},linker=vm,vm.lazy=True,floatX=float32 ${NOSETESTS} ${ARGS}
echo "Number of elements in the compiledir:"
ls ${COMPILEDIR}|wc -l
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论