8000 [llm]update dpo criterion by lugimzzz · Pull Request #9620 · PaddlePaddle/PaddleNLP · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[llm]update dpo criterion #9620

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 2 commits into from
Dec 16, 2024
Merged

[llm]update dpo criterion #9620

merged 2 commits into from
Dec 16, 2024

Conversation

lugimzzz
Copy link
Contributor

PR types

Performance optimization

PR changes

APIs

Description

优化dpo criterion

Copy link
paddle-bot bot commented Dec 11, 2024

Thanks for your contribution!

@@ -148,16 +148,25 @@ def dpo_logps(
if self.config.tensor_parallel_degree > 1 and self.config.sequence_parallel:
labels, sparse_tgt_idx = sequence_parallel_sparse_mask_labels(labels, 0)

hidden_states = paddle.take_along_axis(hidden_states, sparse_tgt_idx, axis=0)
hidden_states = paddle.gather(hidden_states, sparse_tgt_idx, axis=0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gather api代替take_along_axis提高效率

hidden_states = paddle.take_along_axis(hidden_states, sparse_tgt_idx.unsqueeze(-1), axis=0)

hidden_states = paddle.gather(hidden_states, sparse_tgt_idx, axis=0)
elif self.config.use_fused_head_and_loss_fn:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

之前缺少sequence parallel的梯度计算补上

[(per_token_logps[response_index[1] : response_index[2]]).sum() for response_index in response_indexs],
[
(
paddle.gather(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gather 代替slice,gpu和npu能够通用

@@ -194,64 +203,65 @@ def dpo_logps(

if len(response_indexs.shape) == 3:
response_indexs = response_indexs[0]

offset = 1 if self.ignore_eos_token else 0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

offset是因为希望rm和dpo能共用一个数据流,对于dpo来说 ignore_eos_token默认为True

Copy link
codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Project coverage is 52.98%. Comparing base (9f237b4) to head (27dc4d2).
Report is 25 commits behind head on develop.

Current head 27dc4d2 differs from pull request most recent head 6fc343f

Please upload reports for the commit 6fc343f to get more accurate results.

Files with missing lines Patch % Lines
paddlenlp/trl/dpo_criterion.py 9.09% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9620      +/-   ##
===========================================
- Coverage    53.10%   52.98%   -0.13%     
===========================================
  Files          704      708       +4     
  Lines       110967   111168     +201     
===========================================
- Hits         58925    58898      -27     
- Misses       52042    52270     +228     

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

wawltor
wawltor previously approved these changes Dec 11, 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

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 f3ba5b3 into PaddlePaddle:develop Dec 16, 2024
9 of 12 checks passed
@lugimzzz lugimzzz deleted the gather branch December 16, 2024 08:43
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.

2 participants
0