-
Notifications
You must be signed in to change notification settings - Fork 117
[PEFT] feat: Add support for temporary disable adapter #1811
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?
Conversation
|
@HollowMan6 lgtm, need unit tests though. |
1e1fc6f to
cec3e49
Compare
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.
Pull request overview
This PR adds support for temporarily disabling and re-enabling adapter layers in PEFT (Parameter-Efficient Fine-Tuning) implementations, providing functionality similar to HuggingFace's PEFT library. This allows users to temporarily bypass adapter computations and fall back to the base model behavior without removing or unloading the adapters.
Key changes:
- Added
_adapter_enabledflag toAdapterWrapperbase class withenable_adapter_layers()anddisable_adapter_layers()methods - Implemented model-level
enable_adapter_layers(),disable_adapter_layers(), anddisable_adapter()context manager in thePEFTbase class - Updated all adapter forward methods to check the
_adapter_enabledflag and return only base output when disabled - Refactored model walking logic into reusable
_walk_model()helper method
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/megatron/bridge/peft/adapter_wrapper.py | Added _adapter_enabled flag and enable/disable methods to AdapterWrapper base class |
| src/megatron/bridge/peft/base.py | Added model-level enable/disable methods, disable_adapter context manager, and refactored model walking logic into _walk_model() helper |
| src/megatron/bridge/peft/lora_layers.py | Updated LoRALinear and TEFusedLoRALinear forward methods to check adapter enabled flag and updated docstring |
| src/megatron/bridge/peft/dora_layers.py | Updated DoRALinear forward method to check adapter enabled flag |
| src/megatron/bridge/peft/canonical_lora.py | Updated LoRALinearSplitQKV and LoRALinearSplitFC1UpGate forward methods to check adapter enabled flag |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Similar to: https://github.com/huggingface/peft/blob/261366de2e40cde64b702d6b9c527081ad850549/src/peft/mixed_model.py#L192-L201 `enable_adapter_layers` and `disable_adapter_layers` are alternatives if users want to control manually. Signed-off-by: Hollow Man <[email protected]>
Signed-off-by: Hollow Man <[email protected]>
73bdc06 to
a3bb972
Compare
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.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Hollow Man <[email protected]>
What does this PR do ?
Similar to:
https://github.com/huggingface/peft/blob/261366de2e40cde64b702d6b9c527081ad850549/src/peft/mixed_model.py#L192-L201
enable_adapter_layersanddisable_adapter_layersare alternatives if users want to control manually.Can be used for volcengine/verl#4673
Changelog
GitHub Actions CI
See the CI sectionin the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.
Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information
✨ Presented to you with Mind Lab - A Lab for Experiential Intelligence.