Paddle paddle.fluid.core.EnforceNotMet: Invoke operator clip error.

cwxwcias  于 2022-10-20  发布在  其他
关注(0)|答案(6)|浏览(999)

 1)PaddlePaddle版本:1.4.1
   4)系统环境:centos6.3,Python2.7

  • 训练信息

   1)单机单卡

  • 需求就是在embedding之前对输入做一下clip,防止数组越界,使用以下代码不会报错
feature = fluid.layers.data(name=attr_name, shape=[1], dtype='int64')
emb_feature = fluid.layers.embedding(input=feature,size=[conf['dimensions'], conf['emb_size']],
                param_attr=fluid.ParamAttr(name=group_name,initializer=fluid.initializer.Normal(scale=0.3)))
  • 如果增加一层clip,则会报错:
raw_feature = fluid.layers.data(name=attr_name, shape=[1], dtype='int64')
feature = fluid.layers.clip(x=raw_feature, min=0.0, max=10.0)
emb_feature = fluid.layers.embedding(input=feature,size=[10, 8],
                param_attr=fluid.ParamAttr(name=group_name,initializer=fluid.initializer.Normal(scale=0.3)))

报错信息:

Traceback (most recent call last):
  File "train.py", line 289, in <module>
    train()
  File "train.py", line 249, in train
    predictor, cost, test_program, label_offset)
  File "train.py", line 174, in train_loop
    fetch_list=[loss, auc_var, batch_auc_var],
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 565, in run
    use_program_cache=use_program_cache)
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 642, in _run
    exe.run(program.desc, scope, 0, True, True, fetch_var_name)
paddle.fluid.core.EnforceNotMet: Invoke operator clip error.
Python Callstacks: 
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1654, in append_op
    attrs=kwargs.get("attrs", None))
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
    return self.main_program.current_block().append_op(*args,**kwargs)
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/layers/nn.py", line 9495, in clip
    outputs={"Out": out})
  File "/home/users/fuyan01/zhiq/src/paddle_client/deepfm/deepfm.py", line 47, in feature_collector
    feature = fluid.layers.clip(x=raw_feature, min=0.0, max=1.0)
  File "/home/users/fuyan01/zhiq/src/paddle_client/deepfm/deepfm.py", line 112, in ctr_dnn_model
    feature['dependency'], feature)
  File "train.py", line 228, in train
    train_info = dnn_model.ctr_dnn_model(args.embedding_size, args.sparse_feature_dim)
  File "train.py", line 289, in <module>
    train()
C++ Callstacks: 
Input X(0)is not initialized at [/paddle/paddle/fluid/framework/operator.cc:1109]
PaddlePaddle Call Stacks: 
0       0x7f826e59f200p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1       0x7f826e59f579p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2       0x7f826f74af1fp paddle::framework::OperatorWithKernel::IndicateDataType(paddle::framework::ExecutionContext const&) const + 1343
3       0x7f826f74b10fp paddle::framework::OperatorWithKernel::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 47
4       0x7f826f74d4f3p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 243
5       0x7f826f74e194p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 292
6       0x7f826f74c36bp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 267
7       0x7f826e706b7ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 158
8       0x7f826e709b5fp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool) + 143
9       0x7f826e58ffaep
10      0x7f826e5cefcep
11      0x7f8291da53e4p PyEval_EvalFrameEx + 25956
12      0x7f8291da6130p PyEval_EvalCodeEx + 2240
13      0x7f8291da44a1p PyEval_EvalFrameEx + 22049
14      0x7f8291da6130p PyEval_EvalCodeEx + 2240
15      0x7f8291da44a1p PyEval_EvalFrameEx + 22049
16      0x7f8291da6130p PyEval_EvalCodeEx + 2240
17      0x7f8291da44a1p PyEval_EvalFrameEx + 22049
18      0x7f8291da6130p PyEval_EvalCodeEx + 2240
19      0x7f8291da44a1p PyEval_EvalFrameEx + 22049
20      0x7f8291da6130p PyEval_EvalCodeEx + 2240
21      0x7f8291da6242p PyEval_EvalCode + 50
22      0x7f8291dc062cp
23      0x7f8291dc0700p PyRun_FileExFlags + 144
24      0x7f8291dc1c0cp PyRun_SimpleFileExFlags + 220
25      0x7f8291dd34ccp Py_Main + 3164
26      0x7f8291010bd5p __libc_start_main + 245
27            0x400669p
  • 如果首先转换类型成float32,然后cast回到int64,仍然会报错:
