Repository navigation
Conversation
…of aborting TurboMind's top-k kernel supports k <= 1024. A larger top_k reached invokeTopKSortFilter, which threw std::domain_error on the engine thread; nothing catches it there, so the whole api_server process aborted. Reject such a top_k before the request reaches the engine: the OpenAI endpoints return 400, and TurboMindInstance raises ValueError for any other caller (e.g. the pipeline API).
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 TurboMind backend (the default), one request with
top_kabove 1024 aborts the wholeapi_serverprocess.Repro on the released lmdeploy 0.18.0 (
lmdeploy serve api_server Qwen/Qwen3-0.6B --backend turbomind):Server log:
The API only checks
top_k >= -1.invokeTopKSortFilterthrowsstd::domain_errorfork > 1024. That happens on the engine thread, where nothing catches it, sostd::terminatebrings down the process.Modification
lmdeploy/messages.py: newTURBOMIND_MAX_TOP_K = 1024, the kernel limit.serve/openai/endpoints/common.py(validate_request, shared by/v1/chat/completions,/v1/completionsand/generate): with a TurboMind engine, a largertop_know gets a 400 with a clear message. The PyTorch backend is unchanged.turbomind/turbomind.py:_get_generation_configraisesValueErrorfor such atop_kbefore the request reaches the engine. This also covers other callers, such as the pipeline API or endpoints that do not usevalidate_request. For those, the request fails and the server keeps running.Tests
tests/test_lmdeploy/serve/openai/test_turbomind_top_k.py. It checks that chat and completion requests get a 400 above the limit and pass at the limit, that the PyTorch engine config is not affected, and thatTurboMindInstanceraisesValueError. That last test is skipped when the TurboMind extension is not built.tests/test_lmdeploy/serve/openai,test_messages.pyandserve/test_generation_config.py: 661 passed. The 2 failures inresponses/test_serving.py::test_trace_keeps_oversized_terminal_response_successalso fail on main without this change.ruff checkis clean.top_k=2000returns400 The top_k 2000 must not exceed 1024 with the TurboMind backend., the next normal request still succeeds, andtop_k=1024works as before.Related: #5250 fixes the PyTorch-backend counterpart (
top_klarger than the vocabulary).