PaddlePaddle / PaddleHub

Awesome pre-trained models toolkit based on PaddlePaddle. (400+ models including Image, Text, Audio, Video and Cross-Modal with Easy Inference & Serving)【安全加固,暂停交互,请耐心等待】
https://www.paddlepaddle.org.cn/hub
Apache License 2.0
12.73k stars 2.07k forks source link

paddlehub 文本分类问题 #1420

Open 1205469665 opened 3 years ago

1205469665 commented 3 years ago

https://github.com/PaddlePaddle/PaddleHub/blob/release/v2.1/demo/text_classification/README.md 文本分类paddlehub 有支持加载静态图的api 吗? https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/text_classification/pretrained_models image

KPatr1ck commented 3 years ago

你好,静态图版本的文本分类可以查看以下教程: https://github.com/PaddlePaddle/PaddleHub/tree/release/v1.8/demo/text_classification

1205469665 commented 3 years ago

这个是1.8 版本的呀 我现在用的2.0 的 模型文件现在都不一样了, 就是2.0 的怎么用静态图

KPatr1ck commented 3 years ago

image 这里提供了转换脚本,你可以尝试在2.0的paddlehub里保存模型,然后再通过这个脚本转换。

1205469665 commented 3 years ago

我目前使用了这个转换 就是想问 通过这个转换之后,应该如何使用 paddlehub 能读取这个静态图模型

1205469665 commented 3 years ago

还有就是 我用paddlehub 训练完之后转换成静态图 然后执行这个命令测试 python deploy/python/predict.py --model_file=static_graph_params.pdmodel --params_file=static_graph_params.pdiparams 报错 这个是怎么解决? 2021-05-20 17:48:52,836] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\vocab.txt [2021-05-20 17:48:52,838] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\spm_cased_simp_sampled.model [2021-05-20 17:48:52,839] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\dict.wordseg.pickle W0520 17:48:55.521246 12936 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 11.0, Runtime API Version: 10.0 W0520 17:48:55.547174 12936 device_context.cc:372] device: 0, cuDNN Version: 7.6. Traceback (most recent call last): File "deploy/python/predict.py", line 187, in data, tokenizer, label_map, batch_size=args.batch_size) File "deploy/python/predict.py", line 160, in predict self.predictor.run() ValueError: In user code:

File "export_model.py", line 54, in <module>
  paddle.jit.save(model, args.output_path)
File "<decorator-gen-60>", line 2, in save

File "D:\kaifa\python3\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\base.py", line 39, in __impl__
  return func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\jit.py", line 681, in save
  inner_input_spec)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 488, in concrete_program_specify_input_spec
  *desired_input_spec)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 402, in get_concrete_program
  concrete_program, partial_program_layer = self._program_cache[cache_key]
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 711, in __getitem__
  self._caches[item] = self._build_once(item)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 702, in _build_once
  class_instance=cache_key.class_instance)
File "<decorator-gen-58>", line 2, in from_func_spec

File "D:\kaifa\python3\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\base.py", line 39, in __impl__
  return func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 652, in from_func_spec
  outputs = static_func(*inputs)
File "D:\kaifa\python3\lib\site-packages\paddlenlp\transformers\ernie\modeling.py", line 270, in forward
  attention_mask=attention_mask)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\layers.py", line 902, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "C:\Users\ADMINI~1\AppData\Local\Temp\tmppzzlex1_.py", line 16, in forward
  attention_mask,), (attention_mask,))
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\convert_operators.py", line 210, in convert_ifelse
  return _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\convert_operators.py", line 235, in _run_py_ifelse
  return true_fn(*true_args) if pred else false_fn(*false_args)
File "D:\kaifa\python3\lib\site-packages\paddlenlp\transformers\ernie\modeling.py", line 228, in forward
  ).astype(self.pooler.dense.weight.dtype) * -1e9,
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\layers\math_op_patch.py", line 304, in __impl__
  attrs={'axis': axis})
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\framework.py", line 3027, in append_op
  attrs=kwargs.get("attrs", None))
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\framework.py", line 2107, in __init__
  for frame in traceback.extract_stack():

