提交 af321154 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #2539 from carriepl/activate_scan_no_output_from_inplace_optimization

Activate add_no_output_from_inplace optimization by default in scan's inner function
...@@ -118,6 +118,14 @@ class Scan(PureOp): ...@@ -118,6 +118,14 @@ class Scan(PureOp):
optimizer=mode_instance.provided_optimizer, optimizer=mode_instance.provided_optimizer,
linker=mode_instance.linker.clone(allow_gc=self.allow_gc)) linker=mode_instance.linker.clone(allow_gc=self.allow_gc))
# Now that scan has its mode instance, we activate optimization
# add_no_output_from_inplace in this mode instance. This will prevent
# Scan from producing outputs by means of inplace operations and
# therefore allow it to pre-allocate memory storage for the outputs,
# avoiding needless copies.
self.mode_instance = self.mode_instance.including(
"add_no_output_from_inplace")
if not hasattr(self, 'name') or self.name is None: if not hasattr(self, 'name') or self.name is None:
self.name = 'scan_fn' self.name = 'scan_fn'
# to have a fair __eq__ comparison later on, we update the info with # to have a fair __eq__ comparison later on, we update the info with
......
...@@ -1928,7 +1928,6 @@ class T_Scan(unittest.TestCase): ...@@ -1928,7 +1928,6 @@ class T_Scan(unittest.TestCase):
s_v = s_v[:-1] s_v = s_v[:-1]
for i in xrange(100): for i in xrange(100):
cost = learn_rnn_fn(s_v, t_v) cost = learn_rnn_fn(s_v, t_v)
print i, cost
pred = eval_rnn_fn(s_v) pred = eval_rnn_fn(s_v)
assert cost < 0.02 assert cost < 0.02
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论