[Feat]: finished by finish reason - #2061
Conversation
288e876 to
7493e95
Compare
There was a problem hiding this comment.
Code Review
This pull request introduces a short-circuiting mechanism for prefill requests within the PD disaggregation algorithm. It enables the gateway to return an immediate response to the client if a specific finish reason is detected during the prefill phase, effectively bypassing subsequent processing steps. Key changes include modifications to the routing context, HTTP execution flow, and metrics handling, as well as the addition of utility functions for constructing Envoy-compatible immediate responses and new unit tests. I have no feedback to provide.
cbab1b6 to
1e5a545
Compare
|
@varungup90 please help to review |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a short-circuiting mechanism for TRT-LLM prefill requests that complete early (e.g., with a 'stop' finish reason), allowing the gateway to return an immediate response instead of proceeding to a decode phase. It also includes significant hardening of the RoutingContext and associated routing algorithms by adding nil-pointer checks to prevent panics during request cleanup or when handling immediate responses. Feedback focuses on ensuring that the stream context is properly reset when the pooled RoutingContext is deleted to avoid race conditions, and addressing a gap where short-circuited requests currently bypass token accounting and quota metrics.
| st.routerCtx.Delete() | ||
| st.routerCtx = nil |
There was a problem hiding this comment.
When st.routerCtx is deleted and set to nil, st.ctx should also be reset to the original stream context (e.g., the context from srv.Context()). Since RoutingContext objects are pooled and reused, continuing to use a deleted context in st.ctx can lead to race conditions or unexpected behavior in subsequent iterations of the processing loop (for instance, in preRecvCheck or if srv.Recv() is called again). Additionally, a similar cleanup (setting st.routerCtx = nil and resetting st.ctx) should be performed after the call to HandleResponseBody when st.completed is true, to avoid stale pointers in the processState.
| if routingCtx.ImmediateResponse != nil { | ||
| extraHeaders := map[string]string{ | ||
| HeaderRequestID: requestID, | ||
| } | ||
| if routingCtx.RespHeaders != nil { | ||
| for k, v := range routingCtx.RespHeaders { | ||
| extraHeaders[k] = v | ||
| } | ||
| } | ||
| return buildImmediateResponseFromHTTPResponse(routingCtx.ImmediateResponse, extraHeaders), model, routingCtx, stream, term | ||
| } |
There was a problem hiding this comment.
Short-circuited prefill responses return an immediate response to the client without proceeding to the response processing phase or calling AddRequestCount. Consequently, tokens generated during the prefill phase (which are present in the routingCtx.ImmediateResponse.Body) are not accounted for in metrics, logs, or user quotas. This could allow users to bypass token-based rate limits for requests that complete during prefill. Consider extracting the usage information from the response body and reporting it (e.g., via s.requestEndHelper) before returning the immediate response.
📝 Review Comments for PR #2061🔴 Critical & Correctness
🏗️ Design & Architecture
🧪 Testing & Minor Improvements
|
3107423 to
ed3b6f0
Compare
|
@scarlet25151 could you double check varun's command and high priority items from gemini? |
@Jeffwan I discuss with varun, and there is some of a easier way to implement, currently I'm testing on new implementation to avoid regression on vllm, will push it later |
ed3b6f0 to
fe2b74b
Compare
Signed-off-by: chenyu.jiang <chenyu.jiang@bytedance.com>
36091b3 to
79f7a30
Compare
Signed-off-by: chenyu.jiang <chenyu.jiang@bytedance.com>
79f7a30 to
8350e4c
Compare
Pull Request Description
This PR fixes the missing
finish_reasonhandling in PD disaggregation for TensorRT-LLM.Previously, the gateway always proceeded to the decode phase after a synchronous TRT-LLM prefill request, even when the prefill response had already completed generation. This could break short outputs such as single-token answers (
yes/no, numbers, etc.), because the workflow incorrectly assumed a decode hop was still required.This change adds a TRT-LLM-specific short-circuit for synchronous prefill responses:
finish_reasonis a completed state (that is, neither"length"nor"not_finished"), the gateway returns the prefill result immediately and skips decode.TensorRTLLMso other engines, including vLLM, keep their original behavior.In addition, this PR includes:
gateway.gofinish_reasonRelated Issues
Resolves: #2013
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.