-
Notifications
You must be signed in to change notification settings - Fork 743
[Optimization][Speculative Decoding]opt mtp logprob #7883
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
Open
Sunny-bot1
wants to merge
2
commits into
PaddlePaddle:develop
Choose a base branch
from
Sunny-bot1:opt_mtp_logprob
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,9 +121,11 @@ void SpeculateSaveOutMmsgTopK(const paddle::Tensor& sampled_token_ids, | |
| msg_sed.mtype = 1; | ||
| msg_sed.meta[0] = not_need_stop.data<bool>()[0] ? inference_msg_id_from_env | ||
| : -inference_msg_id_from_env; | ||
| msg_sed.meta[1] = message_flag; | ||
| msg_sed.meta[2] = bsz; | ||
| // Pack message_flag (low 8 bits) and max_num_logprobs (high 16 bits) into | ||
| // meta[1]. Receiver unpacks both to avoid reading unused topk slots. | ||
| int max_num_logprobs = logprob_token_ids.shape()[1]; | ||
| msg_sed.meta[1] = message_flag | (max_num_logprobs << 8); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 建议 当 旧代码中 speculative decoding 的 建议在此处加防御断言: PD_CHECK(max_num_logprobs <= 0xFFFF,
"max_num_logprobs %d exceeds 16-bit limit", max_num_logprobs); |
||
| msg_sed.meta[2] = bsz; | ||
| for (int i = 0; i < bsz; i++) { | ||
| int cur_token_num; | ||
| if (seq_lens_decoder_data[i] < prompt_lens_data[i]) { | ||
|
|
@@ -139,24 +141,20 @@ void SpeculateSaveOutMmsgTopK(const paddle::Tensor& sampled_token_ids, | |
| auto* cur_batch_msg_sed = &msg_sed.mtext[i]; | ||
| int token_offset = cu_batch_token_offset_data[i]; | ||
| for (int j = 0; j < cur_token_num; j++) { | ||
| // Use SPEC_LOGPROB_K+1 as stride (fixed struct layout), but only write | ||
| // max_num_logprobs columns to avoid filling unused topk slots. | ||
| auto* cur_tokens = &cur_batch_msg_sed->tokens[j * (SPEC_LOGPROB_K + 1)]; | ||
| auto* cur_scores = &cur_batch_msg_sed->scores[j * (SPEC_LOGPROB_K + 1)]; | ||
| for (int k = 0; k < SPEC_LOGPROB_K + 1; k++) { | ||
| for (int k = 0; k < max_num_logprobs; k++) { | ||
| if (k == 0) { | ||
| cur_tokens[k] = (int)sampled_token_ids_data[i * max_draft_tokens + j]; | ||
| cur_scores[k] = | ||
| logprob_scores_data[(token_offset + j) * (SPEC_LOGPROB_K + 1) + | ||
| k]; | ||
| } else if (k < max_num_logprobs) { | ||
| logprob_scores_data[(token_offset + j) * max_num_logprobs + k]; | ||
| } else { | ||
| cur_tokens[k] = (int) | ||
| logprob_token_ids_data[(token_offset + j) * (SPEC_LOGPROB_K + 1) + | ||
| k]; | ||
| logprob_token_ids_data[(token_offset + j) * max_num_logprobs + k]; | ||
| cur_scores[k] = | ||
| logprob_scores_data[(token_offset + j) * (SPEC_LOGPROB_K + 1) + | ||
| k]; | ||
| } else { | ||
| cur_tokens[k] = -1; | ||
| cur_scores[k] = 0.0; | ||
| logprob_scores_data[(token_offset + j) * max_num_logprobs + k]; | ||
| } | ||
| } | ||
| cur_batch_msg_sed->ranks[j] = (int)logprob_ranks_data[token_offset + j]; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ 疑问
real_k参数是否已成死代码?本次修改将循环条件从
k < real_k + 1改为k < actual_topk,real_k参数不再出现在循环体中。但 Python 侧在调用此算子时仍传入K=20(token_processor.py中的常量)作为real_k属性。请确认
real_k是否还被用于输出 tensor 的预分配或其他地方;若已完全废弃,建议清理该参数以避免后续维护误解。