Skip to content

[Serve][5/5] Enable direct streaming with multi-model architecture for Serve LLM applications - #66315

Closed
celinaky wants to merge 12 commits into
celina/direct-http-ingress-aware-routerfrom
celina/direct-http-multi-model-builder
Closed

celinaky wants to merge 12 commits into
celina/direct-http-ingress-aware-routerfrom
celina/direct-http-multi-model-builder

Conversation

@celinaky

@celinaky celinaky commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Why this is needed

The preceding PRs in the stack add deployment-aware direct HTTP routing to Ray Serve. This PR connects those interfaces to the Ray Serve LLM application builder so one application can directly stream from multiple model deployments while retaining a lightweight ingress for control-plane routes such as model discovery.

Summary

  • Add DirectStreamingIngress, a lightweight application ingress that serves:

    • GET /v1/models
    • GET /v1/models/{model}
    • Share model-discovery behavior between OpenAiIngress and DirectStreamingIngress
  • Build one _direct_http=True LLMServer deployment per configured model

  • Pass the model ID → deployment mapping to LLMRouter

  • Extract the control ingress’s FastAPI route patterns at build time and pass them to LLMRouter

  • In HAProxy, route all HTTP methods through the ingress request router so ingress-owned routes receive priority

Application topology:

DirectStreamingIngress
├── LLMServer:model-a _direct_http=True
├── LLMServer:model-b _direct_http=True
└── LLMRouter ingress request router

Inference requests stream directly through the selected model replica. Model-discovery requests are routed to DirectStreamingIngress.

Test plan

  • Added builder unit coverage for the multi-model application graph
  • Added shared model-discovery coverage
  • Added HAProxy coverage for routing non-POST requests
  • Added end-to-end multi-model routing and streaming coverage
  • git diff --check
  • Repo formatting, lint, type-check, and commit hooks

To Do

  • Review all tests, written by claude
  • Benchmark results

Example usage

Set the feature flags before importing Ray Serve LLM, then build a normal multi-model application. The builder creates the lightweight discovery ingress, marks each model deployment _direct_http=True, and wires the deployment-aware router:

import os

os.environ["RAY_SERVE_ENABLE_HA_PROXY"] = "1"
os.environ["RAY_SERVE_LLM_ENABLE_DIRECT_STREAMING"] = "1"
os.environ["RAY_SERVE_INGRESS_REQUEST_ROUTER_FORWARD_BODY"] = "1"

from openai import OpenAI
from ray import serve
from ray.serve.llm import LLMServingArgs, build_openai_app

llm_configs = [
    {
        "model_loading_config": {
            "model_id": "qwen-0.5b",
            "model_source": "Qwen/Qwen2.5-0.5B-Instruct",
        },
        "accelerator_type": "A10G",
    },
    {
        "model_loading_config": {
            "model_id": "qwen-1.5b",
            "model_source": "Qwen/Qwen2.5-1.5B-Instruct",
        },
        "accelerator_type": "A10G",
    },
]

app = build_openai_app(LLMServingArgs(llm_configs=llm_configs))
serve.run(app)

client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")

# Served by DirectStreamingIngress.
print([model.id for model in client.models.list().data])

# Routed directly to a replica of LLMServer:qwen-1.5b.
stream = client.chat.completions.create(
    model="qwen-1.5b",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@celinaky
celinaky added this pull request to stack #66257 September 19, 2026 05:30
@celinaky
celinaky force-pushed the celina/direct-http-multi-model-builder branch from fe220c5 to 1db1aa2 Compare September 19, 2026 05:51
@celinaky celinaky changed the title [Serve][5/N] Enable direct streaming with multi-model architecture for Serve LLM applications [Serve][5/5] Enable direct streaming with multi-model architecture for Serve LLM applications Sep 19, 2026
@celinaky
celinaky force-pushed the celina/direct-http-multi-model-builder branch from e4bc894 to 1320c85 Compare September 19, 2026 10:13
celinaky and others added 12 commits September 21, 2026 06:34
…r random helper functions, needs review

Signed-off-by: Celina Yang <[email protected]>
…imodel yet, needs follow up

Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
- test_model_discovery.py: drop the _ModelDiscovery cases already pinned
  through OpenAiIngress by test_lora_deployment_base_client.py, the
  structural checks (hasattr, deepcopy, check_health) and the docs-route
  cases implied by the exact route-inventory test.
- test_builder_ingress.py: hoist the direct-streaming fixture and the
  second-model helper to module level, compare the router's routes to what
  the control ingress declares instead of a literal copy, and parametrize
  the ingress config and KV-aware llm_config cases.
- test_multi_model_direct_streaming.py: keep one observation per behavior
  (discovery to the ingress, chat and streaming to the named model,
  unresolvable model fails closed); drop the repeats and the single-model
  class already covered by test_router_direct_streaming.py.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Celina Yang <[email protected]>
@celinaky
celinaky force-pushed the celina/direct-http-multi-model-builder branch from 1320c85 to b522338 Compare September 21, 2026 06:49
@eicherseiji eicherseiji added the go add ONLY when ready to merge, run all tests label Sep 22, 2026
eicherseiji added a commit that referenced this pull request Sep 22, 2026
## 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]>
owenowenisme pushed a commit to owenowenisme/ray that referenced this pull request Sep 23, 2026
…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]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…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]>
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

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.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Oct 7, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants