Repository navigation
[serve][llm] Enable LoRA for direct streaming aggregated and PD disaggregated deployments - #65680
Conversation
There was a problem hiding this comment.
Code Review
This pull request implements support for LoRA multiplexing with direct streaming in Ray Serve, ensuring that requested adapter IDs are properly parsed, validated, and propagated across routing components (including prefill/decode engines and HAProxy). The feedback suggests two key improvements: implementing a FIFO eviction policy on the _multiplexed_handles cache in LLMRouter to prevent unbounded memory growth, and wrapping the multiplexed_model_id_headers loop in the HAProxy Jinja2 template with an existence check to avoid potential rendering errors.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
6bbd31f to
80c624f
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 80c624f. Configure here.
4cfa574 to
af73301
Compare
3f7b5b9 to
7def60f
Compare
) ## Description - Enable model multiplexing for direct-ingress deployments over both HTTP and gRPC. - Remove the deployment-time and runtime rejections that prevented a multiplexed direct-ingress app from running. - At the direct ASGI entry point, recognize both `serve_multiplexed_model_id` and proxy-normalized `serve-multiplexed-model-id`, then store the value in `RequestMetadata.multiplexed_model_id`. - At the direct gRPC entry point, read `multiplexed_model_id` from gRPC invocation metadata and store it in `RequestMetadata.multiplexed_model_id`. ### Client usage ```python # HTTP response = httpx.get( direct_ingress_url, headers={"serve_multiplexed_model_id": "multiplex-model-id"}, ) ``` ```python # gRPC response = stub.Method2( request, metadata=( ("application", "default"), ("multiplexed_model_id", "multiplex-model-id"), ), ) ``` ## Related issues Stack: This PR -> #65679 -> #66170 -> #65680 -> `KVAwareRouter` LoRA support. ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. --------- Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
…coverage Signed-off-by: Jeffrey Wang <[email protected]>
Signed-off-by: Jeffrey Wang <[email protected]>
fc700fd to
25ad726
Compare
## Problem `choose_replica(_reserve=False)` previously called the routing policy once and failed if it returned no candidates. Multiplexed routing can temporarily return no candidates while model-location metadata propagates, even when eligible replicas exist. Through an ingress request router, this becomes a client-visible HTTP 503. ## Solution Reuse the existing selection retry loop with the same pending request so the policy can fall back to an eligible replica. Selection still skips capacity reservations and queue-length probes. Explicitly close the generator to clean up its backoff accounting on success and cancellation. Add a Serve-only HAProxy integration test emulating Serve LLM's separate ingress router: select a backend replica with a multiplexed handle and `_reserve=False`, then return its endpoint for HAProxy to forward the original request. Hold the model-location index empty and require two requests to succeed without client retries. ## Implication for LLM applications When a LoRA adapter first loads, there’s a delay before its location propagates through the controller to the router. An immediate subsequent request can fail because the router [remembers](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/serve/_private/request_router/request_router.py#L331) that an earlier request was sent to a replica to load the adapter, but it has not yet received metadata identifying a replica hosting it. In this state, the multiplexed policy returns no candidates on the new request’s first selection attempt. The old `_reserve=False` [path](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/llm/_internal/serve/core/ingress/router.py#L314-L319) fails immediately instead of retrying, producing HTTP 503. With the retry mechanism, selection runs again using the same pending request, preserving its fallback state. The policy can then select an eligible replica even before the metadata arrives, so this propagation delay alone no longer causes a client-visible failure. ## Stack #65678 → #65679 → this PR → #65680 --------- Signed-off-by: Jeffrey Wang <[email protected]>
# Conflicts: # release/release_tests.yaml
## Why The current 256 KiB cap truncates the router copy of large LLM requests, causing body-aware routing to lose information. Several recent routing changes depend on this body: - [#64224](#64224), [#64328](#64328), and [#65095](#65095) use it for KV-aware routing. - [#65680](#65680) uses it for LoRA model selection. - [#66258](#66258) and [#66315](#66315) use it for deployment-aware, multi-model direct streaming. - [#63183](#63183) introduced the body-forwarding gate shared by these paths. This PR raises the default buffer to 8 MiB and lowers the default `maxconn` to 4,096. The sizing and behavior were verified with a real HAProxy 2.8.25 test and against the bundled HAProxy source code. Both settings retain their existing environment-variable overrides. | Consideration | Result | |---|---| | Request size | A one-million-token English request is commonly estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves 2.28 MiB (~40%) headroom. | | Latency | Requests below 256 KiB do not wait longer. Requests from 256 KiB to 8 MiB now wait for the complete body before routing. | | Memory | Buffers are allocated dynamically. A live stream can use roughly 16 MiB across request and response buffers. Lowering `maxconn` from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB to 64 GiB. | ## Changes - Raise `RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE` from 256 KiB to 8 MiB. - Lower `RAY_SERVE_HAPROXY_MAXCONN` from 20,000 to 4,096. - Test a 6,000,014-byte, million-token-sized request end to end. - Derive rendered-config assertions from their constants so environment overrides remain testable. - Update the KV-aware routing guide. ## Tests - Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly passed. - HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using bundled HAProxy 2.8.25. This does not duplicate the related PRs: they introduce or consume body-aware routing, while this PR increases the shared buffer default and tests a million-token-sized body. AI assistance was used to implement and validate this change; the submitter reviewed every changed line. --------- Signed-off-by: Seiji Eicher <[email protected]> Signed-off-by: Seiji Eicher <[email protected]>
…ject#66170) ## Problem `choose_replica(_reserve=False)` previously called the routing policy once and failed if it returned no candidates. Multiplexed routing can temporarily return no candidates while model-location metadata propagates, even when eligible replicas exist. Through an ingress request router, this becomes a client-visible HTTP 503. ## Solution Reuse the existing selection retry loop with the same pending request so the policy can fall back to an eligible replica. Selection still skips capacity reservations and queue-length probes. Explicitly close the generator to clean up its backoff accounting on success and cancellation. Add a Serve-only HAProxy integration test emulating Serve LLM's separate ingress router: select a backend replica with a multiplexed handle and `_reserve=False`, then return its endpoint for HAProxy to forward the original request. Hold the model-location index empty and require two requests to succeed without client retries. ## Implication for LLM applications When a LoRA adapter first loads, there’s a delay before its location propagates through the controller to the router. An immediate subsequent request can fail because the router [remembers](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/serve/_private/request_router/request_router.py#L331) that an earlier request was sent to a replica to load the adapter, but it has not yet received metadata identifying a replica hosting it. In this state, the multiplexed policy returns no candidates on the new request’s first selection attempt. The old `_reserve=False` [path](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/llm/_internal/serve/core/ingress/router.py#L314-L319) fails immediately instead of retrying, producing HTTP 503. With the retry mechanism, selection runs again using the same pending request, preserving its fallback state. The policy can then select an eligible replica even before the metadata arrives, so this propagation delay alone no longer causes a client-visible failure. ## Stack ray-project#65678 → ray-project#65679 → this PR → ray-project#65680 --------- Signed-off-by: Jeffrey Wang <[email protected]>
…t#66360) ## Why The current 256 KiB cap truncates the router copy of large LLM requests, causing body-aware routing to lose information. Several recent routing changes depend on this body: - [ray-project#64224](ray-project#64224), [ray-project#64328](ray-project#64328), and [ray-project#65095](ray-project#65095) use it for KV-aware routing. - [ray-project#65680](ray-project#65680) uses it for LoRA model selection. - [ray-project#66258](ray-project#66258) and [ray-project#66315](ray-project#66315) use it for deployment-aware, multi-model direct streaming. - [ray-project#63183](ray-project#63183) introduced the body-forwarding gate shared by these paths. This PR raises the default buffer to 8 MiB and lowers the default `maxconn` to 4,096. The sizing and behavior were verified with a real HAProxy 2.8.25 test and against the bundled HAProxy source code. Both settings retain their existing environment-variable overrides. | Consideration | Result | |---|---| | Request size | A one-million-token English request is commonly estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves 2.28 MiB (~40%) headroom. | | Latency | Requests below 256 KiB do not wait longer. Requests from 256 KiB to 8 MiB now wait for the complete body before routing. | | Memory | Buffers are allocated dynamically. A live stream can use roughly 16 MiB across request and response buffers. Lowering `maxconn` from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB to 64 GiB. | ## Changes - Raise `RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE` from 256 KiB to 8 MiB. - Lower `RAY_SERVE_HAPROXY_MAXCONN` from 20,000 to 4,096. - Test a 6,000,014-byte, million-token-sized request end to end. - Derive rendered-config assertions from their constants so environment overrides remain testable. - Update the KV-aware routing guide. ## Tests - Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly passed. - HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using bundled HAProxy 2.8.25. This does not duplicate the related PRs: they introduce or consume body-aware routing, while this PR increases the shared buffer default and tests a million-token-sized body. AI assistance was used to implement and validate this change; the submitter reviewed every changed line. --------- Signed-off-by: Seiji Eicher <[email protected]> Signed-off-by: Seiji Eicher <[email protected]>
|
Release tests skipping concurrency groups: https://buildkite.com/ray-project/release/builds/108266/table |
|
Hmm really struggling at acquiring 4xL4 nodes to pass release tests :( |
…-project#65678) ## Description - Enable model multiplexing for direct-ingress deployments over both HTTP and gRPC. - Remove the deployment-time and runtime rejections that prevented a multiplexed direct-ingress app from running. - At the direct ASGI entry point, recognize both `serve_multiplexed_model_id` and proxy-normalized `serve-multiplexed-model-id`, then store the value in `RequestMetadata.multiplexed_model_id`. - At the direct gRPC entry point, read `multiplexed_model_id` from gRPC invocation metadata and store it in `RequestMetadata.multiplexed_model_id`. ### Client usage ```python # HTTP response = httpx.get( direct_ingress_url, headers={"serve_multiplexed_model_id": "multiplex-model-id"}, ) ``` ```python # gRPC response = stub.Method2( request, metadata=( ("application", "default"), ("multiplexed_model_id", "multiplex-model-id"), ), ) ``` ## Related issues Stack: This PR -> ray-project#65679 -> ray-project#66170 -> ray-project#65680 -> `KVAwareRouter` LoRA support. ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. --------- Signed-off-by: Jeffrey Wang <[email protected]>
…#65679) ## Description Enable `RoundRobinRouter` to use `MultiplexMixin` for requests with a multiplexed model ID. Replica selection proceeds as follows: 1. Serve provides the currently viable candidate replicas. 2. `apply_multiplex_routing()` first selects replicas already hosting the requested model. This warm tier uses a per-model round-robin cursor. 3. If no host is known, or those hosts were already attempted, it selects replicas with the fewest loaded models. This fallback uses the shared cursor. 4. After the matching timeout, it tries fewest-model replicas once more, then all replicas, using the shared cursor. 5. The router intersects the selected tier with viable candidates and applies round-robin ordering. Non-multiplexed requests retain existing shared-cursor round-robin behavior. ### Why `ConsistentHashRouter` is skipped? Model multiplexing and consistent hashing can place conflicting constraints on replica selection. Model multiplexing limits the candidates to replicas that have the requested model loaded, while consistent hashing maps a request to a specific replica. The problem is that the hashed replica may not be one of the replicas with that model loaded. Since it is unclear which constraint should take priority, we deliberately do not support model multiplexing with `ConsistentHashRouter`. ## Related issues Stack: ray-project#65678 -> this PR -> ray-project#66170 -> ray-project#65680 -> `KVAwareRouter` LoRA support. --------- Signed-off-by: Jeffrey Wang <[email protected]>
…ject#66170) ## Problem `choose_replica(_reserve=False)` previously called the routing policy once and failed if it returned no candidates. Multiplexed routing can temporarily return no candidates while model-location metadata propagates, even when eligible replicas exist. Through an ingress request router, this becomes a client-visible HTTP 503. ## Solution Reuse the existing selection retry loop with the same pending request so the policy can fall back to an eligible replica. Selection still skips capacity reservations and queue-length probes. Explicitly close the generator to clean up its backoff accounting on success and cancellation. Add a Serve-only HAProxy integration test emulating Serve LLM's separate ingress router: select a backend replica with a multiplexed handle and `_reserve=False`, then return its endpoint for HAProxy to forward the original request. Hold the model-location index empty and require two requests to succeed without client retries. ## Implication for LLM applications When a LoRA adapter first loads, there’s a delay before its location propagates through the controller to the router. An immediate subsequent request can fail because the router [remembers](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/serve/_private/request_router/request_router.py#L331) that an earlier request was sent to a replica to load the adapter, but it has not yet received metadata identifying a replica hosting it. In this state, the multiplexed policy returns no candidates on the new request’s first selection attempt. The old `_reserve=False` [path](https://github.com/ray-project/ray/blob/9634fa77aab2ece9759b380d20d315d4e27c912b/python/ray/llm/_internal/serve/core/ingress/router.py#L314-L319) fails immediately instead of retrying, producing HTTP 503. With the retry mechanism, selection runs again using the same pending request, preserving its fallback state. The policy can then select an eligible replica even before the metadata arrives, so this propagation delay alone no longer causes a client-visible failure. ## Stack ray-project#65678 → ray-project#65679 → this PR → ray-project#65680 --------- Signed-off-by: Jeffrey Wang <[email protected]>
…t#66360) ## Why The current 256 KiB cap truncates the router copy of large LLM requests, causing body-aware routing to lose information. Several recent routing changes depend on this body: - [ray-project#64224](ray-project#64224), [ray-project#64328](ray-project#64328), and [ray-project#65095](ray-project#65095) use it for KV-aware routing. - [ray-project#65680](ray-project#65680) uses it for LoRA model selection. - [ray-project#66258](ray-project#66258) and [ray-project#66315](ray-project#66315) use it for deployment-aware, multi-model direct streaming. - [ray-project#63183](ray-project#63183) introduced the body-forwarding gate shared by these paths. This PR raises the default buffer to 8 MiB and lowers the default `maxconn` to 4,096. The sizing and behavior were verified with a real HAProxy 2.8.25 test and against the bundled HAProxy source code. Both settings retain their existing environment-variable overrides. | Consideration | Result | |---|---| | Request size | A one-million-token English request is commonly estimated at roughly 4 MB. The test request is 5.72 MiB, so 8 MiB leaves 2.28 MiB (~40%) headroom. | | Latency | Requests below 256 KiB do not wait longer. Requests from 256 KiB to 8 MiB now wait for the complete body before routing. | | Memory | Buffers are allocated dynamically. A live stream can use roughly 16 MiB across request and response buffers. Lowering `maxconn` from 20,000 to 4,096 reduces the theoretical buffer ceiling from 320 GiB to 64 GiB. | ## Changes - Raise `RAY_SERVE_HAPROXY_INGRESS_REQUEST_ROUTER_BUFSIZE` from 256 KiB to 8 MiB. - Lower `RAY_SERVE_HAPROXY_MAXCONN` from 20,000 to 4,096. - Test a 6,000,014-byte, million-token-sized request end to end. - Derive rendered-config assertions from their constants so environment overrides remain testable. - Update the KV-aware routing guide. ## Tests - Pre-commit hooks, Python compilation, Serve mypy, and Serve pyrefly passed. - HAProxy end-to-end test passed: 1 passed, 37 deselected in 2.85s using bundled HAProxy 2.8.25. This does not duplicate the related PRs: they introduce or consume body-aware routing, while this PR increases the shared buffer default and tests a million-token-sized body. AI assistance was used to implement and validate this change; the submitter reviewed every changed line. --------- Signed-off-by: Seiji Eicher <[email protected]> Signed-off-by: Seiji Eicher <[email protected]>
…gregated deployments (ray-project#65680) ## Description Enable LoRA multiplexing for direct streaming, including PD deployments. ### How LoRA used to work with non-direct-streaming? For normal, non-direct-streaming requests, `OpenAIIngress` calls `LLMServer.chat()` or `completions()`, which reach `_run_request()` and resolve the requested LoRA before submitting work to vLLM. ### How LoRA now works with direct streaming? Direct streaming instead has the ingress router select a replica, HAProxy proxy the request to that replica’s native vLLM ASGI application, and stream the response back to the client. That path bypasses `LLMServer.chat()`, `completions()`, and `_run_request()`, so LoRA was never resolved. In this PR, - [Fix] Initialize vLLM’s OpenAI serving state once and share it with the native ASGI app. When the LoRA resolver registers an adapter, the `/v1/completions`, `/v1/chat/completions`, and `/v1/models` handlers now see that same adapter registry. - [Test] Add a direct-streaming LoRA test that sends a cold adapter request through HAProxy, verifies the adapter appears in `/v1/models`, and exercises base-model and adapter requests through completions and chat-completions, with and without streaming. - [Config and docs] Require request-body forwarding for direct-streaming multi-LoRA, enable it in the direct-streaming release test job, and document the required settings. - [Existing] For a LoRA-enabled direct-streaming application, `LLMRouter` reads the requested `model` from the forwarded request body. If it belongs to the configured base model, it selects through a multiplexed Serve handle and HAProxy injects the resulting trusted adapter header for the selected replica. - [Existing] `LLMServer` adds a LoRA-resolving ASGI middleware before vLLM handles the request. - [Existing] Serve’s multiplexed loader downloads and caches the adapter lazily on the selected replica. For PD deployments, propagate the multiplexed model ID to the prefill handle and reject incompatible prefill/decode LoRA configuration. ## Related issues Stack: ray-project#65678 -> ray-project#65679 -> ray-project#66170 -> this PR -> `KVAwareRouter` LoRA support ## Additional information > Optional: Add implementation details, API changes, usage examples, screenshots, etc. --------- Signed-off-by: Jeffrey Wang <[email protected]>

Description
Enable LoRA multiplexing for direct streaming, including PD deployments.
How LoRA used to work with non-direct-streaming?
For normal, non-direct-streaming requests,
OpenAIIngresscallsLLMServer.chat()orcompletions(), which reach_run_request()and resolve the requested LoRA before submitting work to vLLM.How LoRA now works with direct streaming?
Direct streaming instead has the ingress router select a replica, HAProxy proxy the request to that replica’s native vLLM ASGI application, and stream the response back to the client. That path bypasses
LLMServer.chat(),completions(), and_run_request(), so LoRA was never resolved.In this PR,
/v1/completions,/v1/chat/completions, and/v1/modelshandlers now see that same adapter registry./v1/models, and exercises base-model and adapter requests through completions and chat-completions, with and without streaming.LLMRouterreads the requestedmodelfrom the forwarded request body. If it belongs to the configured base model, it selects through a multiplexed Serve handle and HAProxy injects the resulting trusted adapter header for the selected replica.LLMServeradds a LoRA-resolving ASGI middleware before vLLM handles the request.For PD deployments, propagate the multiplexed model ID to the prefill handle and reject incompatible prefill/decode LoRA configuration.
Related issues
Stack: #65678 -> #65679 -> #66170 -> this PR ->
KVAwareRouterLoRA supportAdditional information