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

[LLM] Add tools for parameters #9137

Merged
merged 4 commits into from
Oct 10, 2024

Conversation

Hanyonggong
Copy link
Contributor

@Hanyonggong Hanyonggong commented Sep 13, 2024

PR types

Others

PR changes

Others

Description

add some llm tools:

  • llm/tools/convert_gqa_to_mha.py: convert model from gqa to mha
  • llm/tools/split_weights.py: split model weight according to tensor parallel degree

Copy link

paddle-bot bot commented Sep 13, 2024

Thanks for your contribution!

Copy link

codecov bot commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.98%. Comparing base (9806293) to head (a912ff6).
Report is 50 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9137      +/-   ##
===========================================
- Coverage    53.34%   51.98%   -1.36%     
===========================================
  Files          652      657       +5     
  Lines       105401   110297    +4896     
===========================================
+ Hits         56222    57342    +1120     
- Misses       49179    52955    +3776     

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

@ZHUI
Copy link
Collaborator

ZHUI commented Sep 13, 2024

emm,你们搞得太复杂了。safetensor本来就支持多文件直接加载,还支持mmap切分load。不需要这么麻烦的。

Copy link
Collaborator

@ZHUI ZHUI left a comment

Choose a reason for hiding this comment

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

@DesmonDay 看看我们已有的方法能不能帮推理直接切分参数。

@DesmonDay
Copy link
Contributor

DesmonDay commented Sep 14, 2024

对safetensors格式的权重做TP切分,我们在 https://github.com/PaddlePaddle/PaddleNLP/blob/develop/paddlenlp/transformers/model_utils.py#L2770 这个函数中已经做了实现,直接调用该函数就行,不需要对safetensors合并后再拆分。 @Hanyonggong

@DesmonDay DesmonDay self-requested a review September 14, 2024 03:38
config_file = open(config_path, "r")
config_json = json.load(config_file)

model = paddle.load(gqa_model_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

如果对于safetensors格式的权重,就不支持了?

@@ -0,0 +1,65 @@
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
#
Copy link
Contributor

Choose a reason for hiding this comment

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

这个文件可以直接删掉。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


model_state_dict = paddle.load(model_path)

state_dict = model.convert_tensor_parallel(
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

Copy link
Contributor

Choose a reason for hiding this comment

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

感觉你没有理解我的意思。我的意思是切分TP权重的这个函数,convert_tensor_parallel这个东西,不需要你自己调用了,前面的load_tp_checkpoint已经做了这个功能,拿到的state_dict就是切分后的。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已去除

@CLAassistant
Copy link

CLAassistant commented Sep 19, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@DesmonDay DesmonDay left a comment

Choose a reason for hiding this comment

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

LGTM

@ZHUI ZHUI closed this Oct 9, 2024
@ZHUI ZHUI reopened this Oct 9, 2024
@yuanlehome yuanlehome closed this Oct 10, 2024
@yuanlehome yuanlehome reopened this Oct 10, 2024
@ZHUI ZHUI merged commit 37c211a into PaddlePaddle:develop Oct 10, 2024
12 of 16 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.

5 participants