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

[docs] Lora-like guides #1371

Merged
merged 5 commits into from
Feb 7, 2024
Merged

[docs] Lora-like guides #1371

merged 5 commits into from
Feb 7, 2024

Conversation

stevhliu
Copy link
Member

As discussed in #1332, this PR condenses the LoRA guides by showcasing one specific task type (image classification) and redirecting to other use cases/tasks stored on the PEFT Hub org. Instead, this guide expands on the other LoRA methods such as LoHa, LoKr, and AdaLoRA. The configs of these methods aren't optimized for the best performance, so any feedback you have on that would be super useful!

@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.

Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

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

Thank you @stevhliu for consolidating all the LoRA like guides into a single guide while focusing on usage of different LoRA variants. Thank you for the HF Space collection of notebook examples.

Left a few suggestions and comments.

docs/source/task_guides/lora_based_methods.md Outdated Show resolved Hide resolved
docs/source/task_guides/lora_based_methods.md Outdated Show resolved Hide resolved
docs/source/task_guides/lora_based_methods.md Show resolved Hide resolved
Copy link
Contributor

@pacman100 pacman100 left a comment

Choose a reason for hiding this comment

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

Thank you! 🤗

Copy link
Contributor

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

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

Thanks @stevhliu !

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 for writing this excellent guide and consolidating the different methods. Overall, this looks really good, I just have a concern regarding the use of AdaLora. Please check the comment and the solutions I suggested.

</hfoption>
<hfoption id="AdaLoRA">

[AdaLoRA](../conceptual_guides/adapter#adaptive-low-rank-adaptation-adalora) efficiently manages the LoRA parameter budget by assigning important weight matrices more parameters and pruning less important ones. In contrast, LoRA evenly distributes parameters across all modules. You can control the average desired *rank* or `r` of the matrices, and which modules to apply AdaLoRA to with `target_modules`. Other important parameters to set are `lora_alpha` (scaling factor), and `modules_to_save` (the modules apart from the AdaLoRA layers to be trained and saved). All of these parameters - and more - are found in the [`AdaLoraConfig`].
Copy link
Member

Choose a reason for hiding this comment

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

There is a bit of an issue with the AdaLora example. For AdaLora, we need to call the method update_and_allocate during each training step, otherwise, the adaptation step is not performed. This requires to either write a custom training loop or to subclass the Trainer to add this step. An example of a custom training loop that calls this method is here:

model.base_model.update_and_allocate(global_step)

Given this guide, as is, the reader may not be aware that this is required and thus use AdaLora incorrectly. These solutions come to mind:

  1. Don't provide the AdaLora example. Instead, refer to the existing examples with custom training loops.
  2. Don't use Trainer, instead use a custom training loop that calls this method when AdaLora is being used.
  3. Subclass Trainer to perform this step if AdaLora is being used. I don't know enough about Trainer to be really sure how to do that correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point! I mention update_and_allocate + link to a custom training loop in a Warning in the training section for more visibility. I think we should still keep the example of showing the AdaLoraConfig though so users still know how to set it up.

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.

Happy with the added warning, thanks for adding it.

@stevhliu stevhliu merged commit 9bb83ed into huggingface:main Feb 7, 2024
14 checks passed
@stevhliu stevhliu deleted the lora-guides branch February 7, 2024 19:22
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
* loras

* review

* fix

* feedback

* feedback
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.

5 participants