-
Notifications
You must be signed in to change notification settings - Fork 2.1k
[docs] Task guide for semantic segmentation with LoRA #307
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] Task guide for semantic segmentation with LoRA #307
Conversation
|
The documentation is not available anymore as the PR was closed or merged. |
pacman100
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.
Thank you @MKhalusova for this nice usage guide on semantic segmentation using lora! ✨
Left a comment.
cc @sayakpaul for a quick look as he had worked on this example
| Let's review the `LoraConfig`. To enable LoRA technique, we must define the target modules within `LoraConfig` so that | ||
| `PeftModel` can update the necessary matrices. Specifically, we want to target the `query` and `value` matrices in the | ||
| attention blocks of the base model. These matrices are identified by their respective names, "query" and "value". | ||
| Therefore, we should specify these names in the `target_modules` argument of `LoraConfig`. | ||
|
|
||
| After we wrap our base model `model` with `PeftModel` along with the config, we get | ||
| a new model where only the LoRA parameters are trainable (so-called "update matrices") while the pre-trained parameters | ||
| are kept frozen. These include the parameters of the randomly initialized classifier parameters too. This is NOT we want | ||
| when fine-tuning the base model on our custom dataset. To ensure that the classifier parameters are also trained, we | ||
| specify `modules_to_save`. This also ensures that these modules are serialized alongside the LoRA trainable parameters | ||
| when using utilities like `save_pretrained()` and `push_to_hub()`. | ||
|
|
||
| In addition to specifying the `target_modules` within `LoraConfig`, we also need to specify the `modules_to_save`. When | ||
| we wrap our base model with `PeftModel` and pass the configuration, we obtain a new model in which only the LoRA parameters | ||
| are trainable, while the pre-trained parameters and the randomly initialized classifier parameters are kept frozen. | ||
| However, we do want to train the classifier parameters. By specifying the `modules_to_save` argument, we ensure that the | ||
| classifier parameters are also trainable, and they will be serialized alongside the LoRA trainable parameters when we | ||
| use utility functions like `save_pretrained()` and `push_to_hub()`. | ||
|
|
||
| Let's review the rest of the parameters: | ||
|
|
||
| - `r`: The dimension used by the LoRA update matrices. | ||
| - `alpha`: Scaling factor. | ||
| - `bias`: Specifies if the `bias` parameters should be trained. `None` denotes none of the `bias` parameters will be trained. |
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.
insightful and easy to follow!
sayakpaul
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.
Oh we are going hf.co/docs/peft. Wow, that is so cool!
Let's ship this! 🚀
Co-authored-by: Sourab Mangrulkar <13534540+pacman100@users.noreply.github.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. |
* WIP: semantic segmentation example * make style * some polishing * Update docs/source/task_guides/semantic_segmentation_lora.mdx Co-authored-by: Sourab Mangrulkar <13534540+pacman100@users.noreply.github.com> * minor update --------- Co-authored-by: Sourab Mangrulkar <13534540+pacman100@users.noreply.github.com>
Moves LoRA for semantic segmentation notebook into the docs.