-
Notifications
You must be signed in to change notification settings - Fork 582
[Feature] support min_p_sampling #2872
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
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
da68f6d
Fastdeploy support min_p
lizexu123 4df179f
add test_min_p
lizexu123 f8e391d
fix
lizexu123 edb4202
min_p_sampling
lizexu123 53bdfb2
update
lizexu123 abd4a75
merge develop
lizexu123 8d33bd4
delete vl_gpu_model_runner.py
lizexu123 3e8cd85
fix
lizexu123 4618992
Align usage of min_p with vLLM
lizexu123 12ebeb2
fix
lizexu123 e8dde63
merge develop
lizexu123 5b9ffc5
modified unit test
lizexu123 5c335b1
fix test_min_sampling
lizexu123 d66530c
merge develop
lizexu123 417dea6
pre-commit all files
lizexu123 132eece
fix
lizexu123 30ff611
fix
lizexu123 e21671b
fix
lizexu123 25b6f93
fix xpu_model_runner.py
lizexu123 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
65 changes: 65 additions & 0 deletions
65
custom_ops/gpu_ops/sample_kernels/min_p_sampling_from_probs.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,65 @@ | ||
// 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/phi/backends/context_pool.h" | ||
#include "sample_kernels/sampling.cuh" | ||
|
||
std::vector<paddle::Tensor> MinPSamplingFromProbs(const paddle::Tensor &probs, | ||
const paddle::Tensor &min_p) { | ||
std::vector<int64_t> probs_shape = probs.shape(); | ||
unsigned int batch_size = probs_shape[0]; | ||
unsigned int vocab_size = probs_shape[1]; | ||
auto cu_stream = probs.stream(); | ||
|
||
auto renorm_probs = | ||
GetEmptyTensor(probs.dims(), paddle::DataType::FLOAT32, probs.place()); | ||
|
||
cudaError_t status; | ||
|
||
status = sampling::MinPSamplingFromProb<float, int>( | ||
const_cast<float *>(probs.data<float>()), | ||
const_cast<float *>(min_p.data<float>()), | ||
renorm_probs.data<float>(), | ||
batch_size, | ||
vocab_size, | ||
true, // deterministic | ||
cu_stream); | ||
|
||
|
||
PD_CHECK(status == cudaSuccess, "SamplingFromProbs failed with error code " + | ||
std::string(cudaGetErrorString(status))); | ||
|
||
return {renorm_probs}; | ||
} | ||
|
||
std::vector<std::vector<int64_t>> | ||
MinPSamplingFromProbsInferShape(const std::vector<int64_t> &probs_shape, | ||
const paddle::optional<std::vector<int64_t>> &min_p_shape) { | ||
return {probs_shape}; | ||
} | ||
|
||
std::vector<paddle::DataType> | ||
MinPSamplingFromProbsInferDtype(const paddle::DataType &probs_dtype, | ||
const paddle::optional<paddle::DataType> &min_p_dtype) { | ||
return {probs_dtype}; | ||
} | ||
|
||
|
||
PD_BUILD_STATIC_OP(min_p_sampling) | ||
.Inputs({"probs", "min_p"}) | ||
.Outputs({"renorm_probs"}) | ||
.SetKernelFn(PD_KERNEL(MinPSamplingFromProbs)) | ||
.SetInferShapeFn(PD_INFER_SHAPE(MinPSamplingFromProbsInferShape)) | ||
.SetInferDtypeFn(PD_INFER_DTYPE(MinPSamplingFromProbsInferDtype)); |
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 |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
from fastdeploy.model_executor.layers.sample.meta_data import SamplingMetadata | ||
from fastdeploy.model_executor.layers.sample.ops import ( | ||
apply_penalty_multi_scores, apply_speculative_penalty_multi_scores, | ||
top_k_top_p_sampling) | ||
min_p_sampling, top_k_top_p_sampling) | ||
from fastdeploy.platforms import current_platform | ||
from fastdeploy.worker.output import LogprobsTensors, SamplerOutput | ||
|
||
|
@@ -176,6 +176,7 @@ def __init__(self): | |
self.forward = self.forward_cuda | ||
else: | ||
raise NotImplementedError() | ||
self.step=0 | ||
|
||
self.processor = SamplerProcessor() | ||
|
||
|
@@ -251,6 +252,7 @@ def forward_cuda( | |
|
||
logits = self.processor.apply_token_mask(logits, skip_idx_list) | ||
|
||
|
||
logits = apply_penalty_multi_scores( | ||
sampling_metadata.pre_token_ids, | ||
sampling_metadata.prompt_ids, | ||
|
@@ -268,6 +270,8 @@ def forward_cuda( | |
|
||
probs = F.softmax(logits) | ||
|
||
probs= min_p_sampling(probs,sampling_metadata.min_p) | ||
|
||
_, next_tokens = top_k_top_p_sampling(probs, sampling_metadata.top_p, sampling_metadata.top_k) | ||
|
||
logprobs_tensors = None if num_logprobs is None else \ | ||
|
@@ -282,6 +286,7 @@ def forward_cuda( | |
sampled_token_ids=next_tokens, | ||
logprobs_tensors=logprobs_tensors, | ||
) | ||
self.step+=1 | ||
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. delete it |
||
return sampler_output | ||
|
||
|
||
|
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.
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.
pre-commit all files
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.
咱们的pre-commit失效了吗