InvalidArgumentError: The DataType of equal Op's duplicable Variable Y must be consistent. The current variable type is (int64_t), but the previous variable type is (int). (at D:\v2.0.2\paddle\paddle\fluid\framework\operator.cc:

1520) [operator < equal > error]

KPatr1ck commented 3 years ago

我目前使用了这个转换 就是想问 通过这个转换之后,应该如何使用 paddlehub 能读取这个静态图模型

关于模型的载入,paddlehub使用的接口是paddlepaddle的载入逻辑,具体的静态图和动态图参数的载入方式,请参考: https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/02_paddle2.0_develop/08_model_save_load_cn.html#sanmoxing-canshucunchuzairu-xunlianbushu

另外关于https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/text_classification/pretrained_models 中的转换教程,paddlehub这边的模型没有提供和验证过此类的部署方式,请配合其教程中相应的训练后的模型使用。

1205469665 commented 3 years ago

您好我按照 https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/text_classification/pretrained_models 的教程执行 deom 的训练, 和转换预测,还是 报这个错 https://github.com/PaddlePaddle/PaddleNLP/tree/develop/examples/text_classification/pretrained_models 9:09:51.706229 15372 analysis_predictor.cc:677] The one-time configuration of analysis predictor failed, which may be due to native predictor called first and its configurations taken effect. I0521 09:09:51.706229 15372 analysis_predictor.cc:155] Profiler is deactivated, and no profiling report will be generated. e[1me[35m--- Running analysis [ir_graph_build_pass]e[0m e[1me[35m--- Running analysis [ir_graph_clean_pass]e[0m e[1me[35m--- Running analysis [ir_analysis_pass]e[0m e[32m--- Running IR pass [is_test_pass]e[0m e[32m--- Running IR pass [simplify_with_basic_ops_pass]e[0m e[32m--- Running IR pass [conv_affine_channel_fuse_pass]e[0m e[32m--- Running IR pass [conv_eltwiseadd_affine_channel_fuse_pass]e[0m e[32m--- Running IR pass [conv_bn_fuse_pass]e[0m e[32m--- Running IR pass [conv_eltwiseadd_bn_fuse_pass]e[0m e[32m--- Running IR pass [embedding_eltwise_layernorm_fuse_pass]e[0m I0521 09:09:51.980496 15372 graph_pattern_detector.cc:101] --- detected 1 subgraphs I0521 09:09:51.980496 15372 graph_pattern_detector.cc:101] --- detected 1 subgraphs I0521 09:09:51.981493 15372 graph_pattern_detector.cc:101] --- detected 7 subgraphs e[32m--- Running IR pass [multihead_matmul_fuse_pass_v2]e[0m e[32m--- Running IR pass [squeeze2_matmul_fuse_pass]e[0m e[32m--- Running IR pass [reshape2_matmul_fuse_pass]e[0m I0521 09:09:51.985482 15372 graph_pattern_detector.cc:101] --- detected 3 subgraphs e[32m--- Running IR pass [flatten2_matmul_fuse_pass]e[0m e[32m--- Running IR pass [map_matmul_to_mul_pass]e[0m I0521 09:09:51.988474 15372 graph_pattern_detector.cc:101] --- detected 23 subgraphs e[32m--- Running IR pass [fc_fuse_pass]e[0m I0521 09:09:51.993461 15372 graph_pattern_detector.cc:101] --- detected 3 subgraphs I0521 09:09:51.995455 15372 graph_pattern_detector.cc:101] --- detected 17 subgraphs e[32m--- Running IR pass [fc_elementwise_layernorm_fuse_pass]e[0m I0521 09:09:51.998448 15372 graph_pattern_detector.cc:101] --- detected 6 subgraphs e[32m--- Running IR pass [conv_elementwise_add_act_fuse_pass]e[0m e[32m--- Running IR pass [conv_elementwise_add2_act_fuse_pass]e[0m e[32m--- Running IR pass [conv_elementwise_add_fuse_pass]e[0m e[32m--- Running IR pass [transpose_flatten_concat_fuse_pass]e[0m e[32m--- Running IR pass [runtime_context_cache_pass]e[0m e[1me[35m--- Running analysis [ir_params_sync_among_devices_pass]e[0m I0521 09:09:52.011413 15372 ir_params_sync_among_devices_pass.cc:45] Sync params from CPU to GPU e[1me[35m--- Running analysis [adjust_cudnn_workspace_size_pass]e[0m e[1me[35m--- Running analysis [inference_op_replace_pass]e[0m e[1me[35m--- Running analysis [ir_graph_to_program_pass]e[0m I0521 09:09:52.155030 15372 analysis_predictor.cc:598] ======= optimize end ======= I0521 09:09:52.155030 15372 naive_executor.cc:107] --- skip [feed], feed -> token_type_ids I0521 09:09:52.155030 15372 naive_executor.cc:107] --- skip [feed], feed -> input_ids I0521 09:09:52.156028 15372 naive_executor.cc:107] --- skip [save_infer_model/scale_0.tmp_1], fetch -> fetch [2021-05-21 09:09:52,157] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\vocab.txt [2021-05-21 09:09:52,158] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\spm_cased_simp_sampled.model [2021-05-21 09:09:52,160] [ INFO] - Found C:\Users\Administrator.paddlenlp\models\ernie-tiny\dict.wordseg.pickle W0521 09:09:54.879829 15372 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 11.0, Runtime API Version: 10.0 W0521 09:09:54.891798 15372 device_context.cc:372] device: 0, cuDNN Version: 7.6. Traceback (most recent call last): File "deploy/python/predict.py", line 187, in data, tokenizer, label_map, batch_size=args.batch_size) File "deploy/python/predict.py", line 160, in predict self.predictor.run() ValueError: In user code:

