-
Notifications
You must be signed in to change notification settings - Fork 2.2k
intorduce AdaDoRA implementation using both DoRA and AdaLoRa together #2969
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
Adds weight-decomposed adaptation to AdaLoRA, introducing a learnable magnitude vector and DoRA-scaled forward/merge paths. Propagates configuration to layers and model, updates rank allocation to skip magnitude params, and recalculates magnitudes after pruning/masking. Introduces a GLUE finetuning script that wires AdaLoRA/DoRA, computes total steps for scheduling, and updates rank allocation via a training callback. Improves flexibility by supporting DoRA in AdaLoRA, safer merging, and clearer training integration; unmerging for DoRA remains unsupported.
- Added AdaDoraLinearLayer for handling AdaLoRA's 3-factor decomposition. - Introduced AdaDoraLinearVariant for managing variant-specific operations. - Updated AdaLoraLayer to support DoRA integration and manage variants. - Enhanced SVDLinear to utilize the new variant pattern for merging and unmerging. - Implemented tests for AdaDoraLinearLayer and AdaDoraLinearVariant to ensure functionality. - Updated AdaLoraModel to handle magnitude updates after rank pruning. - Added uv.lock file for dependency management.
…tation after rank pruning
BenjaminBossan
left a comment
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.
Thanks for opening a new PR to add DoRA support to AdaLoRA. I did a first review pass which focused on the general design of the implementation, I haven't done a detailed check of the DoRA logic or the example yet, as it makes more sense to finalize the integration first. Please check my comments.
I also saw that there are unrelated changes in the PR, like changing capitalization of comments or adding the uv lock file. Could you please revert all those changes? Finally, please run make style to ensure the linter is happy.
Moreover, before the PR can be merged, the docs should be updated, but we can leave this for later.
Co-authored-by: Benjamin Bossan <[email protected]>
Co-authored-by: Benjamin Bossan <[email protected]>
- Merge lora_magnitude_vector check with main conditional (with parentheses) - Remove internal exports (AdaDoraLinearLayer, AdaDoraLinearVariant) - Remove obsolete test_adalora_use_dora_raises test - Move run_glue.py to examples/adalora_adadora/ with README
The method was a no-op (just pass) since resetting magnitude after pruning disabled DoRA by making the ratio m/||W+ΔW|| = 1. Removed the dead code for cleanliness.
Per reviewer feedback: variant resolution now happens inside the base class after _move_adapter_to_device_of_base_layer, ensuring correct ordering. SVDLinear just overrides resolve_lora_variant() to return the AdaDoRA variant.
Per reviewer feedback: consistent with LoRA DoRA implementation. Added _compute_lora_weight helper to compute B @ (A * E) * scaling / ranknum externally instead of inside get_weight_norm.
BenjaminBossan
left a comment
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.
Thanks for the updates. I did another review and still found a few areas for improvement, please check my comments.
Co-authored-by: Benjamin Bossan <[email protected]>
keep new ones with lowercase
- Add AdaDoRA config to ALL_CONFIGS test matrix - Delete test_adalora_dora.py (covered by existing tests) - Fix variants.py get_weight_norm calls Addresses review comments from @BenjaminBossan in PR huggingface#2969
…lue for weight normalization and adapter output
Resolved merge conflicts from upstream's update_layer refactoring. Updated to extract use_dora from config object while maintaining backward compatibility. Tests passing.
Resolved conflicts by adapting AdaDoRA to upstream's config-based API. - Updated update_layer() signature to accept AdaLoraConfig parameter - Extract use_dora from config to preserve AdaDoRA functionality - Updated SVDLinear.__init__() to use config object - Updated all module instantiations to pass config=lora_config - Kept fan_in_fan_out in kwargs for Conv1D detection All tests passing for both vanilla AdaLoRA and AdaDoRA variants.
Resolved conflicts by adapting AdaDoRA to upstream's config-based API. - Updated update_layer() signature to accept AdaLoraConfig parameter - Extract use_dora from config to preserve AdaDoRA functionality - Updated SVDLinear.__init__() to use config object - Updated all module instantiations to pass config=lora_config - Kept fan_in_fan_out in kwargs for Conv1D detection All tests passing for both vanilla AdaLoRA and AdaDoRA variants.
|
Summary of Changes
Old: Individual parameters (lora_dropout, init_lora_weights, use_dora, etc.)
Before: Computed lora_weight twice (once for norm, once for result) compute lora_weight oncelora_weight = self._compute_lora_weight(lora_A, lora_B, lora_E, scaling, ranknum) reuse for weight norm (detached)weight_norm = self.get_weight_norm(weight, lora_weight.detach()) reuse for adapter outputlora_result = x @ lora_weight.T
Before: Incorrectly added to base AdaLoraLayer.adapter_layer_names Before: Checked both if use_dora: and if lora_variant is not None: Inline links: Added hyperlinks to AdaLoRA and DoRA papers in introduction Citation section: Added: AdaLoraConfig(use_dora=True) to ALL_CONFIGS test matrix Vanilla AdaLoRA: 6/6 passing (all models) |
This pull request introduces support for AdaDoRA (AdaLoRA with DoRA) to the codebase, enabling the use of DoRA (Weight-Decomposed Low-Rank Adaptation) within the AdaLoRA framework. The main changes add new modules and configuration options to support this, update the initialization and management of adapter layers, and provide a new GLUE finetuning script that demonstrates AdaLoRA/DoRA usage.
Key changes include:
AdaDoRA (DoRA for AdaLoRA) Support
AdaDoraLinearLayerclass inadalora/dora.py, implementing DoRA's magnitude vector and forward logic for AdaLoRA's SVD decomposition, including proper handling of singular values and rank pruning.adalora/__init__.pyto exportAdaDoraLinearLayerandAdaDoraLinearVariantfor external use.adalora/config.pyto allowuse_dora(DoRA) in AdaLoRA by removing the previous error, enabling AdaDoRA configuration.Adapter Layer and Variant Management
AdaLoraLayerinadalora/layer.pyto:lora_magnitude_vectorinadapter_layer_namesfor DoRA support.lora_variantdictionary to manage per-adapter variants (e.g., AdaDoRA).use_doraflag and resolve the correct variant, including initialization of the AdaDoRA variant if requested.Utilities and Imports
LoraVariantintoadalora/layer.pyto support adapter variants.Example and Usage
scripts/run_glue.pythat demonstrates finetuning for GLUE tasks with AdaLoRA and AdaDoRA, including argument parsing for DoRA options, correct PEFT configuration, and integration of the new AdaLoRA/DoRA callback.These changes collectively enable AdaLoRA models to leverage DoRA-style adaptation,while using extending dora.py implementation in LoRA module, with full support in both the core library and example scripts.