int64类型的attr训练非预期
Created by: hutuxian
embedding op的padding_idx这个attr是支持int64类型的,但是当传入参数大于2^31-1时,会出错。下面是一个demo网络,可以通过打印出的main_program看到op中的padding_idx变成了非预期值。
import paddle.fluid as fluid
import numpy as np
import paddle.fluid.layers as layers
x = fluid.layers.data(name="x", shape=[1], dtype='int64', lod_level=1)
layers.Print(x)
emb = fluid.layers.embedding(input=x, size=[10**10+10,1], dtype='float32', padding_idx=10**10L)
layers.Print(emb)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
with open("main_program", "w") as fout:
fout.write(str(fluid.default_main_program()))
exe.run(fluid.default_startup_program())
x = np.array([10**10+1, 10**10+5]).reshape((-1,1)).astype("int64")
xx = fluid.LoDTensor()
xx.set(x, place)
xx.set_lod([[0,1,2]])
res = exe.run(
feed={'x':xx},
fetch_list=[],
return_numpy=False)