|
|
|
@ -1586,8 +1586,7 @@ class DynamicRNN(object):
|
|
|
|
|
self.lod_rank_table = None
|
|
|
|
|
self.max_seq_len = None
|
|
|
|
|
self.step_idx = None
|
|
|
|
|
self.zero_idx = fill_constant(
|
|
|
|
|
shape=[1], value=0, dtype='int64', force_cpu=True)
|
|
|
|
|
self.zero_idx = None
|
|
|
|
|
self.mem_dict = dict()
|
|
|
|
|
self.output_array = []
|
|
|
|
|
self.outputs = []
|
|
|
|
@ -1792,6 +1791,7 @@ class DynamicRNN(object):
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
self._assert_in_rnn_block_('memory')
|
|
|
|
|
self._init_zero_idx_()
|
|
|
|
|
if init is not None:
|
|
|
|
|
if not isinstance(init, Variable):
|
|
|
|
|
raise TypeError(
|
|
|
|
@ -1905,6 +1905,22 @@ class DynamicRNN(object):
|
|
|
|
|
array_write(x=each, i=self.step_idx, array=outside_array)
|
|
|
|
|
self.output_array.append(outside_array)
|
|
|
|
|
|
|
|
|
|
def _init_zero_idx_(self):
|
|
|
|
|
if self.zero_idx is None:
|
|
|
|
|
parent_block = self._parent_block_()
|
|
|
|
|
self.zero_idx = parent_block.create_var(
|
|
|
|
|
name=unique_name.generate('zero_idx'), dtype='int64')
|
|
|
|
|
parent_block.append_op(
|
|
|
|
|
type='fill_constant',
|
|
|
|
|
inputs={},
|
|
|
|
|
outputs={'Out': [self.zero_idx]},
|
|
|
|
|
attrs={
|
|
|
|
|
'shape': [1],
|
|
|
|
|
'dtype': self.zero_idx.dtype,
|
|
|
|
|
'value': float(0),
|
|
|
|
|
'force_cpu': True
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
def _parent_block_(self):
|
|
|
|
|
prog = self.helper.main_program
|
|
|
|
|
parent_idx = prog.current_block().parent_idx
|
|
|
|
|