[BugFix][DataProcessor] Force top_k=1 for greedy decoding when temperature=0#6748
Open
gongweibao wants to merge 2 commits intoPaddlePaddle:developfrom
Open
[BugFix][DataProcessor] Force top_k=1 for greedy decoding when temperature=0#6748gongweibao wants to merge 2 commits intoPaddlePaddle:developfrom
gongweibao wants to merge 2 commits intoPaddlePaddle:developfrom
Conversation
|
gongweibao seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Thanks for your contribution! |
b687f34 to
d4ec7c5
Compare
When temperature is set to 0 (greedy decoding), only setting temperature to a small epsilon is insufficient — the sampling kernel may still pick non-top-1 tokens. Explicitly set top_k=1 in all processors to guarantee argmax behavior. Additionally, add argmax fast-path in top_k_top_p_sampling() under FD_DETERMINISTIC_MODE to handle non-rejection sampling backends that ignore top_k parameter.
d4ec7c5 to
4372539
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6748 +/- ##
==========================================
Coverage ? 71.94%
==========================================
Files ? 392
Lines ? 53903
Branches ? 8476
==========================================
Hits ? 38779
Misses ? 12348
Partials ? 2776
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
top_k=1 → argmax is a correctness optimization, not deterministic-specific. Remove the FD_DETERMINISTIC_MODE guard so all-greedy fast-path and mixed-batch override work unconditionally. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation
When
temperature=0(greedy decoding), the current code only sets temperature to a small epsilon (1e-06). However, this is insufficient — the sampling kernel may still pick non-top-1 tokens due to floating-point noise in the softmax output. This causes non-deterministic outputs for greedy decoding requests.This PR explicitly sets
top_k=1alongside the temperature epsilon to guarantee argmax behavior.Modifications
fastdeploy/engine/engine.py: Addsampling_params.top_k = 1whentemperature ≈ 0.fastdeploy/input/text_processor.py: Addtop_k=1in bothprocess_requestand_process_requestpaths.fastdeploy/input/v1/text_processor.py: Same as above for v1 processor.fastdeploy/input/ernie4_5_processor.py: Same as above for Ernie4.5 processor.tests/input/test_text_processor.py: Addtop_k=1assertion in existing greedy decoding tests.Usage or Command
No new usage. Existing requests with
temperature=0will now automatically usetop_k=1for true greedy decoding.Accuracy Tests
This is a sampling parameter fix, not a kernel/model change. The fix ensures greedy decoding always selects the top-1 token, which is the expected behavior when
temperature=0.Checklist
[BugFix],[Engine],[DataProcessor]pre-commitbefore commit.tests/input/test_text_processor.pyupdated.releasebranch, make sure the PR has been submitted to thedevelopbranch. (N/A — targetingdevelop)