fluid在预测阶段报paddle.fluid.core.EnforceNotMet: Enforce failed
- 版本、环境信息: 1)PaddlePaddle版本:fluid 1.3 gpu hi 我在使用fluid gpu版本做预测时,遇到如下错误。详细见:http://yq01-sys-hic-k40-box-0002.yq01.baidu.com:8388/v1/slurmjobs/24112/workspace ->log/bert_predict.log
Traceback (most recent call last):
File "predict_classifier.py", line 154, in <module>
main(args)
File "predict_classifier.py", line 127, in main
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])
File "/home/slurm/job/tmp/job-24112/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/parallel_executor.py", line 303, in run
self.executor.run(fetch_list, fetch_var_name)
paddle.fluid.core.EnforceNotMet: Enforce failed. Expected framework::product(new_dim) / new_dim[0] == framework::product(t->dims()) / t->dims()[0], but received framework::product(new_dim) / new_dim[0]:69 != framework::product(t->dims()) / t->dims()[0]:63.
at [/paddle/paddle/fluid/framework/lod_tensor.cc:395]
PaddlePaddle Call Stacks:
0 0x7f24994a6e2dp void paddle::platform::EnforceNotMet::Init<std::string>(std::string, char const*, int) + 365
1 0x7f24994a7177p paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int) + 87
2 0x7f249abdb12ep paddle::framework::LoDTensor::MergeLoDTensor(std::vector<paddle::framework::LoDTensor const*, std::allocator<paddle::framework::LoDTensor const*> > 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_>) + 1886
3 0x7f249acb8e74p paddle::framework::details::ParallelSSAGraphExecutor::Run(std::vector<std::string, std::allocator<std::string> > const&) + 3316
4 0x7f249acb678ap paddle::framework::details::ScopeBufferedSSAGraphExecutor::Run(std::vector<std::string, std::allocator<std::string> > const&) + 394
5 0x7f24995e4c92p paddle::framework::ParallelExecutor::Run(std::vector<std::string, std::allocator<std::string> > const&, std::string const&) + 562
6 0x7f249949728ep
7 0x7f24994d21fep
8 0x7f24fb716bb8p PyEval_EvalFrameEx + 25016
9 0x7f24fb71a0bdp PyEval_EvalCodeEx + 2061
10 0x7f24fb717345p PyEval_EvalFrameEx + 26949
11 0x7f24fb71a0bdp PyEval_EvalCodeEx + 2061
12 0x7f24fb717345p PyEval_EvalFrameEx + 26949
13 0x7f24fb71a0bdp PyEval_EvalCodeEx + 2061
14 0x7f24fb71a1f2p PyEval_EvalCode + 50
15 0x7f24fb742f42p PyRun_FileExFlags + 146
16 0x7f24fb7442d9p PyRun_SimpleFileExFlags + 217
17 0x7f24fb75a00dp Py_Main + 3149
18 0x7f24fa957bd5p __libc_start_main + 245
19 0x4007a1p
报错代码:results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])这一行
predict_exe = fluid.ParallelExecutor(
use_cuda=args.use_cuda, main_program=predict_prog)
predict_pyreader.decorate_tensor_provider(
processor.data_generator(
batch_size=args.batch_size, phase='test', epoch=1, shuffle=False))
predict_pyreader.start()
all_results = []
time_begin = time.time()
while True:
try:
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])
all_results.extend(zip(results[2], results[0], results[1]))
except fluid.core.EOFException:
predict_pyreader.reset()
break
time_end = time.time()
错误原因:我在fetch_list里加入了src_ids.name后,出现下图错误,去除后则正常。其中src_ids是模型的输入特征之一,格式如下:
pyreader = fluid.layers.py_reader(
capacity=50,
shapes=[[-1, args.max_seq_len, 1], [-1, args.max_seq_len, 1],
[-1, args.max_seq_len, 1], [-1, args.max_seq_len, 1], [-1, 1]],
dtypes=['int64', 'int64', 'int64', 'float32', 'int64'],
lod_levels=[0, 0, 0, 0, 0],
name=pyreader_name,
use_double_buffer=True)
(src_ids, pos_ids, sent_ids, input_mask,
labels) = fluid.layers.read_file(pyreader)
bert = BertModel(
src_ids=src_ids,
position_ids=pos_ids,
sentence_ids=sent_ids,
input_mask=input_mask,
config=bert_config,
use_fp16=args.use_fp16)
cls_feats = bert.get_pooled_output()
cls_feats = fluid.layers.dropout(
x=cls_feats,
dropout_prob=0.1,
dropout_implementation="upscale_in_train")
logits = fluid.layers.fc(
input=cls_feats,
size=num_labels,
param_attr=fluid.ParamAttr(
name="cls_out_w",
initializer=fluid.initializer.TruncatedNormal(scale=0.02)),
bias_attr=fluid.ParamAttr(
name="cls_out_b", initializer=fluid.initializer.Constant(0.)))
if is_prediction:
probs = fluid.layers.softmax(logits)
feed_targets_name = [
src_ids.name, pos_ids.name, sent_ids.name, input_mask.name
]
https://github.com/PaddlePaddle/LARK/blob/1b54d1444bfde000efa3e71ddf04396c89fd7186/BERT/predict_classifier.py#L113
把ParallelExecutor换成Executor可以解决这个问题
https://github.com/PaddlePaddle/LARK/blob/1b54d1444bfde000efa3e71ddf04396c89fd7186/BERT/predict_classifier.py#L113
把ParallelExecutor换成Executor可以解决这个问题 替换后仍然报错,详见: http://yq01-sys-hic-p40-0085.yq01.baidu.com:8388/v1/slurmjobs/98679/workspace
报错信息在哪儿? 可以截下图
报错信息在哪儿? 可以截下图
报错信息见log/bert_predict.log 代码见BERT/predict_classifier.py 报错信息同前:
Traceback (most recent call last):
File "predict_classifier.py", line 159, in <module>
main(args)
File "predict_classifier.py", line 129, in main
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/executor.py", line 525, in run
use_program_cache=use_program_cache)
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/executor.py", line 591, in _run
exe.run(program.desc, scope, 0, True, True)
paddle.fluid.core.EnforceNotMet: Invoke operator fetch error.
Python Callstacks:
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1317, in append_op
attrs=kwargs.get("attrs", None))
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/executor.py", line 361, in _add_feed_fetch_ops
attrs={'col': i})
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/executor.py", line 588, in _run
fetch_var_name=fetch_var_name)
File "/home/slurm/job/tmp/job-98679/bert-python-gpu/lib/python2.7/site-packages/paddle/fluid/executor.py", line 525, in run
use_program_cache=use_program_cache)
File "predict_classifier.py", line 129, in main
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])
File "predict_classifier.py", line 159, in <module>
main(args)
C++ Callstacks:
Cannot find fetch variable in scope, fetch_var_name is softmax_12.tmp_0 at [/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:37]
PaddlePaddle Call Stacks:
0 0x7f4cb68568f5p void paddle::platform::EnforceNotMet::Init<char const*>(char const*, char const*, int) + 357
1 0x7f4cb6856c79p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2 0x7f4cb7dce4e8p paddle::operators::FetchOp::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 + 1752
3 0x7f4cb8265425p 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&) + 341
4 0x7f4cb697633ap paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 218
5 0x7f4cb6978335p paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool) + 261
6 0x7f4cb683b08bp
7 0x7f4cb68821fep
8 0x7f4d18ac6bb8p PyEval_EvalFrameEx + 25016
9 0x7f4d18aca0bdp PyEval_EvalCodeEx + 2061
10 0x7f4d18ac7345p PyEval_EvalFrameEx + 26949
11 0x7f4d18aca0bdp PyEval_EvalCodeEx + 2061
12 0x7f4d18ac7345p PyEval_EvalFrameEx + 26949
13 0x7f4d18aca0bdp PyEval_EvalCodeEx + 2061
14 0x7f4d18ac7345p PyEval_EvalFrameEx + 26949
15 0x7f4d18aca0bdp PyEval_EvalCodeEx + 2061
16 0x7f4d18aca1f2p PyEval_EvalCode + 50
17 0x7f4d18af2f42p PyRun_FileExFlags + 146
18 0x7f4d18af42d9p PyRun_SimpleFileExFlags + 217
19 0x7f4d18b0a00dp Py_Main + 3149
20 0x7f4d17d07bd5p __libc_start_main + 245
21 0x4007a1p
@kuke 这个再帮看下吧
改成这样试下
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name], program=predict_prog)
改成这样试下
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name], program=predict_prog)
上述写法的效果是否和下面的代码一致?如果是的话,那有问题:我在不输出“src_ids.name”时,使用parallel_executor进行预测,大约要花10分钟。而改成下面的写法,等了近2小时都没有动静。。
predict_exe.run(predict_prog)
results = predict_exe.run(fetch_list=[probs.name, labels.name, src_ids.name])
补充下:src_ids的维度是512,query的id信息
后面这种跑法是错误的
https://github.com/PaddlePaddle/Paddle/blob/1c6d0646276dc9e694c8dab0a3d5284670e358e7/python/paddle/fluid/executor.py#L539
可以参考executor的文档
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。 若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。