-
Notifications
You must be signed in to change notification settings - Fork 216
Add extract adapters support for dora and loha #1611
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
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.
Can you remove this condition in the peft export helper
Line 48 in 50f360a
or getattr(module, "use_dora", {}).get(module.active_adapters[0], False) |
Otherwise, the lora scaling factors appears in the graph and would need to be extracted also since it is not the same for all adapters.
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.
Removed.
output + default (lora_A) -> MatMul -> ... | ||
output + default_1 (lora_B) -> MatMul -> ... | ||
|
||
DoRA: |
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.
I looked at the exported graph for a dora model after the scaling change above. the lora matmuls appear twice in the computation.
Also, the Add weight doesn't need to be extracted. It is just the transpose of the base weight and comes from this step https://github.com/huggingface/peft/blob/363c14e673a12d19f951609d06221962d5c3eb2a/src/peft/tuners/lora/dora.py#L78. This is constant for a model.
What needs to be extracted is the weight in the Div node that depends on the lora weights.
https://github.com/huggingface/peft/blob/363c14e673a12d19f951609d06221962d5c3eb2a/src/peft/tuners/lora/dora.py#L86
https://github.com/huggingface/peft/blob/363c14e673a12d19f951609d06221962d5c3eb2a/src/peft/tuners/lora/dora.py#L63
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.
Ideally, during export, we can precompute https://github.com/huggingface/peft/blob/main/src/peft/tuners/lora/dora.py#L70-L86 so that ConstantOfShape
-> Reshape
doesn't appear in the graph (more compute + memory because of the duplicated transposed base weight) and we just have the mag_norm_scale
weight directly in the graph. But I think this can be done later if needed and is out of scope for this PR.
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 pointing this out! I double checked the graph and updated the code to use Div rather Add for now!
Describe your changes
Add extract adapters support for dora and loha.
Checklist before requesting a review
lintrunner -a
(Optional) Issue link