Skip to content
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

【inference】support load or save Llama2-7b in three patterns #8766

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

lizexu123
Copy link
Contributor

@lizexu123 lizexu123 commented Jul 16, 2024

PR types

New features

PR changes

Others

Description

补充:

  • 导出pdmodel:

python ./predict/export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --output_path ./llama_pdmodel --dtype float16

  • 导出json:

FLAGS_enable_pir_api=1 python ./predict/export_model.py --model_name_or_path meta-llama/Llama-2-7b-chat --output_path ./llama-json --dtype float16

支持三种模式跑

  • 跑Llama2-7b.pdmodel +旧ir

python ./predict/predictor.py --model_name_or_path ./llama_pdmodel --dtype float16 --mode static

  • 跑Llama2-7b.pdmodel +pir

FLAGS_enable_pir_in_executor=1 python ./predict/predictor.py --model_name_or_path ./llama_pdmodel --dtype float16 --mode static

  • 跑Llama2-7b.json +pir

FLAGS_enable_pir_api=1 python ./predict/predictor.py --model_name_or_path ./llama-json --dtype float16 --mode static
如需测试保存优化后的模型再推理,设置inference_config.use_optimized_model(True),第一次执行会先保存优化后的模型,第二次执行,会直接加载优化后的模型进行推理

Copy link

paddle-bot bot commented Jul 16, 2024

Thanks for your contribution!

wawltor
wawltor previously approved these changes Jul 16, 2024
Copy link
Collaborator

@wawltor wawltor left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 349 to 351
params_path = os.path.join(self.config.model_name_or_path, self.config.model_prefix + ".pdiparams")
if paddle.framework.use_pir_api():
model_path = os.path.join(self.config.model_name_or_path, self.config.model_prefix + ".json")
else:
model_path = os.path.join(self.config.model_name_or_path, self.config.model_prefix + ".pdmodel")
params_path = self.config.model_prefix
model_path = self.config.model_name_or_path
inference_config = paddle.inference.Config(model_path, params_path)
Copy link
Collaborator

@yuanlehome yuanlehome Jul 16, 2024

Choose a reason for hiding this comment

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

inference_config = paddle.inference.Config(self.config.model_name_or_path, self.config.model_prefix)

Copy link
Collaborator

Choose a reason for hiding this comment

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

这些改成这一行就行了

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.50%. Comparing base (5a508e5) to head (248f93a).
Report is 215 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8766      +/-   ##
===========================================
+ Coverage    55.43%   55.50%   +0.06%     
===========================================
  Files          626      626              
  Lines        98070    98070              
===========================================
+ Hits         54366    54433      +67     
+ Misses       43704    43637      -67     

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

Copy link
Collaborator

@wawltor wawltor left a comment

Choose a reason for hiding this comment

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

LGTM

@wawltor wawltor merged commit 5e53db1 into PaddlePaddle:develop Jul 16, 2024
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants