Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request addresses two main issues: it prevents a ZeroDivisionError in the prefix-aware router when handling empty input text by checking the length of input_text before calculating the match rate, and it fixes an AttributeError in Deployment.eq by returning NotImplemented when comparing a Deployment instance with a non-Deployment object. Unit tests have been added to verify both fixes. No review comments were provided, so there is no additional feedback.
|
Thanks for the approval, @abrarsheikh! The premerge CI has four failures, but they all appear to be pre-existing and unrelated to this PR's changes (4 Python files: a
Locally, Would it be possible to trigger a re-run, or is there anything else I should do on my end? |
Head branch was pushed to by a user without write access
c2b337e to
a8ccf6e
Compare
c90eabe to
643c038
Compare
643c038 to
9e83881
Compare
|
Hi @abrarsheikh — CI is all green now. Could this be merged? Thanks! |
|
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. |
9e83881 to
8ac5f2d
Compare
…or in Deployment.__eq__() Fix two boundary check bugs in Ray Serve: 1. prefix_aware_router crashes with ZeroDivisionError when input_text is empty (e.g., unsupported multimodal content). Added guard to set match_rate = 0.0 for empty input, triggering fallback routing. 2. Deployment.__eq__() raises AttributeError when compared to non-Deployment types. Added isinstance check returning NotImplemented per Python's data model convention. Fixes ray-project#64573 Fixes ray-project#64574 Signed-off-by: jiangxt2 <[email protected]>
8ac5f2d to
da14e2d
Compare
…or (#66671) PrefixCacheAffinityRouter called ray.get on its prefix tree actor inside choose_replicas (one or two round trips per routing attempt) and in on_request_routed, update_replicas and on_replica_actor_died. Each call stalled the router's event loop, which every DeploymentHandle in the process shares, so routing throughput was capped by the actor round trip and other requests' queue length probes waited behind it. - Await the tree lookup instead of calling ray.get, and send it before the load check so the round trip overlaps with any queue length probes. - Do the prefix match and the smallest-tenants fallback in one actor call, prefix_match_or_smallest_tenants. Empty text now falls back to the smallest tenants instead of raising ZeroDivisionError. - Don't wait on insert, add_tenants, remove_tenants or start_eviction_loop. The actor runs one caller's tasks in submission order, so later lookups from this process still see them. - Drop tree results for replicas that left while the lookup was in flight. ### Benchmark The release test added here, `llm_serve_prefix_router_overhead_benchmark` (`release/llm_tests/serve/prefix_router_overhead_benchmark.py`): 2 replicas behind `PrefixCacheAffinityRouter` (default kwargs) that reply immediately, so only routing costs time. Prompts are ~1 KiB from 8 shared system prompts; closed-loop clients for 5 s per concurrency level. `handle` is `handle.remote()`, as `OpenAiIngress` calls `LLMServer`; `direct` is `handle.choose_replica(..., _reserve=False)`, as the direct-streaming `LLMRouter` does. "Loop stall" is the p99 oversleep of a 1 ms heartbeat on the router's event loop. Run on the release test's setup (Anyscale m5.2xlarge, `anyscale/ray-llm:nightly-py312-cu130` at master `a4a924c1c5`), 5 rounds alternating the image's router with this PR's (`prefix_aware_router.py` and `prefix_tree.py` at `f4ea105b04` copied over the installed ones). Median of 5, master → this PR: | path | concurrency | req/s | p50 ms | p99 ms | router loop stall p99 ms | |---|---|---|---|---|---| | handle | 1 | 192 → 213 | 5.1 → 4.6 | 7.3 → 7.0 | 1.9 → 1.1 | | handle | 8 | 249 → 316 | 31.5 → 24.7 | 42.9 → 36.7 | 14.3 → 5.6 | | handle | 32 | 260 → 315 | 121.8 → 100.8 | 146.3 → 132.1 | 54.8 → 12.7 | | handle | 64 | 256 → 312 | 242.5 → 202.9 | 320.4 → 238.9 | 143.1 → 13.1 | | direct | 1 | 357 → 436 | 2.7 → 2.1 | 5.1 → 5.1 | 3.8 → 1.6 | | direct | 8 | 375 → 645 | 21.1 → 11.4 | 31.6 → 29.9 | 21.6 → 5.0 | | direct | 32 | 379 → 596 | 83.0 → 49.2 | 118.2 → 111.7 | 85.4 → 12.0 | | direct | 64 | 370 → 794 | 165.7 → 71.6 | 461.6 → 366.3 | 455.2 → 36.1 | On master, throughput is flat in concurrency and the loop stall grows with it. In every round, this PR had higher throughput and a lower loop stall than master at every level. The nightly includes #66489, so `direct` picks also insert into the tree (with a blocking `ray.get` on master). Because routing is now concurrent, a new prefix's first request can be routed before earlier inserts reach the tree: on the `handle` path the 8 prefixes split 5/3 across the 2 replicas in 2 of 5 runs with this PR and 4/4 in all runs on master; on the `direct` path, 4/4 in all runs for both. ### Tests ``` python -m pytest --noconftest --import-mode=importlib -q \ python/ray/llm/tests/serve/cpu/deployments/test_prefix_aware_request_router.py \ python/ray/llm/tests/serve/cpu/deployments/test_prefix_tree.py 68 passed ``` Run locally on macOS (`--noconftest` because the llm `conftest.py` imports vLLM). New tests: `TestNonBlockingTreeCalls` (3) and `TestPrefixTreePrefixMatchOrSmallestTenants` (4). All but `test_replica_removed_during_tree_lookup_is_not_chosen`, which guards a window master doesn't have, fail on master. No existing issue or PR does this (searched open PRs for `PrefixCacheAffinityRouter`, `prefix_aware_router`, `get_smallest_tenants`, "prefix tree actor ray.get"); #64577 fixes the same `ZeroDivisionError`. Written with AI assistance (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Artur Niederfahrenhorst <[email protected]> Signed-off-by: Artur Niederfahrenhorst <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Why are these changes needed?
Two boundary check bugs in Ray Serve:
prefix_aware_routercrashes withZeroDivisionErrorwheninput_textis an empty string (e.g., for unsupported multimodal content that yields no extractable text). The match rate calculationlen(matched_text) / len(input_text)divides by zero.Deployment.__eq__()directly accessesother._namewithout checking ifotheris aDeploymentinstance. Comparing aDeploymentto any non-Deployment object (string, None, int) raisesAttributeError.What changes are made?
python/ray/llm/_internal/serve/routing_policies/prefix_aware/prefix_aware_router.py: Add empty string guard before match rate division, settingmatch_rate = 0.0to trigger fallback routingpython/ray/serve/deployment.py: Addisinstance(other, Deployment)guard returningNotImplementedper Python's data model conventionpython/ray/llm/tests/serve/cpu/deployments/test_prefix_aware_request_router.py: Add test for empty input handlingpython/ray/serve/tests/unit/test_schema.py: Add tests for__eq__with non-Deployment typesdeployment_to_schema(parenthesized ternary, auto-formatted by black)Related issues
Fixes #64573
Fixes #64574
Checks
git commit -s)