lod level was set to 0 after "lod_reset" layer
Created by: zlinker
here is the demo with paddle version 1.3.0:
# data
lod = list(range(5))
data_list = []
for x in lod:
data_list.extend([1] * x)
lod = list(np.cumsum(lod))
data_list = np.expand_dims(np.array(data_list, dtype="int32"), -1)
lod_tensor = fluid.LoDTensor()
lod_tensor.set(data_list, fluid.CPUPlace())
lod_tensor.set_lod([lod])
# network
data = fluid.layers.data(name="data",
shape=[-1, 1],
dtype="int32",
lod_level=1, )
print("data.lod_level:", data.lod_level)
data_reset= fluid.layers.lod_reset(x=data, target_lod=lod)
print("data_reset.lod_level:", data_reset.lod_level)
padding = fluid.layers.assign(input=np.array([0], "int32"))
data_padded, seq_len = fluid.layers.sequence_pad(x=data_reset, pad_value=padding, maxlen=5)
# executor
exe = fluid.Executor(place=fluid.CPUPlace())
exe.run(fluid.default_startup_program())
out = exe.run(feed={"data": lod_tensor},
fetch_list=[data_padded.name],
return_numpy=False)
it will throw error message as follow when the demo run:
paddle.fluid.core.EnforceNotMet: Enforce failed. Expected x_desc->GetLoDLevel() >= 1, but received x_desc->GetLoDLevel():0 < 1:1 at [D:\1.3\paddle\paddle\fluid\operators\sequence_ops\sequence_pad_op.cc:77]
comment the sequence_pad layer and print the output from data and data_reset layers as follow:
data.lod_level: 1
data_reset.lod_level: 0
1551416743 Tensor[data]
shape: [10,1,]
dtype: int
LoD: [[ 0,1,3,6,10, ]]
data: 1,1,1,1,1,1,1,1,1,1,
1551416743 Tensor[lod_reset_0.tmp_0]
shape: [10,1,]
dtype: int
LoD: [[ 0,1,3,6,10, ]]
data: 1,1,1,1,1,1,1,1,1,1,
it seems that only the lod_level of lod_reset layer output was set to 0 even target_lod was known(as [ 0,1,3,6,10, ]) in the network compiling stage, which raising the following EnforceNotMet error in sequence_pad layer, how to solve this problem? thx.