File "export_model.py", line 54, in <module>
  paddle.jit.save(model, args.output_path)
File "<decorator-gen-60>", line 2, in save

File "D:\kaifa\python3\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\base.py", line 39, in __impl__
  return func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\jit.py", line 681, in save
  inner_input_spec)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 488, in concrete_program_specify_input_spec
  *desired_input_spec)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 402, in get_concrete_program
  concrete_program, partial_program_layer = self._program_cache[cache_key]
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 711, in __getitem__
  self._caches[item] = self._build_once(item)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 702, in _build_once
  class_instance=cache_key.class_instance)
File "<decorator-gen-58>", line 2, in from_func_spec

File "D:\kaifa\python3\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\base.py", line 39, in __impl__
  return func(*args, **kwargs)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\program_translator.py", line 652, in from_func_spec
  outputs = static_func(*inputs)
File "D:\kaifa\python3\lib\site-packages\paddlenlp\transformers\ernie\modeling.py", line 270, in forward
  attention_mask=attention_mask)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\layers.py", line 902, in __call__
  outputs = self.forward(*inputs, **kwargs)
File "C:\Users\ADMINI~1\AppData\Local\Temp\tmps_cio73f.py", line 16, in forward
  attention_mask,), (attention_mask,))
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\convert_operators.py", line 210, in convert_ifelse
  return _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args)
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\dygraph\dygraph_to_static\convert_operators.py", line 235, in _run_py_ifelse
  return true_fn(*true_args) if pred else false_fn(*false_args)
File "D:\kaifa\python3\lib\site-packages\paddlenlp\transformers\ernie\modeling.py", line 228, in forward
  ).astype(self.pooler.dense.weight.dtype) * -1e9,
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\layers\math_op_patch.py", line 304, in __impl__
  attrs={'axis': axis})
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\framework.py", line 3027, in append_op
  attrs=kwargs.get("attrs", None))
File "D:\kaifa\python3\lib\site-packages\paddle\fluid\framework.py", line 2107, in __init__
  for frame in traceback.extract_stack():

InvalidArgumentError: The DataType of equal Op's duplicable Variable Y must be consistent. The current variable type is (int64_t), but the previous variable type is (int). (at D:\v2.0.2\paddle\paddle\fluid\framework\operator.cc:

1520) [operator < equal > error]