Repository navigation
[Serve] Route multiplexed requests by an ordered candidate model ID list - #67400
rahulmansharamani14 wants to merge 6 commits into
Conversation
Add `candidate_multiplexed_model_ids`, an ordered tuple of acceptable model
IDs, to the handle options and `RequestMetadata`.
`get_request_metadata` resolves the list to the caller's first choice, because
the replica-side multiplexing API takes a single model ID. Routers that don't
understand candidate lists, including the default router, then behave as if
that ID had been passed alone and need no changes.
EOFgit add python/ray/serve/_private/handle_options.py \
python/ray/serve/_private/common.py \
python/ray/serve/_private/default_impl.py \
python/ray/serve/tests/unit/test_request_metadata.py \
python/ray/serve/tests/unit/test_default_impl.py
git commit -s -F - <<'EOF'
[Serve] Carry candidate multiplexed model IDs through request metadata
Add `candidate_multiplexed_model_ids`, an ordered tuple of acceptable model
IDs, to the handle options and `RequestMetadata`.
`get_request_metadata` resolves the list to the caller's first choice, because
the replica-side multiplexing API takes a single model ID. Routers that don't
understand candidate lists, including the default router, then behave as if
that ID had been passed alone and need no changes.
Signed-off-by: rahulmansharamani14 <[email protected]>
…tions Validate and normalize the caller's list, rejecting non-strings, empty IDs and duplicates. Setting either `multiplexed_model_id` or `candidate_multiplexed_model_ids` clears the other, so a chained `options()` call can't combine two conflicting routing instructions. Passing both in one call raises. Signed-off-by: rahulmansharamani14 <[email protected]>
Rank replicas by an ordered candidate list so custom routers don't reimplement it against private mixin state. A router using it must write the matched candidate back to `RequestMetadata.multiplexed_model_id`. Signed-off-by: rahulmansharamani14 <[email protected]>
Add an end-to-end test with a custom router that serves a warm later candidate instead of cold-loading the caller's first choice, and document the helper in the custom request router guide. Signed-off-by: rahulmansharamani14 <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces support for candidate_multiplexed_model_ids in Ray Serve, allowing requests to specify an ordered list of acceptable multiplexed model IDs. This enables custom request routers to select a warm model replica from the candidates and avoid cold-start latencies. The changes include updates to request metadata, handle options, routing logic, documentation, and comprehensive unit and end-to-end tests. The review feedback focuses on improving type annotations to support both lists and tuples, updating error messages to reflect this flexibility, and fixing a logical bug where explicitly clearing multiplexed_model_id to an empty string fails to clear the candidate model IDs.
|
Routers only rank replicas. The router picks the served candidate once the replica is known, on every send path. Also accept tuples in the type hints, clear the candidates when multiplexed_model_id is set to an empty string, make rank_replicas_via_multiplex delegate to the candidates helper, and skip the custom-router end-to-end tests under HAProxy. Signed-off-by: rahulmansharamani14 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 105f61a. Configure here.
| replica = await self._active_request_router._choose_replica_for_request( | ||
| pr, is_retry=is_retry | ||
| ) | ||
| self._resolve_multiplexed_model_id(pr.metadata, replica) |
There was a problem hiding this comment.
Retry desyncs FIFO multiplex model index
Medium Severity
_resolve_multiplexed_model_id mutates RequestMetadata.multiplexed_model_id on the reused PendingRequest after a replica is chosen. On rejection, reset_future plus lazy model-index cleanup leave the request under both the original and resolved keys, so FIFO matching can hand it a replica chosen for another model. apply_multiplex_routing on retry also searches for the previously resolved ID instead of the first candidate, including on the default router.
Additional Locations (2)
Reviewed by Cursor Bugbot for commit 105f61a. Configure here.
There was a problem hiding this comment.
Confirmed. Every key the request sits under is one of its own candidates, so it still runs a model it accepts. I proposed resetting the model ID to the first candidate before a retry, and will add it if the reviewer agrees.
|
@johntaylor-cell I addressed all five points in 105f61a and merged master. Point 1 was the real gap. A router cannot know which replica a request ends up on, because Ray skips full replicas after ranking. So I moved the model pick to right after the replica is chosen.
The earlier premerge failure came from my end-to-end test, because HAProxy rejects a custom router on the ingress deployment. I skipped both tests under HAProxy, the same way The two remaining open points, where the pick runs and mutual exclusion, are under "Needs maintainer agreement" in the description. |
|
One open design question on retries. Say a request has I would reset the model ID to the first candidate before a retry, so it routes by |
|
Thanks @rahulmansharamani14. Here are my comments and answer:
|


Description
Today a request can name only one multiplexed model. If the replica it reaches does not have that model loaded, the replica loads it, which is slow, even when the replica already has another model the caller would accept.
This PR lets the caller pass an ordered list of acceptable models instead:
Routing works as before. Once Ray picks a replica, the request runs on the first model in the list that the replica already has, or on the first model if it has none of them.
Related issues
Closes #65348 (design discussion is on the issue thread)
#67095 targets the same issue with a different approach from the one the thread settled on.
Additional information
Key changes
candidate_multiplexed_model_idsoption onDeploymentHandle.options.MultiplexMixin.rank_replicas_via_multiplex_candidateshelper for custom routers.Design decisions
Settled
Needs maintainer agreement
router.py, so it works the same for every router. OK?Out of scope: HTTP and gRPC requests, and local testing mode, which uses the first model.
Testing
choose_replica(),broadcast(), and option validation. The new tests fail without the change.AI assistance
Written with AI assistance (Claude Code). I've reviewed every changed line.