Skip to content

[Model][1/N] Automatic conversion of CrossEncoding model #20012

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

Merged
merged 13 commits into from
Jun 27, 2025

Conversation

noooop
Copy link
Contributor

@noooop noooop commented Jun 24, 2025

verify_and_update_config

Sometimes when implementing a model, we need to modify some default values in the config, or change variables to names commonly used by vllm.

how did the problem occur

But now vllm uses a multiprocessing architecture, so changing VllmConfig in model init will not affect the main process.

from vllm import LLM

model_name = "Qwen/Qwen3-Reranker-0.6B"

model = LLM(
    model=model_name,
    task="score",
    hf_overrides={
        "architectures": ["Qwen3ForSequenceClassification"],
        "classifier_from_token": ["no", "yes"],
        "is_original_qwen3_reranker": True,
    },
)


print("num_labels:", model.llm_engine.vllm_config.model_config.hf_config.num_labels)

# num_labels: 2
# expected: num_labels: 1

It seems that this is not much of an issue for loading the model.

But if get values from vllm_config in the main processing or server api processing, it may get incorrect data.

Solution 1

Change verify_and_update_config into a class method and call it after initializing model_config.

@dataclass(frozen=True)
class _LazyRegisteredModel(_BaseRegisteredModel):
"""
Represents a model that has not been imported in the main process.
"""
module_name: str
class_name: str
# Performed in another process to avoid initializing CUDA
def inspect_model_cls(self) -> _ModelInfo:
return _run_in_subprocess(
lambda: _ModelInfo.from_model_cls(self.load_model_cls()))

It seems that everyone intends to avoid directly importing the model in the main process.

Solution 2

Using a similar method like _run_in_subprocess, but I'm not sure if vllm_config is picklable. e.g., referencing some lambda functions

Solution 3

Modify somewhere in vllm.config, that's why vllm.config has over 4000+ lines.

Solution 4 <- this pr

separate config and model impl.

I am sure this is not the best solution.

This pr intends to start further discussion on this issue. 抛砖引玉

Essential Elements of an Effective PR Description Checklist

  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

Purpose

this pr is to address some complex issues found when dealing with #19675

  • verify_and_update_config
    Simplification of the 4000+ lines of vllm.config by moving code specific to certain models out.
  • fix FAILED tests/models/language/pooling/test_baai.py::test_embed_models_mteb[model_info0] - TypeError: VllmRunner.encode() got an unexpected keyword argument 'use_tqdm'
  • hitchhike
    • BertWithRope.config_verify -> verify_and_update_config

Test Plan

pytest tests/models/language/pooling/test_qwen3_reranker.py

Test Result

Manage to keep all testing happy.

(Optional) Documentation Update

Signed-off-by: wang.yuqi <noooop@126.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 @noooop, 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 a robust mechanism to handle model-specific configuration adjustments within vLLM's multiprocessing architecture. Previously, certain configuration values, like num_labels for specific models, were not correctly propagated from the model's initialization to the main process's VllmConfig. This change centralizes and standardizes how these adjustments are applied, ensuring that the VllmConfig is accurately updated early in its lifecycle, thereby preventing inconsistencies and incorrect behavior.

Highlights

  • Centralized Configuration Updates: A new try_verify_and_update_config method has been added to VllmConfig, which is called during its __post_init__. This method dynamically loads and applies model-specific configuration adjustments based on the detected model architecture, ensuring consistency across processes.
  • Dedicated Model Configuration Module: A new module, vllm/model_executor/models/config.py, has been introduced. This module now houses static methods for verifying and updating VllmConfig properties for specific model architectures (e.g., Qwen3ForSequenceClassification), cleanly separating this logic from the model's main implementation.
  • Qwen3-Reranker num_labels Fix: The specific issue where the num_labels for Qwen3-Reranker models was incorrectly set to 2 (instead of 1) is now resolved. This adjustment is handled by the new centralized configuration mechanism, ensuring correct model behavior.
  • Refactored Model Weight Loading: Redundant configuration logic and assertions related to num_labels have been removed from the qwen3.py model implementation, as these concerns are now managed by the new dedicated configuration module.
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

  1. 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.

@mergify mergify bot added the qwen Related to Qwen models label Jun 24, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a mechanism to verify and update model configurations, particularly for CrossEncoding models, by separating configuration and model logic. This involves adding a try_verify_and_update_config method to VllmConfig and creating a new VerifyAndUpdateConfig class in vllm/model_executor/models/config.py. The changes also include modifications to the Qwen3 model to accommodate the new configuration verification process. The code maintains testing and aims for simplification, but there are opportunities to improve readability and documentation.

Copy link

👋 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 fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

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 ready label to the PR or enable auto-merge.

🚀

@noooop
Copy link
Contributor Author

noooop commented Jun 24, 2025

@DarkLight1337

Does this work for you?

@noooop noooop changed the title [Model][2/N] Automatic conversion of CrossEncoding model. Part 2 [Model][1/N] Automatic conversion of CrossEncoding model. Part 1 Jun 24, 2025
@DarkLight1337
Copy link
Member

cc @maxdebayser

Copy link
Contributor

@maxdebayser maxdebayser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this because while implementing support for encoder models I've encountered several situations where I had to disable/enable feature is config.py because of model specifics.

Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from 9b0b84c to 954412f Compare June 25, 2025 02:52
Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from 34764ec to d7fc461 Compare June 25, 2025 02:56
noooop added 2 commits June 25, 2025 11:25
Signed-off-by: wang.yuqi <noooop@126.com>
Signed-off-by: wang.yuqi <noooop@126.com>
@noooop
Copy link
Contributor Author

noooop commented Jun 25, 2025

@DarkLight1337

ready to final review

I have locally tested and fixed as many tests as possible.

noooop added 2 commits June 25, 2025 14:51
Signed-off-by: wang.yuqi <noooop@126.com>
Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from 5a70d6f to fb7c8e0 Compare June 25, 2025 06:52
@noooop noooop changed the title [Model][1/N] Automatic conversion of CrossEncoding model. Part 1 [Model][1/N] Automatic conversion of CrossEncoding model Jun 25, 2025
@noooop
Copy link
Contributor Author

noooop commented Jun 25, 2025

@DarkLight1337

Could you plz look at this thread, thanks

Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from 73e3079 to fbd9dfa Compare June 25, 2025 10:31
Copy link
Collaborator

@Isotr0py Isotr0py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM! Thanks for this enhancement!

@Isotr0py Isotr0py added the ready ONLY add when PR is ready to merge/full CI is needed label Jun 26, 2025
Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from e3ae464 to 94dbbe8 Compare June 26, 2025 08:25
Signed-off-by: wang.yuqi <noooop@126.com>
@noooop noooop force-pushed the verify_and_update_config branch from a2a8596 to abe9209 Compare June 26, 2025 09:17
@noooop
Copy link
Contributor Author

noooop commented Jun 26, 2025

@Isotr0py

Is the failure of buildkite/ci/pr/basic-models-test related to this pr?

I can't reproduce this error locally .

@Isotr0py
Copy link
Collaborator

Seems just a network issue on CI runner, retrying.

@vllm-bot vllm-bot merged commit cd4cfee into vllm-project:main Jun 27, 2025
4 of 7 checks passed
@noooop
Copy link
Contributor Author

noooop commented Jun 27, 2025

Thanks for reviewing

@noooop
Copy link
Contributor Author

noooop commented Jun 27, 2025

Is the failure of buildkite/ci/pr/basic-models-test related to this pr?

find an earlier failure

https://buildkite.com/vllm/ci/builds/22564

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qwen Related to Qwen models ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants