Skip to content

【PaddleNLP No.21】Create paddle.inference infer example for ernie-3.0-tiny #10480

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

Merged
merged 1 commit into from
Apr 24, 2025

Conversation

hanlintang
Copy link
Contributor

PR types

Function optimization

PR changes

Models

Description

  1. 为Ernie-3.0-tiny删除无法匹配PIR的fastdeploy部署方式,提供基于paddle.inference的推理示例。
  2. 基于实现内容修改文档,更新更换推理方式的运行结果。

Modified:
slm/model_zoo/ernie-3.0-tiny/README.md
slm/model_zoo/ernie-3.0-tiny/deploy/README.md
slm/model_zoo/ernie-3.0-tiny/deploy/python/README.md
slm/model_zoo/ernie-3.0-tiny/deploy/python/infer_demo.py

其他问题

在训练Ernie-3.0-tiny时遇到了一些问题,可能需要后续进行修复:

  1. 部分参数丢失
Traceback (most recent call last):
  File "run_train.py", line 286, in <module>
    main()
  File "run_train.py", line 151, in main
    model = JointErnie.from_pretrained(
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/transformers/model_utils.py", line 2567, in from_pretrained
    model, missing_keys, unexpected_keys, mismatched_keys = cls._load_pretrained_model(
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/transformers/model_utils.py", line 2254, in _load_pretrained_model
    raise RuntimeError(f"Error(s) in loading state_dict for {model.__class__.__name__}:\n\t{error_msg}")
RuntimeError: Error(s) in loading state_dict for JointErnie:
        Skip loading for ernie.embeddings.word_embeddings.weight. ernie.embeddings.word_embeddings.weight receives a shape [5965, 312], but the expected shape is [6000, 312].
        You may consider adding `ignore_mismatched_sizes=True` in the model `from_pretrained` method.

按照最后一句提示在指定位置加入参数设置忽略不匹配的size可以通过。

  1. 评估部分报错
Traceback (most recent call last):
  File "run_train.py", line 288, in <module>
    main()
  File "run_train.py", line 230, in main
    trainer.train(resume_from_checkpoint=checkpoint)
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/trainer/trainer.py", line 892, in train
    return self._inner_training_loop(
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/trainer/trainer.py", line 1281, in _inner_training_loop
    self._maybe_log_save_evaluate(tr_loss, model, epoch, ignore_keys_for_eval, inputs=inputs)
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/trainer/trainer.py", line 1578, in _maybe_log_save_evaluate
    metrics = self.evaluate(ignore_keys=ignore_keys_for_eval)
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/trainer/trainer.py", line 3118, in evaluate
    output = self.evaluation_loop(
  File "/home/aistudio/.local/lib/python3.8/site-packages/paddlenlp/trainer/trainer.py", line 3340, in evaluation_loop
    metrics = self.compute_metrics(EvalPrediction(predictions=all_preds, label_ids=batch_labels))
  File "/home/aistudio/PaddleNLP/slm/model_zoo/ernie-3.0-tiny/utils.py", line 113, in compute_metrics
    intent_label, slot_label = p.label_ids
ValueError: too many values to unpack (expected 2)

问题出现在评估部分,需要后续修改;暂时跳过的方式是在训练参数中去掉以下部分可以只训练跳过dev评估:

--do_eval
--eval_steps 100
--load_best_model_at_end True
--metric_for_best_model eval_accuracy

Issue: #9763
@DrownFish19

Copy link

paddle-bot bot commented Apr 23, 2025

Thanks for your contribution!

Copy link

codecov bot commented Apr 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.67%. Comparing base (ce7b4cc) to head (474f42d).
Report is 17 commits behind head on develop.

❌ Your project status has failed because the head coverage (48.67%) is below the target coverage (58.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #10480      +/-   ##
===========================================
- Coverage    48.99%   48.67%   -0.32%     
===========================================
  Files          765      768       +3     
  Lines       125974   126915     +941     
===========================================
+ Hits         61720    61778      +58     
- Misses       64254    65137     +883     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DrownFish19 DrownFish19 added the HappyOpenSource 快乐开源活动issue与PR label Apr 24, 2025
@DrownFish19
Copy link
Collaborator

可以尝试输出intent_label, slot_label = p.label_ids 中的p.label_id,检查输出内容

Copy link
Collaborator

@DrownFish19 DrownFish19 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DrownFish19 DrownFish19 merged commit 14bb7cf into PaddlePaddle:develop Apr 24, 2025
10 of 12 checks passed
@hanlintang hanlintang deleted the ernie3.0-tiny branch April 24, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor HappyOpenSource 快乐开源活动issue与PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants