-
Notifications
You must be signed in to change notification settings - Fork 79
feat: support multi_stream_parallel and modify batch sampler. [1/4] #110
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
liutongxuan
merged 2 commits into
jd-opensource:main
from
guojinrong-nn:feat_prefill_multi_streams_parallel
Sep 10, 2025
Merged
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| /* Copyright 2025 The xLLM Authors. All Rights Reserved. | ||
| Copyright 2024 The ScaleLLM 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 | ||
|
|
||
| https://github.com/jd-opensource/xllm/blob/main/LICENSE | ||
|
|
||
| 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 "sampling_params.h" | ||
|
|
||
| #include <glog/logging.h> | ||
| #include <gtest/gtest.h> | ||
| #include <torch/torch.h> | ||
|
|
||
| namespace xllm { | ||
|
|
||
| TEST(SamplingParamsTest, NormalConcat) { | ||
| // construct sampling_parameters_1 | ||
| RequestSamplingParam request_1, request_2; | ||
| std::vector<int32_t> selected_token_idxes_1{11, 23}; | ||
| std::vector<int32_t> sample_idxes_1{0, 1}; | ||
| std::vector<std::vector<int64_t>> unique_token_ids_vec_1{ | ||
| std::vector<int64_t>{ | ||
| 151645, 100022, 104202, 104167, 198, 77091, 872, 220, 151644}, | ||
| std::vector<int64_t>{ | ||
| 151645, 100022, 104202, 104167, 198, 77091, 872, 220, 151644}}; | ||
| std::vector<std::vector<int32_t>> unique_token_counts_vec_1{ | ||
| std::vector<int32_t>{1, 1, 1, 1, 3, 1, 1, 1, 2}, | ||
| std::vector<int32_t>{1, 1, 1, 1, 3, 1, 1, 1, 2}}; | ||
| std::vector<int32_t> unique_token_lens_vec_1{9, 9}; | ||
|
|
||
| SamplingParameters sampling_parameters_1; | ||
| sampling_parameters_1.init( | ||
| std::vector<const RequestSamplingParam*>{&request_1, &request_2}, | ||
| selected_token_idxes_1, | ||
| sample_idxes_1, | ||
| unique_token_ids_vec_1, | ||
| unique_token_counts_vec_1, | ||
| unique_token_lens_vec_1); | ||
|
|
||
| // construct sampling_parameters_2 | ||
| RequestSamplingParam request_3, request_4; | ||
| std::vector<int32_t> selected_token_idxes_2{13, 28}; | ||
| std::vector<int32_t> sample_idxes_2{0, 1}; | ||
| std::vector<std::vector<int64_t>> unique_token_ids_vec_2{ | ||
| std::vector<int64_t>{151645, | ||
| 119414, | ||
| 100287, | ||
| 26288, | ||
| 101239, | ||
| 198, | ||
| 77091, | ||
| 106055, | ||
| 872, | ||
| 220, | ||
| 151644}, | ||
| std::vector<int64_t>{0, | ||
| 62112, | ||
| 9370, | ||
| 107425, | ||
| 151645, | ||
| 99489, | ||
| 106309, | ||
| 198, | ||
| 77091, | ||
| 71618, | ||
| 872, | ||
| 220, | ||
| 151644}}; | ||
| std::vector<std::vector<int32_t>> unique_token_counts_vec_2{ | ||
| std::vector<int32_t>{1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2}, | ||
| std::vector<int32_t>{0, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2}}; | ||
| std::vector<int32_t> unique_token_lens_vec_2{11, 12}; | ||
|
|
||
| SamplingParameters sampling_parameters_2; | ||
| sampling_parameters_2.init( | ||
| std::vector<const RequestSamplingParam*>{&request_3, &request_4}, | ||
| selected_token_idxes_2, | ||
| sample_idxes_2, | ||
| unique_token_ids_vec_2, | ||
| unique_token_counts_vec_2, | ||
| unique_token_lens_vec_2); | ||
|
|
||
| // construct expected output | ||
| torch::Tensor result_selected_token_idxes = torch::tensor({11, 23, 37, 52}); | ||
| torch::Tensor result_sample_idxes = torch::tensor({0, 1, 2, 3}); | ||
|
|
||
| // execute concat | ||
| sampling_parameters_1.concat(sampling_parameters_2); | ||
|
|
||
| // check results | ||
| EXPECT_TRUE(torch::equal(sampling_parameters_1.selected_token_idxes, | ||
| result_selected_token_idxes)); | ||
| EXPECT_TRUE( | ||
| torch::equal(sampling_parameters_1.sample_idxes, result_sample_idxes)); | ||
| } | ||
|
|
||
| TEST(SamplingParamsTest, AbnormalConcat) { | ||
| // construct both of default sampling_parameters | ||
| SamplingParameters sampling_parameters_1, sampling_parameters_2; | ||
|
|
||
| // execute concat | ||
| sampling_parameters_1.concat(sampling_parameters_2); | ||
|
|
||
| // check results | ||
| EXPECT_FALSE(sampling_parameters_1.selected_token_idxes.defined()); | ||
| EXPECT_FALSE(sampling_parameters_1.sample_idxes.defined()); | ||
| } | ||
|
|
||
| } // namespace xllm |
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
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.
Uh oh!
There was an error while loading. Please reload this page.