sequence_pad 在inferShape时出错
sequence_pad op 在**编译(inferShape)**的时候,会强制要求lod level >= 1。 但是在编译的过程中很多op会把lod level = 1的input变成lod level = 0。 到了sequence_pad那一步就会出错。
训练的时候lod level是正常的。
这么问题要怎么解决?搜了一下inferShape的时候强制要求lod level >= 1的也就只有sequence_pad,是不是可以把这个检查去掉?
Traceback (most recent call last):
input_padded, _ = layers.sequence_pad(input, pad_value, maxlen=maxlen) # (batch, max_seq_len, 1), (batch, 1)
File "/home/ol/anaconda2/envs/paddle-dev/lib/python2.7/site-packages/paddle/fluid/layers/nn.py", line 3039, in sequence_pad
attrs={'padded_length': maxlen})
File "/home/ol/anaconda2/envs/paddle-dev/lib/python2.7/site-packages/paddle/fluid/layer_helper.py", line 50, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "/home/ol/anaconda2/envs/paddle-dev/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1207, in append_op
op = Operator(block=self, desc=op_desc, *args, **kwargs)
File "/home/ol/anaconda2/envs/paddle-dev/lib/python2.7/site-packages/paddle/fluid/framework.py", line 656, in __init__
self.desc.infer_shape(self.block.desc)
paddle.fluid.core.EnforceNotMet: Enforce failed. Expected x_desc->GetLoDLevel() >= 1, but received x_desc->GetLoDLevel():0 < 1:1.
at [/paddle/paddle/fluid/operators/sequence_pad_op.cc:77]
PaddlePaddle Call Stacks:
0 0x7fde63d5bd42p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 482
1 0x7fde64d73363p paddle::operators::SequencePadOp::InferShape(paddle::framework::InferShapeContext*) const + 6019
2 0x7fde63e07bccp paddle::framework::OpDesc::InferShape(paddle::framework::BlockDesc const&) const + 924
3 0x7fde63db7299p void pybind11::cpp_function::initialize<pybind11::cpp_function::initialize<void, paddle::framework::OpDesc, paddle::framework::BlockDesc const&, pybind11::name, pybind11::is_method, pybind11::sibling>(void (paddle::framework::OpDesc::*)(paddle::framework::BlockDesc const&) const, pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::{lambda(paddle::framework::OpDesc const*, paddle::framework::BlockDesc const&)#1}, void, paddle::framework::OpDesc const*, paddle::framework::BlockDesc const&, pybind11::name, pybind11::is_method, pybind11::sibling>(pybind11::cpp_function::initialize<void, paddle::framework::OpDesc, paddle::framework::BlockDesc const&, pybind11::name, pybind11::is_method, pybind11::sibling>(void (paddle::framework::OpDesc::*)(paddle::framework::BlockDesc const&) const, pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::{lambda(paddle::framework::OpDesc const*, paddle::framework::BlockDesc const&)#1}&&, void (*)(paddle::framework::OpDesc const*, paddle::framework::BlockDesc const&), pybind11::name const&, pybind11::is_method const&, pybind11::sibling const&)::{lambda(pybind11::detail::function_call&)#3}::_FUN(pybind11::detail::function_call) + 201
sequence_pad op 在**编译(inferShape)**的时候,会强制要求lod level >= 1。 但是在编译的过程中很多op会把lod level = 1的input变成lod level = 0。 到了sequence_pad那一步就会出错。
InferShape是为了提前报错,去掉检查只是隐藏问题了。
训练的时候lod level是正常的。
lod为什么会和训练和预测有关? 你的数据格式是一样的吗?
sequence_pad这个情况碰到两次。
- 一次是dynamic rnn在static_input的时候会把lod_level=1的输出成lod_level=0。
- 另一次是py_reader创建input时,虽然设置了lod_levels=[1, ...],但是输出的lod_level依旧是0。
以上都是inferShape时候的情况。
感谢反馈,我排查一下
py_reader上有没有最小复现代码?
py_reader的lod_level问题是一个bug,感谢反馈,这个bug已经在develop分支修复,且会在后续的1.2版本release。
谢谢!
您好,鉴于此问题已经解决,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持
您好,py_reader的bug确实解决了,想问问
dynamic rnn在static_input的时候会把lod_level=1的输出成lod_level=0
这个bug好像还在啊?
提供下demo:
from paddle import fluid
x = fluid.layers.data(name='x', shape=[-1, 1], dtype='int64', lod_level=1)
print (x)
drnn = fluid.layers.DynamicRNN()
with drnn.block():
_ = drnn.step_input(x)
static_x = drnn.static_input(x)
print (static_x)
得到的output如下:

看过了,是shrink_rnn_memory op导致的, https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/operators/shrink_rnn_memory_op.cc#L103-L108
我对这块不熟悉,为什么输出是和输入一样的lod level? 看op的注释里显示,这个是故意的,原因是while op会处理这个。我找作者确认一下这样做的原因是什么。
dynamic rnn会丢掉lod信息
请问这个issue目前有进展么?
@yma-admin dynamic rnn 有已知的bug,暂时不建议用,这个bug和编译时的lod传导问题会在下一个版本修复 @LihangLiu sequence pad要求lod level=1是合理的,除了dynamic rnn外,其它大部分op都能在编译时正确传导lod,作为sequence pad的前驱应该没有问题。
@kuke 下一个版本版本号多少呢?
@LihangLiu 下一个版本是 1.7
PR https://github.com/PaddlePaddle/Paddle/pull/19144 可解决此issue中的问题。已经更新到develop。
Since you haven't replied for more than a year, we have closed this issue/pr. If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up. 由于您超过一年未回复,我们将关闭这个issue/pr。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。