Skip to content

Conversation

@Ziheng-Zhang-AUS
Copy link

What does this PR do?

Fixes #9251

  • Support PEFT 0.17.0 features of LoRA injection for nn.parameters.
  • Add corresponding GUI module
  • Add corresponding LoRA tests

Before submitting

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Ziheng-Zhang-AUS, 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 LoRA fine-tuning capabilities by enabling users to target specific "nn.Parameters" for LoRA injection, rather than being limited to entire modules. This granular control is especially valuable for advanced model architectures like Mixture-of-Experts (MoE) models, allowing for more precise and efficient adaptation. The changes span across configuration, model adaptation logic, testing, and the graphical user interface, ensuring a complete and robust implementation.

Highlights

  • Direct LoRA Parameter Injection: Introduced a new "lora_parameters" argument to allow direct application of LoRA to specific "nn.Parameters", which is particularly useful for fine-tuning components like expert parameters in Mixture-of-Experts (MoE) models.
  • PEFT 0.17.0 Feature Support: Implemented support for the LoRA injection features available in PEFT version 0.17.0, enhancing compatibility and leveraging the latest capabilities.
  • Web UI Integration: Added a dedicated input field in the web-based training interface for users to easily specify "lora_parameters" through the GUI.
  • Comprehensive Testing: Included new test cases to validate the correct functionality of LoRA injection into specified parameters, ensuring robustness and reliability.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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 pull request introduces a valuable feature to support LoRA injection for nn.Parameters, which is particularly useful for Mixture-of-Experts (MoE) models. The implementation looks mostly correct, with new arguments added to the configuration, CLI, and web UI.

However, I've found several critical issues in the tests. The utility function check_lora_model has been refactored, but the existing tests that rely on it have not been updated correctly, causing them to fail or test the wrong thing. The new test for lora_parameters also has incorrect logic. Additionally, the refactored check_lora_model seems to have lost some functionality compared to the old version, specifically for checking modules_to_save.

I've also noticed a minor issue with a print statement that should be a logger call, and an unrelated .drawio file that might have been added by mistake.

Please address the critical issues in the tests to ensure the new functionality is properly verified and doesn't introduce regressions.

@hiyouga
Copy link
Owner

hiyouga commented Oct 23, 2025

Please resolve the gemini's review

@Ziheng-Zhang-AUS
Copy link
Author

I have modified the implementation according to Gemini's review :)

@Kuangdd01 Kuangdd01 added the pending This problem is yet to be addressed label Oct 25, 2025
target_parameters = []
if len(finetuning_args.lora_target) == 1 and finetuning_args.lora_target[0] == "all":
target_modules = find_all_linear_modules(model, finetuning_args.freeze_vision_tower)
if finetuning_args.lora_parameters: # if specified the parameters to be adapted, use them
Copy link
Owner

Choose a reason for hiding this comment

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

When we specify the target parameters, the target modules should not be affected

Copy link
Owner

Choose a reason for hiding this comment

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

This if-else is strange

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I didn't understand the idea very clearly, because I noticed that Lora target has a default value of "all". I was thinking that if this default value is not changed and Lora parameters are used for injection without the user specifying a target, then this if-else should be judged here.

Choose a reason for hiding this comment

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

The current implementation will prevent target_parameters (lora_parameters) from being passed to peftconfig when target_modules (lora_target) is specified. There is no need to modify this peice of code to pass lora_parameters. Instead I would pass it immediatly to peft_kwargs:

            peft_kwargs = {
                "r": finetuning_args.lora_rank,
                "target_modules": target_modules,
                "target_parameters": finetuning_args.lora_parameters,
                "lora_alpha": finetuning_args.lora_alpha,
                "lora_dropout": finetuning_args.lora_dropout,
                "use_rslora": finetuning_args.use_rslora,
                "use_dora": finetuning_args.use_dora,
                "modules_to_save": finetuning_args.additional_target,
            }

target_parameters is an optional argument with None as default.

"use_rslora": finetuning_args.use_rslora,
"use_dora": finetuning_args.use_dora,
"modules_to_save": finetuning_args.additional_target,
"target_parameters": target_parameters,
Copy link
Owner

Choose a reason for hiding this comment

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

Is target parameters always be defined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending This problem is yet to be addressed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Integration of New PEFT Functionality - target_parameters for LoRA and state_dict-Based Adapter Injection

5 participants