-
Notifications
You must be signed in to change notification settings - Fork 749
[RL] Fix the incorrect routing of EOS tokens, which leads to changes in accuracy #7960
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
gongshaotian
wants to merge
11
commits into
PaddlePaddle:release/2.6
Choose a base branch
from
gongshaotian:r3_eos_2.6
base: release/2.6
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
11 commits
Select commit
Hold shift + click to select a range
507e464
Reset buffer size of R3
gongshaotian 956b543
refine code
gongshaotian ef9c4b3
R3 fix Eos bug
gongshaotian 34349e6
merge release/2.6
gongshaotian 3b09e05
pre-commit
gongshaotian 046d1ad
fix r3 ci and support dsa
gongshaotian d4454ed
refine code
gongshaotian 7176cc0
refine code
gongshaotian 20849ef
reset ci dir
gongshaotian 4e2565c
refine code
gongshaotian a064ee2
fix dsv3
gongshaotian 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
108 changes: 108 additions & 0 deletions
108
custom_ops/gpu_ops/get_position_ids_and_slot_mapping.cu
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "helper.h" | ||
| #include "paddle/extension.h" | ||
|
|
||
| __global__ void GetPositionIdsAndSlotMappingKernel( | ||
| const int* __restrict__ seq_lens_encoder, | ||
| const int* __restrict__ seq_lens_decoder, | ||
| const int* __restrict__ seq_lens_this_time, | ||
| const int* __restrict__ batch_id_per_token, | ||
| const int* __restrict__ block_tables, | ||
| const int bsz, | ||
| const int max_num_blocks, | ||
| const int block_size, | ||
| int64_t* __restrict__ position_ids, | ||
| int64_t* __restrict__ slot_mapping) { | ||
| int current_bid = threadIdx.x; | ||
| if (current_bid >= bsz) return; | ||
|
|
||
| // Calculate the offset of current batch in the position_ids buffer | ||
| int buffer_offset = 0; | ||
| for (int i = 0; i < current_bid; i++) { | ||
| buffer_offset += seq_lens_this_time[i]; | ||
| } | ||
|
|
||
| // Calculate the token offset in the current batch | ||
| int token_offset = seq_lens_decoder[current_bid]; | ||
| int token_num_this_batch = seq_lens_this_time[current_bid]; | ||
| if (token_num_this_batch == 0) return; | ||
|
|
||
| // Write position ids and slot mapping for current batch | ||
| #pragma unroll | ||
| for (int i = 0; i < token_num_this_batch; i++) { | ||
| int pos_id = token_offset + i; | ||
| int idx = buffer_offset + i; | ||
|
|
||
| // Write position_id | ||
| position_ids[idx] = pos_id; | ||
|
|
||
| // Calculate slot mapping directly | ||
| int block_idx = pos_id / block_size; | ||
| int block_offset = pos_id % block_size; | ||
| int batch_id = batch_id_per_token[idx]; | ||
|
|
||
| // Get block_id from block_tables | ||
| int block_id = block_tables[batch_id * max_num_blocks + block_idx]; | ||
|
|
||
| // Calculate slot mapping | ||
| slot_mapping[idx] = static_cast<int64_t>( | ||
| static_cast<int64_t>(block_id) * block_size + block_offset); | ||
| } | ||
| } | ||
|
|
||
| void GetPositionIdsAndSlotMapping(const paddle::Tensor& seq_lens_encoder, | ||
| const paddle::Tensor& seq_lens_decoder, | ||
| const paddle::Tensor& seq_lens_this_time, | ||
| const paddle::Tensor& batch_id_per_token, | ||
| const paddle::Tensor& block_tables, | ||
| const paddle::Tensor& position_ids, | ||
| const paddle::Tensor& slot_mapping, | ||
| const int block_size) { | ||
| const int bsz = seq_lens_this_time.shape()[0]; | ||
| const int total_token_num = position_ids.shape()[0]; | ||
| const int max_num_blocks = block_tables.shape()[1]; | ||
|
|
||
| GetPositionIdsAndSlotMappingKernel<<<1, | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
| bsz, | ||
| 0, | ||
| seq_lens_this_time.stream()>>>( | ||
| seq_lens_encoder.data<int>(), | ||
| seq_lens_decoder.data<int>(), | ||
| seq_lens_this_time.data<int>(), | ||
| batch_id_per_token.data<int>(), | ||
| block_tables.data<int>(), | ||
| bsz, | ||
| max_num_blocks, | ||
| block_size, | ||
| const_cast<int64_t*>(position_ids.data<int64_t>()), | ||
| const_cast<int64_t*>(slot_mapping.data<int64_t>())); | ||
| } | ||
|
|
||
| PD_BUILD_STATIC_OP(get_position_ids_and_slot_mapping) | ||
| .Inputs({ | ||
| "seq_lens_encoder", | ||
| "seq_lens_decoder", | ||
| "seq_lens_this_time", | ||
| "batch_id_per_token", | ||
| "block_tables", | ||
| "position_ids", | ||
| "slot_mapping", | ||
| }) | ||
| .Attrs({"block_size: int"}) | ||
| .Outputs({"position_ids_out", "slot_mapping_out"}) | ||
| .SetInplaceMap({{"position_ids", "position_ids_out"}, | ||
| {"slot_mapping", "slot_mapping_out"}}) | ||
| .SetKernelFn(PD_KERNEL(GetPositionIdsAndSlotMapping)); | ||
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
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.
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.
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.