保存ernie embedding inference model报错
Created by: GeminiHu
报错代码:
fluid.io.save_inference_model(dirname='./infer_model', feeded_var_names=[pyreader.name], target_vars=[graph_vars["cls_embeddings"]], executor=exe)
报错信息: `----------- Configuration Arguments ----------- batch_size: 1 data_set: ./task_data/txt_match/test.tsv do_lower_case: True ernie_config_path: config/ernie_config.json init_pretraining_params: ./checkpoints/step_9000 max_seq_len: 510 output_dir: ./test use_cuda: True vocab_path: config/vocab.txt
attention_probs_dropout_prob: 0.1 hidden_act: relu hidden_dropout_prob: 0.1 hidden_size: 768 initializer_range: 0.02 max_position_embeddings: 513 num_attention_heads: 12 num_hidden_layers: 12 type_vocab_size: 2 vocab_size: 18000
Device count: 2 Total num examples: 1200 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! reader_double_buffer W0410 16:55:00.093608 35269 device_context.cc:263] Please NOTE: device: 1, CUDA Capability: 70, Driver API Version: 9.1, Runtime API Version: 9.0 W0410 16:55:00.093653 35269 device_context.cc:271] device: 1, cuDNN Version: 7.0. Load pretraining parameters from ./checkpoints/step_9000. ################################################## Traceback (most recent call last): File "ernir_encoder.py", line 195, in main(args) File "ernir_encoder.py", line 156, in main target_vars=[graph_vars["cls_embeddings"]], executor=exe) File "/home/huyichen/anaconda3/lib/python3.7/site-packages/paddle/fluid/io.py", line 954, in save_inference_model var, 1., name="save_infer_model/scale_{}".format(i)) File "/home/huyichen/anaconda3/lib/python3.7/site-packages/paddle/fluid/layers/nn.py", line 8857, in scale 'bias_after_scale': bias_after_scale File "/home/huyichen/anaconda3/lib/python3.7/site-packages/paddle/fluid/layer_helper.py", line 56, in append_op return self.main_program.current_block().append_op(args, kwargs) File "/home/huyichen/anaconda3/lib/python3.7/site-packages/paddle/fluid/framework.py", line 1317, in append_op attrs=kwargs.get("attrs", None)) File "/home/huyichen/anaconda3/lib/python3.7/site-packages/paddle/fluid/framework.py", line 726, in init self.desc.infer_var_type(self.block.desc) paddle.fluid.core.EnforceNotMet: at [/paddle/paddle/fluid/operators/detail/safe_ref.h:28] PaddlePaddle Call Stacks: 0 0x7f48ecfdd515p void paddle::platform::EnforceNotMet::Init<char const>(char const, char const, int) + 357 1 0x7f48ecfdd899p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137 2 0x7f48ed84babfp paddle::operators::ScaleOpVarTypeInference::operator()(paddle::framework::OpDesc const&, paddle::framework::BlockDesc*) const + 431 3 0x7f48ed84bba3p std::_Function_handler<void (paddle::framework::OpDesc const&, paddle::framework::BlockDesc*), paddle::framework::details::OpInfoFiller<paddle::operators::ScaleOpVarTypeInference, (paddle::framework::details::OpInfoFillType)3>::operator()(char const*, paddle::framework::OpInfo*) const::{lambda(paddle::framework::OpDesc const&, paddle::framework::BlockDesc*)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::OpDesc const&, paddle::framework::BlockDesc*) + 35 4 0x7f48ed0df292p paddle::framework::OpDesc::InferVarType(paddle::framework::BlockDesc*) const + 98 5 0x7f48ed053333p 6 0x7f48ed0088cep 7 0x556025e52004p _PyMethodDef_RawFastCallKeywords + 612 8 0x556025e52121p _PyCFunction_FastCallKeywords + 33 9 0x556025eae40ep _PyEval_EvalFrameDefault + 21294 10 0x556025deef19p _PyEval_EvalCodeWithName + 761 11 0x556025df01e8p _PyFunction_FastCallDict + 984 12 0x556025e06cb3p _PyObject_Call_Prepend + 99 13 0x556025e49c0ap 14 0x556025e522d8p _PyObject_FastCallKeywords + 296 15 0x556025eae98ap _PyEval_EvalFrameDefault + 22698 16 0x556025deef19p _PyEval_EvalCodeWithName + 761 17 0x556025df01e8p _PyFunction_FastCallDict + 984 18 0x556025e06cb3p _PyObject_Call_Prepend + 99 19 0x556025dfb7dep PyObject_Call + 110 20 0x556025eaaf1ep _PyEval_EvalFrameDefault + 7742 21 0x556025deef19p _PyEval_EvalCodeWithName + 761 22 0x556025e51337p _PyFunction_FastCallKeywords + 903 23 0x556025eaa5d5p _PyEval_EvalFrameDefault + 5365 24 0x556025deef19p _PyEval_EvalCodeWithName + 761 25 0x556025e51337p _PyFunction_FastCallKeywords + 903 26 0x556025eaa5d5p _PyEval_EvalFrameDefault + 5365 27 0x556025deef19p _PyEval_EvalCodeWithName + 761 28 0x556025e51337p _PyFunction_FastCallKeywords + 903 29 0x556025eaa5d5p _PyEval_EvalFrameDefault + 5365 30 0x556025e510abp _PyFunction_FastCallKeywords + 251 31 0x556025ea97d6p _PyEval_EvalFrameDefault + 1782 32 0x556025deef19p _PyEval_EvalCodeWithName + 761 33 0x556025defdd4p PyEval_EvalCodeEx + 68 34 0x556025defdfcp PyEval_EvalCode + 28 35 0x556025f089e4p 36 0x556025f12bd1p PyRun_FileExFlags + 161 37 0x556025f12dc3p PyRun_SimpleFileExFlags + 451 38 0x556025f13edbp 39 0x556025f13fbcp _Py_UnixMain + 60 40 0x7f4918882830p __libc_start_main + 240 41 0x556025eb8ed2p`
尝试方案:
参照BERT predict_classifier.py文件找到save_inference_model的使用, 其中feed_target_names参数来自于该行代码:
predict_pyreader, probs, feed_target_names = create_model(...)
但是model.classifier中create_model函数的返回值是pyreader, loss, probs, accuracy, num_seqs
似乎这里使用的create_model不是predict_classifier.py第29行导入的函数?
希望帮我解决save ernie embedding inference model的问题,如果其他地方我有什么理解错误的麻烦指正!谢谢!