Skip to content

[BugFix] Honour include_logprobs_decode_token in the /v1 chat logprobs path - #8130

Open
MincongZhou wants to merge 1 commit into
PaddlePaddle:developfrom
MincongZhou:fix/v1-chat-logprobs-decode-flag
Open

MincongZhou wants to merge 1 commit into
PaddlePaddle:developfrom
MincongZhou:fix/v1-chat-logprobs-decode-flag

Conversation

@MincongZhou

@MincongZhou MincongZhou commented Oct 8, 2026 •

Copy link
Copy Markdown

Motivation

include_logprobs_decode_token is honoured on the legacy chat path and silently ignored on the /v1 (async) path.

Correct side -- fastdeploy/entrypoints/openai/serving_chat.py:958-967 gates detokenization:

for tid, lp in zip(topk_token_ids, topk_logprobs):
    if request_decode_flag:
        token_str = self.engine_client.data_processor.process_logprob_response(
            [tid], clean_up_tokenization_spaces=False
        )
        token_bytes = token_str.encode("utf-8", errors="replace")
        if "\ufffd" in token_str:
            token_str = "bytes:" + "".join(f"\\x{byte:02x}" for byte in token_bytes)
    else:
        token_str = ""
        token_bytes = []
    entry = LogProbEntry(token=token_str, logprob=lp, bytes=list(token_bytes))

Divergent side -- fastdeploy/entrypoints/openai/v1/serving_chat.py: neither _create_chat_logprobs (:103) nor _build_logprobs_response (:132) took the flag, and :165-173 detokenized unconditionally. This is not inheritance: the v1 class extends OpenAiServingBase, 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 under entrypoints/openai/v1/.

Consequence: a client sending include_logprobs_decode_token: false gets populated token and bytes on 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 on FD_ENABLE_ASYNC_LLM=0 versus =1.

Modifications

One file, +27/-10: fastdeploy/entrypoints/openai/v1/serving_chat.py.

  • request_decode_flag: Optional[bool] = True is added to _create_chat_logprobs and _build_logprobs_response, and forwarded from the former to the latter.
  • The detokenization block is wrapped in the gate, reused verbatim from the legacy servicer, with token_str = "" / token_bytes = [] on the disabled branch.
  • The request's value is passed at the four call sites (streaming and non-streaming, chosen and draft logprobs).

The default is True in both signatures, so every existing caller keeps its behaviour.

Usage or Command

Directly:

python -m pytest tests/entrypoints/openai/v1/test_serving_chat_v1.py -k "logprobs and (decode or default)" -v

The three added cases are test_build_logprobs_response_skips_decoding_when_disabled, test_build_logprobs_response_decodes_by_default and test_create_chat_logprobs_forwards_the_decode_flag.

To reproduce the divergence at the builder level, the real _build_logprobs_response from each module was extracted with ast and executed against a stubbed data_processor, for the same include_logprobs_decode_token=False request:

upstream develop
  serving_chat.py       (legacy)  token=''       bytes=[]                    detok_calls=0
  v1/serving_chat.py              token=' hello' bytes=[32, 104, 101, ...]   detok_calls=3   <-- divergence

this change
  serving_chat.py       (legacy)  token=''       bytes=[]                    detok_calls=0
  v1/serving_chat.py              token=''       bytes=[]                    detok_calls=0

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 fastdeploy in this environment (paddle is not installable), so tests/entrypoints/openai/v1/test_serving_chat_v1.py cannot 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

  • Add at least a tag in the PR title.
    • Tag used: [BugFix].
  • Format your code, run pre-commit before commit.
    • Ran the configured black/ruff/flake8 at the repository's line length (119); all clean.
  • Add unit tests. Please write the reason in this PR if no unit tests.
    • Three cases added to tests/entrypoints/openai/v1/test_serving_chat_v1.py.
  • Provide accuracy results.
    • Not applicable (see Accuracy Tests above).
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.
    • Targeting develop.

Scope note: the completion path is deliberately untouched

include_logprobs_decode_token is absent from _build_logprobs_response in v1/serving_completion.py and also from its legacy twin serving_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

gh search over issues and PRs (all states) for include_logprobs_decode_token: 2 results, #5463 (the merged PR that introduced the switch, i.e. the spec) and #6934 (merged, unrelated). process_logprob_response returns one merged PR, #7658, which fixed a different defect (a missing attribute on MultiModalProcessor). None of the 24 open logprobs PRs touches v1/serving_chat.py.

…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.
@MincongZhou MincongZhou changed the title fix(v1): honour include_logprobs_decode_token in the /v1 chat logprobs path [BugFix] Honour include_logprobs_decode_token in the /v1 chat logprobs path Oct 8, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant