fix(infer): complete streamed requests independently within batches - #10177
Open
taking-lying-flat wants to merge 3 commits into
Open
taking-lying-flat wants to merge 3 commits into
taking-lying-flat wants to merge 3 commits into
Conversation
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.
PR type
PR information
When one request finishes before other requests in a Transformers streaming batch, its final event waits for the entire batch:
_infer_stream()removes PAD tokens before checking whether the last token is PAD. Additionally, the worker forwards missing chunks asNone, which the async consumer interprets as end-of-stream and can close a request before its final event arrives.Detect completion from generated EOS IDs and template stop words before cleaning token IDs. Keep independent stop-word state for the consumer because generation runs ahead in another thread. Exclude the initial streamed prompt from completion detection and token counts, and preserve a terminating EOS when it shares its ID with PAD. A normal PAD does not end a request. Reuse existing batch-end handling for length-limit completion.
Skip missing chunks in the worker and close each async stream after its final response. Existing per-request completion flags prevent duplicate final events and tool-call parsing. Production changes are confined to
transformers_engine.py.Fix existing worker-test cleanup to stop its background loop before closing it and handle intentional test-worker shutdown cleanly. The PR modifies only existing files.
Experiment results
python -m pytest tests/infer/test_prompt_usage.py tests/infer/test_transformers_worker.py -q: 11 tests and 20 subtests passed, with no deselected tests.generate()implementation using a small randomly initialized GPT-2 model and deterministic logits on CPU.git diff --checkpassed.No deployed-service latency benchmark was run.