raw_feature = fluid.layers.data(name=attr_name, shape=[1], dtype='int64')
feature = fluid.layers.clip(x=raw_feature, min=0.0, max=10.0)
emb_feature = fluid.layers.embedding(input=feature,size=[10, 8],
                param_attr=fluid.ParamAttr(name=group_name,initializer=fluid.initializer.Normal(scale=0.3)))
Traceback (most recent call last):
  File "train.py", line 289, in <module>
    train()
  File "train.py", line 249, in train
    predictor, cost, test_program, label_offset)
  File "train.py", line 174, in train_loop
    fetch_list=[loss, auc_var, batch_auc_var],
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 565, in run
    use_program_cache=use_program_cache)
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 642, in _run
    exe.run(program.desc, scope, 0, True, True, fetch_var_name)
paddle.fluid.core.EnforceNotMet: Invoke operator cast error.
Python Callstacks: 
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1654, in append_op
    attrs=kwargs.get("attrs", None))
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
    return self.main_program.current_block().append_op(*args,**kwargs)
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/layers/tensor.py", line 183, in cast
    'out_dtype': out.dtype})
  File "/home/users/fuyan01/zhiq/src/paddle_client/deepfm/deepfm.py", line 47, in feature_collector
    cast_feature = fluid.layers.cast(raw_feature, dtype='float32')
  File "/home/users/fuyan01/zhiq/src/paddle_client/deepfm/deepfm.py", line 114, in ctr_dnn_model
    feature['dependency'], feature)
  File "train.py", line 228, in train
    train_info = dnn_model.ctr_dnn_model(args.embedding_size, args.sparse_feature_dim)
  File "train.py", line 289, in <module>
    train()
C++ Callstacks: 
Input X(0)is not initialized at [/paddle/paddle/fluid/framework/operator.cc:1109]
PaddlePaddle Call Stacks: 
0       0x7f950e318200p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1       0x7f950e318579p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2       0x7f950f4c3f1fp paddle::framework::OperatorWithKernel::IndicateDataType(paddle::framework::ExecutionContext const&) const + 1343
3       0x7f950f4c410fp paddle::framework::OperatorWithKernel::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 47
4       0x7f950e57d9f8p paddle::operators::CastOp::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 40
5       0x7f950f4c64f3p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 243
6       0x7f950f4c7194p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 292
7       0x7f950f4c536bp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 267
8       0x7f950e47fb7ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 158
9       0x7f950e482b5fp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool) + 143
10      0x7f950e308faep
11      0x7f950e347fcep
12      0x7f9531b1e3e4p PyEval_EvalFrameEx + 25956
13      0x7f9531b1f130p PyEval_EvalCodeEx + 2240
14      0x7f9531b1d4a1p PyEval_EvalFrameEx + 22049
15      0x7f9531b1f130p PyEval_EvalCodeEx + 2240
16      0x7f9531b1d4a1p PyEval_EvalFrameEx + 22049
17      0x7f9531b1f130p PyEval_EvalCodeEx + 2240
18      0x7f9531b1d4a1p PyEval_EvalFrameEx + 22049
19      0x7f9531b1f130p PyEval_EvalCodeEx + 2240
20      0x7f9531b1d4a1p PyEval_EvalFrameEx + 22049
21      0x7f9531b1f130p PyEval_EvalCodeEx + 2240
22      0x7f9531b1f242p PyEval_EvalCode + 50
23      0x7f9531b3962cp
24      0x7f9531b39700p PyRun_FileExFlags + 144
25      0x7f9531b3ac0cp PyRun_SimpleFileExFlags + 220
26      0x7f9531b4c4ccp Py_Main + 3164
27      0x7f9530d89bd5p __libc_start_main + 245
28            0x400669p
5lhxktic

5lhxktic1#

显示是输入没有初始化,clip 的输入 raw_feature 是不是没有传值进去?

yzxexxkh

yzxexxkh2#

@Superjomn 传值进去了,第一段代码是没有问题的,如果没传值,第一段应该也会报错吧

at0kjp5o

at0kjp5o3#

我的意思是第二段代码,你的 raw_feature 是不是空

