Repository navigation
Conversation
A request with top_k larger than the vocabulary made torch.topk raise "selected index k out of range" inside the engine loop, which stopped the engine: that request and every later one failed with 503. A top_k at or above the vocabulary size keeps every token, so take the full-sort path for it, as for top_k <= 0.
This branch has not been deployed
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
With the PyTorch backend, one request with
top_klarger than the vocabulary stops the engine. That request and every later one get503 The inference engine is unavailableuntil the server restarts.Repro on the released lmdeploy 0.18.0 (
lmdeploy serve api_server Qwen/Qwen3-0.6B --backend pytorch):Server log:
check_requestonly enforcestop_k >= -1.FusedLogitsProcessor._filter_sorted_logitsthen passes the batch maximum totorch.topk, which raises whenkis larger than the vocabulary. The error is raised inside the engine loop, so it takes the engine down.Modification
A
top_kat or above the vocabulary size keeps every token. It now goes down the same full-sort path astop_k <= 0. The per-rowtop_kmask still applies, so in a mixed batch the other rows keep their owntop_k.Tests
test_filter_logits_top_k_larger_than_vocabintests/pytorch/engine/test_logits_process.py. It fails on main withRuntimeError: selected index k out of rangeand passes with this change. It covers a batch where every row is over the limit and a mixed batch (top_k=[1, 8]over 3 tokens).tests/pytorch/engine/test_logits_process.pyandtests/test_lmdeploy/serve/test_generation_config.pypass.ruff checkis clean.top_k=1000000andtop_k=40000requests return normal completions, and later requests still succeed.