提交 0ce29584 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Remove the part about pushing out dot, it's done elsewhere and this

code doesn't work.
上级 d3d3a54c
...@@ -700,91 +700,7 @@ class PushOutScanOutput(gof.Optimizer): ...@@ -700,91 +700,7 @@ class PushOutScanOutput(gof.Optimizer):
clients=clients) clients=clients)
for nd in local_fgraph_topo: for nd in local_fgraph_topo:
if (isinstance(nd.op, theano.tensor.Dot) and if (isinstance(nd.op, theano.tensor.elemwise.Elemwise) and
nd.out in args.inner_out_nit_sot):
"""
The following optimization involves pushing out, after the
scan, a Dot whose output is nitsot (not feed back to the inner
graph) and where one input is one of scan's input with ndim=2
and the other is an intermediate variable in the Scan inner
graph with ndim=1.
The Dot product is pushed out of the scan and its inputs are
now the original matrix and a new matrix obtained by
concatenating the vectors into a matrix.
"""
# Ensure that the output of the Dot is used in the outer
# graph to avoid apply the optimization needlessly
dot_out_nitsot_idx = args.inner_out_nit_sot.index(nd.out)
outer_dot_output = args.outer_out_nit_sot[dot_out_nitsot_idx]
if len(outer_dot_output.clients) == 0:
continue
"""
Validate that one of the inputs is a matrix AND a
non-sequence input to scan and that the other input is a
vector and either an sequence input to scan or the result
of computation in the inner function of scan.
"""
valid_inputs = False
idx_matrix_input = -1
idx_vector_input = -1
if (nd.inputs[0].ndim == 2 and
(nd.inputs[0] in args.inner_in_non_seqs or
isinstance(nd.inputs[0], tensor.Constant)) and
nd.inputs[1].ndim == 1 and
(nd.inputs[1] in args.inner_in_seqs or
nd.inputs[1] not in args.inner_inputs)):
valid_inputs = True
idx_matrix_input = 0
idx_vector_input = 1
elif (nd.inputs[1].ndim == 2 and
(nd.inputs[1] in args.inner_in_non_seqs or
isinstance(nd.inputs[1], tensor.Constant)) and
nd.inputs[0].ndim == 1 and
(nd.inputs[0] in args.inner_in_seqs or
nd.inputs[0] not in args.inner_inputs)):
valid_inputs = True
idx_matrix_input = 1
idx_vector_input = 0
if valid_inputs:
# The optimization can be applied on the current Dot
# Move out of scan the two inputs to the Dot
(outer_vars,
new_scan_node,
new_scan_args) = self.push_out_inner_vars(fgraph,
nd.inputs,
node, args)
outer_vector_input = outer_vars[idx_vector_input]
outer_matrix_input = outer_vars[idx_matrix_input]
# Perform the Dot outside of scan
if idx_matrix_input == 0:
outer_dot_inputs = [outer_vector_input,
outer_matrix_input.transpose()]
outer_dot_output = theano.tensor.dot(*outer_dot_inputs)
else: # idx_matrix_input == 1
outer_dot_inputs = [outer_vector_input,
outer_matrix_input]
outer_dot_output = theano.tensor.dot(*outer_dot_inputs)
# Modify the outer graph to add the outer Dot
fgraph.replace_all(
[(new_scan_args.outer_out_nit_sot[dot_out_nitsot_idx],
outer_dot_output)],
reason="scanOp_pushout_output")
break
elif (isinstance(nd.op, theano.tensor.elemwise.Elemwise) and
nd.op.scalar_op == scalar.add and nd.op.scalar_op == scalar.add and
nd.out in args.inner_out_sit_sot and nd.out in args.inner_out_sit_sot and
self.inner_sitsot_only_last_step_used(nd.out, args)): self.inner_sitsot_only_last_step_used(nd.out, args)):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论