-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Documentation for prefix cache-aware router #55218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Seiji Eicher <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @eicherseiji, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces comprehensive documentation for the PrefixAwarePow2RequestRouter
, a specialized component designed to optimize Large Language Model (LLM) inference. The new guide aims to equip users with the knowledge to effectively configure, deploy, and monitor this router, thereby improving cache locality and overall performance for LLM serving workloads.
Highlights
- New Documentation Added: A dedicated guide for the
PrefixAwarePow2RequestRouter
has been added to the advanced guides section of the documentation. - LLM Inference Optimization Explained: The new documentation details the router's three-tier algorithm for balancing cache locality and load distribution, specifically for Large Language Model (LLM) inference.
- Configuration and Deployment Guidance: The guide provides practical examples and parameters for configuring and deploying LLM applications using this specialized router.
- Performance Tuning and Debugging: Sections are included to help users optimize performance, monitor routing decisions, and troubleshoot common issues such as low cache hit rates, load imbalance, or memory growth.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds comprehensive documentation for the new PrefixAwarePow2RequestRouter
. The guide is well-structured and covers the functionality, configuration, and best practices. I've identified a critical issue in the main code example that would prevent it from running, along with a minor typo. I've provided suggestions to correct these issues. The changes to index.md
look good.
```python | ||
import ray | ||
from ray import serve | ||
from ray.llm._internal.serve.request_router.prefix_aware.prefix_aware_router import ( | ||
PrefixAwarePow2ReplicaRouter | ||
) | ||
|
||
llm_config = LLMConfig( | ||
model_loading_config=dict( | ||
model_id="qwen-0.5b", | ||
model_source="Qwen/Qwen2.5-0.5B-Instruct", | ||
), | ||
deployment_config=dict( | ||
request_router_config=dict( | ||
request_router_class=PrefixAwarePow2ReplicaRouter, | ||
request_router_kwargs= | ||
), | ||
# Configure routing behavior | ||
request_router_kwargs={ | ||
"imbalanced_threshold": 5, # More aggressive load balancing | ||
"match_rate_threshold": 0.15, # Require 15% match rate | ||
"do_eviction": True, # Enable memory management | ||
"eviction_threshold_chars": 500_000, | ||
"eviction_target_chars": 400_000, | ||
"eviction_interval_secs": 30, | ||
} | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code example has a few issues that will prevent it from running:
LLMConfig
andbuild_openai_app
are used without being imported, which will cause aNameError
.- There's a syntax error in
deployment_config
. Therequest_router_kwargs
is specified at the wrong level, and there's a strayrequest_router_kwargs=
line which is invalid syntax.
Here is a corrected version of the code block with the necessary imports and correct configuration structure to make it runnable for users.
import ray
from ray import serve
from ray.llm import LLMConfig
from ray.llm.openai import build_openai_app
from ray.llm._internal.serve.request_router.prefix_aware.prefix_aware_router import (
PrefixAwarePow2ReplicaRouter
)
llm_config = LLMConfig(
model_loading_config=dict(
model_id="qwen-0.5b",
model_source="Qwen/Qwen2.5-0.5B-Instruct",
),
deployment_config=dict(
request_router_config=dict(
request_router_class=PrefixAwarePow2ReplicaRouter,
request_router_kwargs={
"imbalanced_threshold": 5, # More aggressive load balancing
"match_rate_threshold": 0.15, # Require 15% match rate
"do_eviction": True, # Enable memory management
"eviction_threshold_chars": 500_000,
"eviction_target_chars": 400_000,
"eviction_interval_secs": 30,
}
)
),
)
# Deploy the application
app = build_openai_app({"llm_configs": [llm_config]})
serve.run(app)
(prefix-aware-algorithm)= | ||
## How Prefix Cache-Aware Routing Works | ||
|
||
The `PrefixAwarePow2RequestRouter` implements a three tier routing strategy that balances cache locality with load distribution: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For better readability and grammatical correctness, it's best to hyphenate compound adjectives like 'three-tier' when they precede a noun.
The `PrefixAwarePow2RequestRouter` implements a three tier routing strategy that balances cache locality with load distribution: | |
The `PrefixAwarePow2RequestRouter` implements a three-tier routing strategy that balances cache locality with load distribution: |
```python | ||
import ray | ||
from ray import serve | ||
from ray.llm._internal.serve.request_router.prefix_aware.prefix_aware_router import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered exposing this from a public module that is not _internal
? If you keep the _internal
, when you stabilize the API, you will have no choice but to move it. If you already put it at a location that might be stable, you might be able to keep it. One reasonable choice would be from ray.serve.llm.routers import PrefixAwarePow2ReplicaRouter
. It might also make it more likely for people to adopt this feature.
Why are these changes needed?
Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.