Repository navigation
[Router][Bugfix] Handle all router types correctly in proxy_multipart_request - #1021
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the proxy_multipart_request function to support asynchronous routing for KvawareRouter, PrefixAwareRouter, and SessionRouter by awaiting their route_request method with an additional empty JSON body argument. However, the review correctly points out that DisaggregatedPrefillOrchestratedRouter and DisaggregatedPrefillRouter also require five arguments (with the former being asynchronous), which would currently trigger a TypeError in the fallback else block. A code suggestion is provided to handle these additional router types safely.
b4822cd to
de7d140
Compare
…art_request
proxy_multipart_request was calling router.route_request() without await
and without the required request_json argument, causing a TypeError when
using SessionRouter, KvawareRouter, or PrefixAwareRouter for multipart
endpoints (/v1/audio/transcriptions, /v1/images/edits).
Add the same isinstance guard used in route_general_request to call the
async routers with await and pass {} as request_json (no JSON body for
multipart/form-data), while keeping the synchronous call for other routers.
Fixes vllm-project#1019
Signed-off-by: Shern Shiou Tan <[email protected]>
de7d140 to
b675c83
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request modifies the proxy_multipart_request function to handle different router types by checking their classes with isinstance to determine if the routing call should be awaited and if an empty JSON body should be passed. The reviewer correctly points out that hardcoding these checks is fragile and violates the Open-Closed Principle, suggesting a dynamic approach using Python's inspect module to check the method signature and coroutine status instead.
| if isinstance( | ||
| router, | ||
| ( | ||
| KvawareRouter, | ||
| PrefixAwareRouter, | ||
| SessionRouter, | ||
| DisaggregatedPrefillOrchestratedRouter, | ||
| ), | ||
| ): | ||
| chosen_url = await router.route_request( | ||
| endpoints, | ||
| engine_stats, | ||
| request_stats, | ||
| request, | ||
| {}, # no JSON body for multipart/form-data | ||
| ) | ||
| elif isinstance(router, DisaggregatedPrefillRouter): | ||
| chosen_url = router.route_request( | ||
| endpoints, | ||
| engine_stats, | ||
| request_stats, | ||
| request, | ||
| {}, # no JSON body for multipart/form-data | ||
| ) | ||
| else: | ||
| chosen_url = router.route_request( | ||
| endpoints, | ||
| engine_stats, | ||
| request_stats, | ||
| request, | ||
| ) |
There was a problem hiding this comment.
Hardcoding specific router classes with isinstance checks is fragile and violates the Open-Closed Principle. If a new router is added in the future, this code will need to be manually updated, which is highly error-prone.
Instead, we can use Python's standard inspect module to dynamically determine if the route_request method is asynchronous and whether it accepts the request_json parameter. This makes the routing invocation completely generic and future-proof.
import inspect
route_fn = router.route_request
sig = inspect.signature(route_fn)
route_args = [endpoints, engine_stats, request_stats, request]
if "request_json" in sig.parameters:
route_args.append({})
if inspect.iscoroutinefunction(route_fn):
chosen_url = await route_fn(*route_args)
else:
chosen_url = route_fn(*route_args)
Description
proxy_multipart_request(used by/v1/audio/transcriptionsand/v1/images/edits) was callingrouter.route_request()synchronously and without the requiredrequest_jsonargument, causing aTypeErrorwhen usingSessionRouter,KvawareRouter, orPrefixAwareRouter.Changes
isinstance(router, (KvawareRouter, PrefixAwareRouter, SessionRouter))guard already used inroute_general_requestawaitand pass{}asrequest_json(no JSON body in multipart/form-data)RoundRobinRouter): keep the original synchronous call unchangedFixes #1019
BEFORE SUBMITTING, PLEASE READ THE CHECKLIST BELOW AND FILL IN THE DESCRIPTION ABOVE
-swhen doinggit commit[Bugfix],[Feat], and[CI].Detailed Checklist (Click to Expand)
Thank you for your contribution to production-stack! Before submitting the pull request, please ensure the PR meets the following criteria. This helps us maintain the code quality and improve the efficiency of the review process.
PR Title and Classification
Please try to classify PRs for easy understanding of the type of changes. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:
[Bugfix]for bug fixes.[CI/Build]for build or continuous integration improvements.[Doc]for documentation fixes and improvements.[Feat]for new features in the cluster (e.g., autoscaling, disaggregated prefill, etc.).[Router]for changes to thevllm_router(e.g., routing algorithm, router observability, etc.).[Misc]for PRs that do not fit the above categories. Please use this sparingly.Note: If the PR spans more than one category, please include all relevant prefixes.
Code Quality
The PR need to meet the following code quality standards:
pre-committo format your code. SeeREADME.mdfor installation.DCO and Signed-off-by
When contributing changes to this project, you must agree to the DCO. Commits must include a
Signed-off-by:header which certifies agreement with the terms of the DCO.Using
-swithgit commitwill automatically add this header.What to Expect for the Reviews
We aim to address all PRs in a timely manner. If no one reviews your PR within 5 days, please @-mention one of YuhanLiu11
, Shaoting-Feng or ApostaC.