Skip to content

Add get_hidden_dim to qwen3.py for correct lora #7312

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 9 commits into from
Jul 20, 2025

Conversation

logachevpa
Copy link
Contributor

Motivation

This is fix of #7271

Modifications

Without it qwen3 lora doesn't work

Checklist

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 @logachevpa, 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 addresses a known issue where LoRA (Low-Rank Adaptation) was not functioning correctly with Qwen3 models. My change introduces a new method that exposes the necessary hidden dimension information for various model sub-modules, thereby enabling proper integration and functionality of LoRA for Qwen3 models.

Highlights

  • LoRA Compatibility for Qwen3 Models: I've added a new method, get_hidden_dim, to the qwen3.py model definition. This method is crucial for enabling correct Low-Rank Adaptation (LoRA) functionality by providing the input and output dimensions for various key modules within the Qwen3 architecture, such as attention projections (q_proj, k_proj, v_proj, o_proj, qkv_proj, kv_proj) and feed-forward network layers (gate_up_proj, down_proj). Without this method, LoRA would not be able to correctly identify the dimensions needed for its adaptations.
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.

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

This PR adds a get_hidden_dim method to qwen3.py to support LoRA. The review identified issues in the dimension calculations for K/V projections and potential ambiguities in how dimensions are determined for kv_proj and gate_up_proj. Addressing these is crucial for correct LoRA application.

@logachevpa logachevpa marked this pull request as draft June 18, 2025 11:42
@logachevpa logachevpa marked this pull request as ready for review June 18, 2025 13:22
@logachevpa logachevpa marked this pull request as draft June 18, 2025 13:24
@logachevpa
Copy link
Contributor Author

Tested quality with lora qwen3 32b and got results similar to vllm

@logachevpa logachevpa marked this pull request as ready for review June 18, 2025 16:26
@Fridge003
Copy link
Collaborator

@logachevpa Thanks for your contribution! Can you add a test for Qwen3 lora under test/srt/models/lora folder?

@logachevpa
Copy link
Contributor Author

@Fridge003 Thank for suggestion to write tests. I've writen it but noticed that 32 tokens * 15 examples is too much for this lora, i couldn't run it successfully, every time i got some minor mistake and it was not samples with loras but also without lora. I lowered max_new_tokens and passed tested with first run. I think it's enough.

Also i noticed that qwen3 by default use sampling despite there is do_sample=False in GenerationConfig. so i put model.generation_config.do_sample = False and then it worked fine

@logachevpa
Copy link
Contributor Author

Fixed style

@logachevpa
Copy link
Contributor Author

Fixed Fidge003's suggestions

@logachevpa
Copy link
Contributor Author

My tests was ok https://github.com/sgl-project/sglang/actions/runs/15880211253/job/44822085834
Not all other tests, that i didn't touch, was ok.

Copy link
Collaborator

@Fridge003 Fridge003 left a comment

Choose a reason for hiding this comment

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

LGTM

@Fridge003
Copy link
Collaborator

@logachevpa Please fix conflict with main branch

return meta-llama

return meta

fix style

isolate qwen3 tests

style
@logachevpa
Copy link
Contributor Author

@Fridge003 fixed conflicts

@logachevpa
Copy link
Contributor Author

@Fridge003 what do I need to do to merge this pr?

@Fridge003 Fridge003 added the ready-to-merge The PR is ready to merge after the CI is green. label Jul 19, 2025
@zhyncs zhyncs merged commit 877e35d into sgl-project:main Jul 20, 2025
3 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge The PR is ready to merge after the CI is green.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants