ERNIE 模型 sequence_unpad op参数shape检查出错
Created by: wangjiawei04
Serving端报错
----------------------
Error Message Summary:
----------------------
Error: The shape of Input(Length) should be [batch_size].
[Hint: Expected len_dims.size() == 1, but received len_dims.size():2 != 1:1.] at (/paddle/paddle/fluid/operators/sequence_ops/sequence_unpad_op.cc:41)
[operator < sequence_unpad > error]
报错的原因是 paddle.fluid.layers. sequence_unpad ( x, length, name=None )
当中的length字段不能为两个维度,预期是[1], 实际上是[1 ,1]
此api详情 https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/sequence_unpad_cn.html#sequence-unpad
那么为什么是[1,1]呢?
首先要介绍client端的代码
placeholder_test = [1] * 100
eval_placeholder_0 = placeholder_test
eval_placeholder_1 = placeholder_test
eval_placeholder_2 = placeholder_test
eval_placeholder_3 = placeholder_test
eval_placeholder_4 = placeholder_test
eval_placeholder_5 = placeholder_test
eval_placeholder_6 = placeholder_test
len_test = [100]
eval_placeholder_7 = len_test
eval_placeholder_8 = len_test
eval_placeholder_9 = len_test
eval_placeholder_10 = len_test
eval_placeholder_11 = len_test
eval_placeholder_12 = len_test
eval_placeholder_13 = len_test
feed_dict = {"eval_placeholder_0":eval_placeholder_0, "eval_placeholder_1":eval_placeholder_1, "eval_placeholder_2":eval_placeholder_2,
"eval_placeholder_3":eval_placeholder_3, "eval_placeholder_4":eval_placeholder_4, "eval_placeholder_5":eval_placeholder_5, "eval_placeholder_6":eval_placeholder_6,
"eval_placeholder_7":eval_placeholder_7, "eval_placeholder_8":eval_placeholder_8, "eval_placeholder_9":eval_placeholder_9,
"eval_placeholder_10":eval_placeholder_10, "eval_placeholder_11":eval_placeholder_11, "eval_placeholder_12":eval_placeholder_12, "eval_placeholder_13":eval_placeholder_13}
其中eval_placeholder_7
到13
就是sequence_unpad的length参数。可以看到这个参数在这里传入的都是[100]
。在这里eval_placeholder_7
到13
shape =1,非lod tensor。
但是在 https://github.com/PaddlePaddle/Serving/blob/develop/core/general-server/op/general_reader_op.cpp#L139
这个位置,general reader op有这样一个操作
lod_tensor.shape.push_back(batch_size);
这一步多append了一个 1,导致和sequence_unpad的length参数输入所需的shape不一样
再来看下模型是怎么组网的
# 可以认为input=text_ids_a 就是 eval_placeholder_0
embed1 = L.embedding(
input=text_ids_a,
size=[self.config.vocab_size, self.config.emb_size],
dtype=self._emb_dtype,
param_attr=F.ParamAttr(
name=self._word_emb_name, initializer=self._param_initializer),
is_sparse=False)
# 可以认为length = len_a 就是 eval_placeholder_7
emb1 = L.sequence_unpad(embed1, length=len_a)
这是出错部分的网络结构,可以发现eval_placeholder_7
被用来做为api的传参,前面不能加batch_size的维度
应该如何解决?