-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在aistudio平台上使用paddlepaddle python环境训练,通过paddle的go api进行推理, 报错详细间日志。 #58652
Comments
把 paddle_inference_c C预测库更新到最新,同样有此错误,是不是哪里用法不对,有没有大神指导下 @jzhang533 @wanglun @lileding |
可以提供一下你的复现流程和代码吗?流程涉及的内容比较多,光看log不好定位。 |
2)推理go代码主要流程如下:
} func load_content(content string, tk *tokenizer.Tokenizer) []float32 {
} func initLableMap() {
} var inTensor *pd.Tensor func main() {
} func predict(content string) int32 {
} func numElements(shape []int32) int32 { func maxValue(vals []float32) (max_index int32) { 疑问:就是go api中的reshape函数这里我填写的是[1,512],(报错应该跟这个没有关系), 因为我训练比较简单,就是通过输入content字符串截断512字节,label就是多个分类,比如1,2,3,4等。然后官方给的go推理demo是图像相关的,按照官方给的图像是没问题,paddleNlp的模型就有问题,nlp底层我感觉还是走的transfomer那一套。不知道大神是否用过paddlenlp的go推理。 |
看描述,训练出的模型应该没问题,麻烦你把go的推理代码整理一下新建个repo,并传一下你的参数文件,最好是我可以直接跑的单独项目。 我没跑过paddlenlp的go推理,但我得找到这个bug的具体的原因,才能找到相应的大佬去解决。 |
@6clc 链接:https://pan.baidu.com/s/1fGZiXEBW9lTesqGRGHynKg?pwd=i9tg |
感觉还是paddle对nlp模型(如bert chinese)的不支持,我go transfomer 参考这个大佬 https://github.com/sugarme/transformer |
这边可以先尝试用C++ API进行推理么 |
|
主要是预处理这块熟不熟悉 |
bug描述 Describe the Bug
1)训练过程:paddlepaddle 的版本2.5最新版本,paddleNLP 2.6版本,在AIstudio平台参考paddleNLP中的text_classification的训练,使用的模型是bert-base-chinese,训练完成后,保存了模型文件如下:
2)推理过程:使用go api 加载 model.pdiparams和 model.pdmodel文件,在cpu环境下进行推理,编译成二进制后,运行后报如下错误:
terminate called after throwing an instance of 'phi::enforce::EnforceNotMet'
what():
Compile Traceback (most recent call last):
File "/home/aistudio/PaddleNLP/applications/text_classification/multi_class/train.py", line 231, in
main()
File "/home/aistudio/PaddleNLP/applications/text_classification/multi_class/train.py", line 208, in main
export_model(model=trainer.model, input_spec=input_spec, path=model_args.export_model_dir)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddlenlp/transformers/export.py", line 59, in export_model
paddle.jit.save(model, save_path)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl
return wrapped_func(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/api.py", line 752, in wrapper
func(layer, path, input_spec, **configs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl
return wrapped_func(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/dygraph/base.py", line 75, in impl
return func(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/api.py", line 1043, in save
static_func.concrete_program_specify_input_spec(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 709, in concrete_program_specify_input_spec
concrete_program, _ = self.get_concrete_program(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 589, in get_concrete_program
concrete_program, partial_program_layer = self._program_cache[
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1249, in getitem
self._caches[item_id] = self._build_once(item)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1193, in _build_once
concrete_program = ConcreteProgram.from_func_spec(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/decorator.py", line 232, in fun
return caller(func, *(extras + args), **kw)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in impl
return wrapped_func(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/dygraph/base.py", line 75, in impl
return func(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 1063, in from_func_spec
outputs = static_func(*inputs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddlenlp/transformers/bert/modeling.py", line 706, in forward
outputs = self.bert(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1256, in call
return self._dygraph_call_func(*inputs, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/nn/layer/layers.py", line 1235, in _dygraph_call_func
outputs = self.forward(*inputs, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddlenlp/transformers/bert/modeling.py", line 425, in forward
if attention_mask is None:
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/convert_operators.py", line 352, in convert_ifelse
out = _run_py_ifelse(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/jit/dy2static/convert_operators.py", line 429, in _run_py_ifelse
py_outs = true_fn() if pred else false_fn()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddlenlp/transformers/bert/modeling.py", line 426, in forward
attention_mask = paddle.unsqueeze(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/layers/math_op_patch.py", line 445, in impl
current_block(self).append_op(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/framework.py", line 4013, in append_op
op = Operator(
File "/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/paddle/fluid/framework.py", line 2781, in init
for frame in traceback.extract_stack():
C++ Traceback (most recent call last):
0 PD_PredictorRun
1 paddle::AnalysisPredictor::ZeroCopyRun()
2 paddle::framework::NaiveExecutor::Run()
3 paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, phi::Place const&)
4 paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, phi::Place const&) const
5 paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, phi::Place const&, paddle::framework::RuntimeContext*) const
6 std::_Function_handler<void (paddle::framework::InferShapeContext*), paddle::framework::details::OpInfoFiller<equal_InferShapeFunctor, (paddle::framework::details::OpInfoFillType)4>::operator()(char const*, paddle::framework::OpInfo*) const::{lambda(paddle::framework::InferShapeContext*)#1}>::_M_invoke(std::_Any_data const&, paddle::framework::InferShapeContext*&&)
7 equal_InferShapeFunctor::operator()(paddle::framework::InferShapeContext*) const
8 phi::CompareInferMeta(phi::MetaTensor const&, phi::MetaTensor const&, int, phi::MetaTensor*)
9 phi::funcs::GetBroadcastDimsArrays(phi::DDim const&, phi::DDim const&, int*, int*, int*, int, int)
10 phi::enforce::EnforceNotMet::EnforceNotMet(phi::ErrorSummary const&, char const*, int)
11 phi::enforce::GetCurrentTraceBackStringabi:cxx11
Error Message Summary:
InvalidArgumentError: Axis should be less than 2, but received axis is 2.
[Hint: Expected axis < max_dim, but received axis:2 >= max_dim:2.] (at /paddle/paddle/phi/kernels/funcs/common_shape.h:53)
[operator < equal > error]
SIGABRT: abort
PC=0x7f7d19dcc387 m=0 sigcode=18446744073709551610
signal arrived during cgo execution
goroutine 1 [syscall]:
runtime.cgocall(0x7b64a0, 0xc000071958)
/opt/go1.18/src/runtime/cgocall.go:157 +0x5c fp=0xc000071918 sp=0xc0000718e0 pc=0x409cfc
ds_nlpcls/paddle._Cfunc_PD_PredictorRun(0x1bb1ac0)
_cgo_gotypes.go:1353 +0x49 fp=0xc000071958 sp=0xc000071918 pc=0x70e369
ds_nlpcls/paddle.(*Predictor).Run.func1(0xc000266410)
/home/zhouzh/ds_nlpcls/paddle/predictor.go:145 +0x6d fp=0xc0000719b0 sp=0xc000071958 pc=0x710ead
ds_nlpcls/paddle.(*Predictor).Run(0xc000266410)
/home/zhouzh/ds_nlpcls/paddle/predictor.go:145 +0x1e fp=0xc0000719d8 sp=0xc0000719b0 pc=0x710e1e
main.predict({0x83f621, 0x22d7})
/home/zhouzh/ds_nlpcls/main.go:249 +0x1c6 fp=0xc000071ba8 sp=0xc0000719d8 pc=0x7b4546
main.main()
/home/zhouzh/ds_nlpcls/main.go:227 +0x5ee fp=0xc000071f80 sp=0xc000071ba8 pc=0x7b414e
runtime.main()
/opt/go1.18/src/runtime/proc.go:250 +0x1d8 fp=0xc000071fe0 sp=0xc000071f80 pc=0x4417f8
runtime.goexit()
/opt/go1.18/src/runtime/asm_amd64.s:1571 +0x1 fp=0xc000071fe8 sp=0xc000071fe0 pc=0x46f281
rax 0x0
rbx 0x28fc2d0
rcx 0xffffffffffffffff
rdx 0x6
rdi 0x37f9
rsi 0x37f9
rbp 0x7f7d1a15e868
rsp 0x7ffefca7aa18
r8 0x7f7d20eb8010
r9 0x7f7d20ec1700
r10 0x8
r11 0x206
r12 0x28f6ad0
r13 0x1
r14 0x7ffefca7ad20
r15 0x1
rip 0x7f7d19dcc387
rflags 0x206
cs 0x33
fs 0x0
gs 0x0
3)疑问:为何底层C++ 会调用我训练过程中的python环境,这个地方报错我该如何定位和解决,没找到新相关的解决方法,麻烦帮忙看看,非常感谢!
其他补充信息 Additional Supplementary Information
No response
The text was updated successfully, but these errors were encountered: