-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
[Frontend][Model] Qwen3Rerank API Server backward compatibility #20239
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?
[Frontend][Model] Qwen3Rerank API Server backward compatibility #20239
Conversation
…ible and support instruction Signed-off-by: BetterAndBetterII <betterandbetterii@gmail.com>
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
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 @BetterAndBetterII, 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 flexibility and usability of the /score
and /rerank
API endpoints by integrating native support for templated inputs. This change is particularly beneficial for models requiring specific prompt formats, as it shifts the prompt formatting responsibility from the client to the server. The implementation prioritizes backward compatibility while offering robust configuration options for template application, streamlining the interaction with diverse model architectures.
Highlights
- Templated Input Support: I've introduced native support for templated inputs in the
/score
and/rerank
API endpoints. This allows models like Qwen3-Reranker to receive the exact prompt format they expect directly from the server, eliminating the need for client-side preprocessing. - Flexible Template Configuration: Templates can now be specified in multiple ways: directly within the API request body (
score_template
/rerank_template
), as cluster-wide defaults viahf_overrides
during engine initialization, or potentially from the model'stokenizer_config.json
(though not currently utilized by Qwen3). - Backward Compatibility: The templating feature is opt-in. If no template is provided, the system behaves identically to its pre-patch state, ensuring existing clients and models remain fully functional without any required changes.
- Enhanced Testing: New unit tests have been added to cover various scenarios, including verifying that legacy paths remain unchanged, custom templates provided via the API work as expected, and the
hf_overrides
fallback mechanism functions correctly, specifically for the Qwen3-Reranker model.
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 is currently in preview and 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 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
The PR adds templating support for /score
and /rerank
endpoints. There's a critical issue with inconsistent field names between ScoreRequest
and RerankRequest
in the protocol, leading to a bug in the serving logic. I've provided suggestions to unify these names. I've also pointed out an area for code improvement in the tests.
rerank_template: Optional[dict[str, str]] = Field( | ||
default=None, | ||
description=("A dictionary containing query_template and " | ||
"document_template to format the reranker input.") | ||
) | ||
rerank_template_kwargs: Optional[dict[str, Any]] = Field( | ||
default=None, | ||
description=("A dictionary of key-value pairs to be formatted into " | ||
"the rerank model's template.") | ||
) |
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 field names rerank_template
and rerank_template_kwargs
in RerankRequest
are inconsistent with ScoreRequest
's score_template
and score_template_kwargs
. To ensure consistency, unify the field names in RerankRequest
to match ScoreRequest
.
Also, improve the description for rerank_template_kwargs
by using the description from score_template_kwargs
.
rerank_template: Optional[dict[str, str]] = Field( | |
default=None, | |
description=("A dictionary containing query_template and " | |
"document_template to format the reranker input.") | |
) | |
rerank_template_kwargs: Optional[dict[str, Any]] = Field( | |
default=None, | |
description=("A dictionary of key-value pairs to be formatted into " | |
"the rerank model's template.") | |
) | |
score_template: Optional[dict[str, str]] = Field( | |
default=None, | |
description=("A dictionary containing query_template and " | |
"document_template to format the reranker input.") | |
) | |
score_template_kwargs: Optional[dict[str, Any]] = Field( | |
default=None, | |
description=("Additional keyword args to pass to the template renderer. " | |
"Will be accessible by the rerank template.") | |
) |
template_config = (request.score_template | ||
or self.model_config.hf_config.get( | ||
"score_template")) |
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 request.score_template_kwargs: | ||
context.update(request.score_template_kwargs) |
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.
"score_template_kwargs": { | ||
"instruction": instruction | ||
} |
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.
Is it viable to instead extend the chat template with query/document prompts and enable them via |
cc @noooop |
It is not a direct extension of chat_template, because chat_template actually accepts a message. Here we only want to accept query+document(+kwargs like instruct) and then apply a template. So I think a feasible solution is to propose a score_template or rerank_template to apply, but the specific name needs to be discussed. |
@@ -1194,7 +1194,16 @@ class ScoreRequest(OpenAIBaseModel): | |||
"default: 0). Any priority other than 0 will raise an error " | |||
"if the served model does not use priority scheduling."), | |||
) | |||
|
|||
score_template: Optional[dict[str, str]] = Field( |
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.
Ah I see that these endpoints don't use chat templates now. In that case, I prefer separating query_template
and document_template
into separate arguments to avoid unnecessary nesting.
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.
copy that 🫡
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.
but here we may need to pass in instruction, that is, other parameters may need to be applied to the template. Maybe a template+template kwargs is better?
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 for user convenience, it's better to separate template and template kwargs, since the kwargs aren't used that often
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 template is a triple of query
, document
, instruction
, among which if the user does not give the instruction, use the default instruction.
should basically be consistent with mteb
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 should use the same API for the entire ecosystem, so I think it should be implemented by Sentence Transformers first.
Personally, I think this feature is very important. refer to: #19260 (comment) If you are interested in the
|
Thank you very much. I am very interested in starting the PR of sentence-transformer. If sentence-transformer supports this, then we need to align this at the OpenAI API server interface level of vllm? |
You can also leave comments on sentence-transformer and share your thoughts. |
I don't have enough context with rerank atm, but will wait for @DarkLight1337 review. |
Purpose
This PR adds native support for templated inputs in the /score and /rerank endpoints, enabling models such as Qwen3-Reranker to receive the exact prompt format they expect without client-side preprocessing.
Backward Compatibility
This change is very important because all downstream applications use query+document input instead of instruct input.
This will make it impossible to directly access the qwen3 Reranker model, and some adapter changes must be made.
My change allows vllm to support template input from two aspects, mainly referring to
chat_template
andchat_template_kwargs
:PR #19260 reports that the current implementation need client side template format.
Changes
Test Plan
New unit tests ensure:
(a) legacy paths remain identical for untreated models;
(b) custom template works via API;
(c) default fallback via hf_overrides succeeds.
Test Result
encountered dependency issue, solving...
Documentation Update
Add “Templated Score/Rerank” section with curl / Python snippets.
Essential Elements of an Effective PR Description Checklist
supported_models.md
andexamples
for a new model.