Repository navigation
[Fix] Disable top-k filtering by default - #5079
Merged
silencelamb merged 4 commits intoNov 3, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The loader discards explicitly configured top_k=50 as a default value, causing requests that omit top_k to fall back to 0 and unintentionally disable top-k filtering.
1 open issue
What changed in this PR
This PR removes implicit top-50 truncation from LMDeploy’s generation defaults, making omitted top_k disable filtering.
Changes:
- Change
GenerationConfig.top_kfrom50to0. - Document that
0disables top-k filtering. - Add regression cases for fallback behavior and model/request overrides, including explicit
0.
| File | Description |
|---|---|
tests/test_lmdeploy/serve/test_generation_config.py |
Add parameterized tests for top-k fallback and override precedence. |
lmdeploy/messages.py |
Set the top-k default to 0 and document its meaning. |
Review effort: Balanced
silencelamb
reviewed
Oct 31, 2026
silencelamb
approved these changes
Nov 2, 2026
silencelamb
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Explicit top_k values are preserved, and null generation defaults are correctly treated as unset. Both review concerns are resolved.
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 neither the request nor the model’s
generation_config.jsonspecifiestop_k, LMDeploy falls back to50. Callers can easily specify onlytemperatureandtop_pand overlook this additional truncation, leading to unintended sampling differences across serving engines.Other engines default to no top-k filtering when no value is supplied:
top_k=0.top_k=-1.For example, with model defaults
{"temperature": 1.0, "top_p": 0.95}, omittingtop_kcurrently introduces a top-50 restriction in LMDeploy. This PR removes that implicit restriction.Modification
GenerationConfig.top_kfrom50to0, the existing value for disabling top-k filtering.top_k=50in Transformers 4.x). Absent fields still fall back to LMDeploy defaults.nullgeneration defaults as unset, preserving explicit values such as0andtop_k=50.Compatibility
Sampled outputs may change when
top_kis omitted from both the effective defaults and the request. Users can explicitly settop_k=50to retain the previous behavior.Model/server defaults and request overrides retain their existing precedence. Greedy decoding is unaffected.
Validation
top_k,top_p,temperature, andmin_p; zero values; mixed null/non-null defaults; and files exported viato_dict()andto_json_file(..., use_diff=False).top_k=50and request override coverage remain passing.