Fix ray mp duplicate output - #4833
Open
RunningLeon wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Ray MP streaming edge case where the final EngineOutput could be yielded twice (once when produced, and again when the stream task terminates), resulting in duplicated final token output to callers.
Changes:
- Track whether the stream produced any output and avoid replaying an already-consumed terminal
EngineOutputwhen the remote async generator finishes. - Clear the per-stream pending slot after a consumer reads an item so the stream task can detect “already consumed” terminal output.
- Add unit tests covering: (1) no duplicate final output after cleanup delay, (2) final output returned once when unconsumed, (3) failure-before-first-yield returns
INTERNAL_ENGINE_ERROR.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/pytorch/engine/test_ray_mp_engine.py | Adds regression tests to ensure Ray MP streaming does not duplicate the final output and preserves error behavior. |
| lmdeploy/pytorch/engine/mp_engine/ray_engine.py | Adjusts stream task finalization and consumption tracking to prevent repeating already-consumed terminal outputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lvhan028
reviewed
Aug 6, 2026
| init_event.set() | ||
| self._stream_aiter[stream_id][1] = (result, True) | ||
| stream_out = self._stream_aiter[stream_id] | ||
| pending = stream_out[1] |
Collaborator
There was a problem hiding this comment.
Is it possible that stream_out[1] is out of index?
Collaborator
There was a problem hiding this comment.
we need to find a way to deal with these magic index in the future. Another example is the following terminal_result = pending[0] cc @grimoire
grimoire
approved these changes
Aug 6, 2026
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
Fix ray mp duplicate output
Modification
Please briefly describe what modification is made in this PR.
BC-breaking (Optional)
Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
Use cases (Optional)
If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.
Checklist