报错信息是 clip 的输入是空

4sup72z8

4sup72z84#

@Superjomn 感谢,确实是输入的问题,已解决,但是又遇到了另一个问题,clip操作似乎不支持int64类型的输入,然后我尝试先cast成float32,clip之后cast回int64,作为embedding的输入。代码如下:


# coding: utf-8

import paddle.fluid as fluid
import numpy as np

x_true=np.array([100,1,1,1,1,1,1,1,1,1]).reshape([10, 1]) 
y_true=np.array([0,1,1,1,1,1,1,1,1,1]).reshape([10, 1]) 

# 定义网络

x = fluid.layers.data(name="x",shape=[1],dtype='int64')
y = fluid.layers.data(name="y",shape=[1],dtype='int64')

cast_x = fluid.layers.cast(x, dtype='float32')
clip_x = fluid.layers.clip(cast_x, min=0.0, max=1.0)
new_x = fluid.layers.cast(clip_x, dtype='int64')
emb = fluid.layers.embedding(input=new_x, size=[2, 2]) 
cost = fluid.layers.cross_entropy(input=emb, label=y)
loss = fluid.layers.reduce_sum(cost)
optimizer = fluid.optimizer.Adam(learning_rate=0.01)
optimizer.minimize(loss)
cpu = fluid.CPUPlace()
exe = fluid.Executor(cpu)
exe.run(fluid.default_startup_program())
results = exe.run(fluid.default_main_program(), feed={"x": x_true, "y": y_true},
                                                fetch_list=[loss])
print ("{}".format(results[0][0]))

报错信息如下:

Traceback (most recent call last):
  File "test.py", line 23, in <module>
    fetch_list=[loss])
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 565, in run
    use_program_cache=use_program_cache)
  File "/home/users/fuyan01/.jumbo/lib/python2.7/site-packages/paddle/fluid/executor.py", line 642, in _run
    exe.run(program.desc, scope, 0, True, True, fetch_var_name)
paddle.fluid.core.EnforceNotMet: Input X(0)is not initialized at [/paddle/paddle/fluid/framework/operator.cc:1109]
PaddlePaddle Call Stacks: 
0       0x7fba3ab7e200p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 352
1       0x7fba3ab7e579p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2       0x7fba3bd29f1fp paddle::framework::OperatorWithKernel::IndicateDataType(paddle::framework::ExecutionContext const&) const + 1343
3       0x7fba3bd2a10fp paddle::framework::OperatorWithKernel::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 47
4       0x7fba3ade39f8p paddle::operators::CastOp::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 40
5       0x7fba3bd2c4f3p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&, paddle::framework::RuntimeContext*) const + 243
6       0x7fba3bd2d194p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 292
7       0x7fba3bd2b36bp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 267
8       0x7fba3ace5b7ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 158
9       0x7fba3ace8b5fp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector<std::string, std::allocator<std::string> > const&, bool) + 143
10      0x7fba3ab6efaep
11      0x7fba3abadfcep
12      0x7fba5d2e93e4p PyEval_EvalFrameEx + 25956
13      0x7fba5d2ea130p PyEval_EvalCodeEx + 2240
14      0x7fba5d2e84a1p PyEval_EvalFrameEx + 22049
15      0x7fba5d2ea130p PyEval_EvalCodeEx + 2240
16      0x7fba5d2e84a1p PyEval_EvalFrameEx + 22049
17      0x7fba5d2ea130p PyEval_EvalCodeEx + 2240
18      0x7fba5d2ea242p PyEval_EvalCode + 50
19      0x7fba5d30462cp
20      0x7fba5d304700p PyRun_FileExFlags + 144
21      0x7fba5d305c0cp PyRun_SimpleFileExFlags + 220
22      0x7fba5d3174ccp Py_Main + 3164
23        0x318ae1ecddp __libc_start_main + 253
24            0x400669p
izkcnapc

izkcnapc5#

clip目前的确不支持 int64 ,但是从您的报错来看应该是cast的时候没有数据输入,您可以检查一下,cast op输入是否有数据

l7wslrjt

l7wslrjt6#

@JiabinYang 这段代码如果不加optimizer,只是正向传播就不会报错。
完整的代码就在上面,cast的输入是x,feed={"x": x_true, "y": y_true},这样应该是有数据的吧

相关问题