Skip to content
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

Feat: add support for Conv2D DoRA #1516

Merged
merged 14 commits into from
Mar 12, 2024
Merged

Feat: add support for Conv2D DoRA #1516

merged 14 commits into from
Mar 12, 2024

Conversation

sayakpaul
Copy link
Member

@sayakpaul sayakpaul commented Feb 28, 2024

TODO

  • Incorporate _apply_dora() in the forward() of Conv2D
  • merge()
  • unmerge()
  • Tests
  • Docs

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@sayakpaul
Copy link
Member Author

@BenjaminBossan would love to get your thoughts on the changes I have introduced so far here.

@BenjaminBossan
Copy link
Member

Thanks a lot Sayak, this already looks pretty good. Probably the main thing to get right is the dimensions across which to normalize, which does look correct to me. Maybe there is also some room to speed up the application of the norm, not sure.

As a next step, let's add a test case for Conv2d + DoRA. This should be as easy as adding an example or two here:

("Vanilla MLP 7 LoRA with DoRA", "MLP", LoraConfig, {"target_modules": ["lin0"], "use_dora": True}),
("Vanilla MLP 8 LoRA with DoRA", "MLP", LoraConfig, {"target_modules": ["lin0", "lin1"], "use_dora": True}),
(
"Vanilla MLP 9 LoRA with DoRA",
"MLP",
LoraConfig,
{"target_modules": "lin1", "use_dora": True, "lora_alpha": 32},
),
("Embedding + transformers Conv1D 1 LoRA", "EmbConv1D", LoraConfig, {"target_modules": ["conv1d"]}),
("Embedding + transformers Conv1D 2 LoRA", "EmbConv1D", LoraConfig, {"target_modules": ["emb"]}),
("Embedding + transformers Conv1D 3 LoRA", "EmbConv1D", LoraConfig, {"target_modules": ["emb", "conv1d"]}),
("Conv2d 1 LoRA", "Conv2d", LoraConfig, {"target_modules": ["conv2d"]}),
("Conv2d 2 LoRA", "Conv2d", LoraConfig, {"target_modules": ["conv2d", "lin0"]}),

Let's do this and check if the tests pass, then plan the next steps.

@sayakpaul sayakpaul marked this pull request as ready for review March 12, 2024 10:55
@sayakpaul
Copy link
Member Author

@BenjaminBossan I think this is ready for a review now.

@sayakpaul
Copy link
Member Author

Cc: @nbasyl if you want to give this a look as well.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

This looks pretty good, thanks a lot for enabling DoRA with Conv2d. Curious to see if we can get nice improvements for diffusion models.

Implementation-wise, I have only a few minor comments. On top of those, could you please document the new changes here:

  • The docstring of use_dora inside of tuners/lora/config.py still mentions that only linear layers are supported.
  • Same for the help of use_dora in the same file.
  • docs/source/developer_guide/lora.md also needs updating with regard to the supported layers.

Before merging, it would be nice to have another review.

Edit: Please also merge with recent main, as there could be merge conflicts with #1518 otherwise.

src/peft/tuners/lora/layer.py Outdated Show resolved Hide resolved
src/peft/tuners/lora/layer.py Outdated Show resolved Hide resolved
tests/test_custom_models.py Outdated Show resolved Hide resolved
@sayakpaul
Copy link
Member Author

@BenjaminBossan resolved your comments. Thank you!

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Thanks a lot, Sayak, the PR looks great. Let's see if Shih-yang also has time to take a look. Otherwise, I'd be glad to have a second pair of eyes by @younesbelkada or @pacman100.

src/peft/tuners/lora/config.py Show resolved Hide resolved
@nbasyl
Copy link

nbasyl commented Mar 12, 2024

The PR looks great, I have skimmed through the code and did not notice any problems. @sayakpaul, Thanks for the effort!

@BenjaminBossan BenjaminBossan merged commit 3b63996 into main Mar 12, 2024
14 checks passed
@BenjaminBossan
Copy link
Member

Thanks so much Sayak.

@sayakpaul sayakpaul deleted the feat/conv-dora branch March 12, 2024 15:25
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants