fluid.layer.rnn 不能指定paramAttr
Created by: Meiyim
测试paddle版本:1.7.1 gpu 测试代码:
import paddle
from paddle import fluid
from paddle.fluid import layers
print(paddle.__version__)
def gru(input, hidden_size, name, param_initializer):
encoder_fwd_cell = layers.GRUCell(hidden_size=hidden_size//2, param_attr=fluid.ParamAttr(name=name+'_fwd_gru.w_0', initializer=param_initializer), bias_attr=name+'_fwd_gru.b_0')
encoder_bwd_cell = layers.GRUCell(hidden_size=hidden_size//2, param_attr=fluid.ParamAttr(name=name+'_bwd_gru.w_0', initializer=param_initializer), bias_attr=name+'_bwd_gru.b_0')
fwd_output, fwd_state = layers.rnn(
cell=encoder_fwd_cell,
inputs=input,
time_major=False,
is_reverse=False)
bwd_output, bwd_state = layers.rnn(
cell=encoder_bwd_cell,
inputs=input,
time_major=False,
is_reverse=True)
output = layers.concat([fwd_output, bwd_output], -1)
return output
emb = fluid.data(name='a', shape=[10,100,768], dtype='float32')
gru(emb, 768, 'test', None)
错误输出:
1.7.1
Traceback (most recent call last):
File "test.py", line 49, in <module>
gru(emb, 768, 'test', None)
File "test.py", line 36, in gru
is_reverse=False)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/layers/rnn.py", line 486, in rnn
outputs, new_states = cell.call(inputs, copy_states, **kwargs)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/layers/rnn.py", line 276, in call
new_hidden = self.gru_unit(inputs, states)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/dygraph/layers.py", line 298, in __call__
self._build_once(*inputs, **kwargs)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/contrib/layers/rnn_impl.py", line 109, in _build_once
dtype=self._dtype)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/dygraph/layers.py", line 113, in create_parameter
default_initializer)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/layer_helper_base.py", line 353, in create_parameter
**attr._to_kwargs(with_initializer=True))
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/framework.py", line 2448, in create_parameter
param = Parameter(global_block, *args, **kwargs)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/framework.py", line 4640, in __init__
**kwargs)
File "/home/work/chenxuyi/app_paddle_1.7/lib/python3.6/site-packages/paddle/fluid/framework.py", line 895, in __init__
"matched.".format(self.name, old_shape, shape))
ValueError: Variable test_fwd_gru.w_0 has been created before. the previous shape is (1152, 768); the new shape is (1152, 384). They are not matched.