Repository navigation
[BugFix] Honour include_logprobs_decode_token in the /v1 chat logprobs path - #8130
Open
MincongZhou wants to merge 1 commit into
Open
MincongZhou wants to merge 1 commit into
MincongZhou wants to merge 1 commit into
Conversation
…s path The switch was added for the chat logprobs path by PaddlePaddle#5463, whose contract is that when it is disabled "the token and bytes fields in the logprobs result are empty". Its diff gates detokenization in fastdeploy/entrypoints/openai/serving_chat.py, but adds nothing under fastdeploy/entrypoints/openai/v1/. The v1 servicer is a hand-maintained copy (it extends OpenAiServingBase rather than the legacy class), so neither _create_chat_logprobs nor _build_logprobs_response ever received the flag and detokenization ran unconditionally: a client sending include_logprobs_decode_token=false still got populated token/bytes on every entry, and still paid the detokenization cost it had opted out of - once per candidate token per generated token per choice. The same request body produced different response documents depending on FD_ENABLE_ASYNC_LLM. Thread the request field through both helpers and their four call sites, reusing the legacy gate verbatim.
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
include_logprobs_decode_tokenis honoured on the legacy chat path and silently ignored on the/v1(async) path.Correct side --
fastdeploy/entrypoints/openai/serving_chat.py:958-967gates detokenization:Divergent side --
fastdeploy/entrypoints/openai/v1/serving_chat.py: neither_create_chat_logprobs(:103) nor_build_logprobs_response(:132) took the flag, and:165-173detokenized unconditionally. This is not inheritance: the v1 class extendsOpenAiServingBase, so it is a hand-maintained copy that never received the gate.The contract comes from the PR that introduced the switch (#5463): for
v1/chat/completions, when it is disabled "the token and bytes fields in the logprobs result are empty". That PR's seven changed files contain nothing underentrypoints/openai/v1/.Consequence: a client sending
include_logprobs_decode_token: falsegets populatedtokenandbyteson every entry anyway, and still pays the detokenization it opted out of -- once per candidate token, per generated token, per choice. The same request body returns different response documents depending onFD_ENABLE_ASYNC_LLM=0versus=1.Modifications
One file, +27/-10:
fastdeploy/entrypoints/openai/v1/serving_chat.py.request_decode_flag: Optional[bool] = Trueis added to_create_chat_logprobsand_build_logprobs_response, and forwarded from the former to the latter.token_str = ""/token_bytes = []on the disabled branch.The default is
Truein both signatures, so every existing caller keeps its behaviour.Usage or Command
Directly:
The three added cases are
test_build_logprobs_response_skips_decoding_when_disabled,test_build_logprobs_response_decodes_by_defaultandtest_create_chat_logprobs_forwards_the_decode_flag.To reproduce the divergence at the builder level, the real
_build_logprobs_responsefrom each module was extracted withastand executed against a stubbeddata_processor, for the sameinclude_logprobs_decode_token=Falserequest:Lint on the repository's configured settings (black line-length 119, ruff 119 with
pyproject.toml, flake8): all exit 0 on both changed files, and both are lint-clean before and after.Not verified here: I could not import
fastdeployin this environment (paddleis not installable), sotests/entrypoints/openai/v1/test_serving_chat_v1.pycannot be collected locally and I have not run it. The executed probe works at the level of the two builders and their signatures, not through a live server. CI will be the first real run of the added test.Accuracy Tests
Not applicable -- this does not change the kernels or the model forward path, only whether a response field is detokenized. No model outputs are affected; with the default (
True) the emitted bytes are identical to today's.Checklist
[BugFix].pre-commitbefore commit.black/ruff/flake8at the repository's line length (119); all clean.tests/entrypoints/openai/v1/test_serving_chat_v1.py.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.develop.Scope note: the completion path is deliberately untouched
include_logprobs_decode_tokenis absent from_build_logprobs_responseinv1/serving_completion.pyand also from its legacy twinserving_completion.py:909-941. Since both sides agree, that is not a divergence, and adding a gate there would make the two differ -- a separate feature rather than this fix. (The switch is plumbed in the legacy completion prompt-logprobs path at:534/:780/:993, which is a different code path.)Competition
ghsearch over issues and PRs (all states) forinclude_logprobs_decode_token: 2 results, #5463 (the merged PR that introduced the switch, i.e. the spec) and #6934 (merged, unrelated).process_logprob_responsereturns one merged PR, #7658, which fixed a different defect (a missing attribute onMultiModalProcessor). None of the 24 open logprobs PRs touchesv1/serving_chat.py.