-
Notifications
You must be signed in to change notification settings - Fork 493
feat(pd_router): implement prompt-length-aware routing for pd router #1800
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: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @googs1025, 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 significantly enhances the Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
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 introduces a dual routing strategy for the PD router, optimizing for short prompts by routing them directly to a decode pod, bypassing the prefill stage. The changes include adding a configurable threshold for short prompts and updating the routing logic. The test suite has been significantly expanded to cover these new scenarios.
My review identifies a critical correctness issue in the new short-prompt routing path where it incorrectly depends on the availability of prefill pods, which could lead to failures. I've also suggested an improvement for logging to enhance observability when tokenization fails. The tests are well-written but miss a key scenario that would expose the bug I found.
| _, decodePod, err := r.filterPrefillDecodePods(ctx, readyPodList.All()) | ||
| if err != nil { | ||
| klog.Warning("Failed to select decode pod for direct inference; falling back to prefill-decode flow", | ||
| "request_id", ctx.RequestID, "error", err) | ||
| } else if decodePod != nil { | ||
| ctx.SetTargetPod(decodePod) | ||
| return ctx.TargetAddress(), nil | ||
| } |
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.
The current implementation for the short-prompt optimization path reuses filterPrefillDecodePods, which is designed to find a pair of prefill and decode pods. This creates a bug: if no prefill pods are available, filterPrefillDecodePods will return an error, causing the short-prompt path to fail and fall back to the standard prefill-decode flow. The standard flow will then also fail for the same reason (no prefill pods).
The short-prompt path should be able to select a decode pod independently of prefill pods. A new test case like the one below would fail with the current implementation:
{
name: "short prompt with only decode pods available: should succeed",
readyPods: []*v1.Pod{
// No prefill pod!
{ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{PDRoleSetIdentifier: "test", PDRoleIdentifier: "decode"},
Name: "decode-1",
}, Status: v1.PodStatus{
PodIP: "127.0.0.2",
Conditions: []v1.PodCondition{{Type: v1.PodReady, Status: v1.ConditionTrue}},
}},
},
message: "hi",
shortPromptThreshold: 2048,
expectPrefillCall: false,
serverCode: http.StatusOK,
llmEngine: VLLMEngine,
expectError: false, // This would fail
expectTargetAddr: "127.0.0.2:8000",
},I recommend refactoring the pod selection logic. A new function, say selectDecodePod, should be created to encapsulate the logic for selecting only a decode pod. This would involve extracting the decode-pod-specific selection logic from filterPrefillDecodePods. The Route function can then be updated to call this new function for the short-prompt path.
| _, decodePod, err := r.filterPrefillDecodePods(ctx, readyPodList.All()) | |
| if err != nil { | |
| klog.Warning("Failed to select decode pod for direct inference; falling back to prefill-decode flow", | |
| "request_id", ctx.RequestID, "error", err) | |
| } else if decodePod != nil { | |
| ctx.SetTargetPod(decodePod) | |
| return ctx.TargetAddress(), nil | |
| } | |
| decodePod, err := r.selectDecodePod(ctx, readyPodList.All()) | |
| if err != nil { | |
| klog.Warning("Failed to select decode pod for direct inference; falling back to prefill-decode flow", | |
| "request_id", ctx.RequestID, "error", err) | |
| } else { | |
| ctx.SetTargetPod(decodePod) | |
| return ctx.TargetAddress(), nil | |
| } |
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.
I think we can ignore this comment, because filterPrefillDecodePods check both prefill and decode pod, this make sense in every round request
9f43e3d to
8a1e47b
Compare
| prefillRequestTimeout int = utils.LoadEnvInt("AIBRIX_PREFILL_REQUEST_TIMEOUT", defaultPrefillRequestTimeout) | ||
| aibrixDecodeMaxRequest float64 = utils.LoadEnvFloat("AIBRIX_DECODE_MAX_REQUEST", defaultMaxRequest) | ||
| aibrixDecodeMaxThroughputDiff float64 = utils.LoadEnvFloat("AIBRIX_DECODE_MAX_THROUGHPUT", defaultMaxTokenThroughputDiff) | ||
| shortPromptThreshold = utils.LoadEnvInt("AIBRIX_SHORT_PROMPT_THRESHOLD", defaultShortPromptThreshold) |
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.
em. this is to support remote prefill feature.
Instead of using SHORT_PROMPT etc, let's be specific and use REMOTE_PREFILL term instead
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.
done
Jeffwan
left a comment
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.
overall looks good to me. I also suggest to update the doc page with detail P/D explaination. Let's replace "dual" with term instead in PR title
| // 1. **Short-Prompt Optimization (Decode-Only)**: | ||
| // - If the input prompt length (in tokens) ≤ AIBRIX_SHORT_PROMPT_THRESHOLD (default value = 2048 tokens), | ||
| // the request is routed directly to a decode pod. | ||
| // - The decode pod performs *both* prefill (KV cache computation) and decoding locally, |
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.
How will gateway know that decode pod supports both prefill/decode role? vLLM supports it, but not sure if every engine supports this.
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.
Oh, that's a good question. I'll do some check on that, such as whether sglang supports it, and if not, I'll add the condition that it's limited to VLLM engine.
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.
check in sglang community sgl-project/sglang#14284
b4004a8 to
74fcad5
Compare
| return "", fmt.Errorf("engine validation failed for request %s: %w", ctx.RequestID, err) | ||
| } | ||
|
|
||
| // NOTE: Short-prompt optimization (bypassing remote prefill) is currently ONLY supported for vLLM. |
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.
add comment "ONLY supported for vLLM" for now
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.
if r.remotePrefillThreshold > 0 && llmEngine == VLLMEngine {
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.
In vLLM it supports multiple roles, but it is not necessary that user configures kv_both. Will need a flag to guide gateway.
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.
Can you also run a benchmark to compare TTFT/TPOT/E2E P90/P99.
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.
In vLLM it supports multiple roles, but it is not necessary that user configures kv_both. Will need a flag to guide gateway.
sorry, I don't know much about this part. Could you explain it in more detail or give me more relevant info?
74fcad5 to
975ff83
Compare
Signed-off-by: CYJiang <[email protected]>
975ff83 to
197e7e9
Compare
Pull Request Description
[Please provide a clear and concise description of your changes here]
Related Issues
Resolves: #1798
Important: Before submitting, please complete the description above and review the checklist below.
Contribution Guidelines (Expand for Details)
We appreciate your contribution to aibrix! To ensure a smooth review process and maintain high code quality, please adhere to the following guidelines:
Pull Request Title Format
Your PR title should start with one of these prefixes to indicate the nature of the change:
[Bug]: Corrections to existing functionality[CI]: Changes to build process or CI pipeline[Docs]: Updates or additions to documentation[API]: Modifications to aibrix's API or interface[CLI]: Changes or additions to the Command Line Interface[Misc]: For changes not covered above (use sparingly)Note: For changes spanning multiple categories, use multiple prefixes in order of importance.
Submission Checklist
By submitting this PR, you confirm that you've read these guidelines and your changes align with the project's contribution standards.