-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
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 @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 theqwen3.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
-
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
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.
Tested quality with lora qwen3 32b and got results similar to vllm |
@logachevpa Thanks for your contribution! Can you add a test for Qwen3 lora under |
@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 |
Fixed style |
Fixed Fidge003's suggestions |
My tests was ok https://github.com/sgl-project/sglang/actions/runs/15880211253/job/44822085834 |
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.
LGTM
@logachevpa Please fix conflict with main branch |
return meta-llama return meta fix style isolate qwen3 tests style
@Fridge003 fixed conflicts |
@Fridge003 what do I need to do to merge this pr? |
Motivation
This is fix of #7271
Modifications
Without it qwen3 lora doesn't work
Checklist