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

[Auto] Support AutoPeftModel for custom HF models #707

Merged
merged 2 commits into from
Jul 15, 2023

Conversation

younesbelkada
Copy link
Contributor

@younesbelkada younesbelkada commented Jul 14, 2023

What does this PR do?

Extends the recent PR: #694 by adding the support for all HF models: whisper, etc.

The logic is as follows:

  • Since if a user trains a model with task_type=None, it must be a custom model, we add to the peft config dictionary a new field termed as auto_mapping, responsible of storing all required information for retrieving back this class: https://huggingface.co/ybelkada/whisper-lora-test-auto-mapping/blob/main/adapter_config.json#L2
  • For users that want to register whisper/ sd etc models in the future to be compatible with AutoPeftModel they need to load the model from the Hub and push it again

Current API:

- from peft import PeftModel, PeftConfig, AutoPeftModel
+ from peft import AutoPeftModel
- from transformers import WhisperForConditionalGeneration

- model_id = "smangrul/openai-whisper-large-v2-LORA-colab"

peft_model_id = "smangrul/openai-whisper-large-v2-LORA-colab"
- peft_config = PeftConfig.from_pretrained(peft_model_id)
- model = WhisperForConditionalGeneration.from_pretrained(
-     peft_config.base_model_name_or_path, load_in_8bit=True, device_map="auto"
- )
- model = PeftModel.from_pretrained(model, peft_model_id)
+ model = AutoPeftModel.from_pretrained(peft_model_id)

Added tests for Whisper

cc @BenjaminBossan @pacman100

@younesbelkada younesbelkada marked this pull request as draft July 14, 2023 10:48
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jul 14, 2023

The documentation is not available anymore as the PR was closed or merged.

@younesbelkada younesbelkada marked this pull request as ready for review July 14, 2023 12:17
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.

LGTM, but it's outside my area of expertise, so let's wait for Sourab's review before merging.

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 @younesbelkada, this is a pretty cool way of retaining info on base modules/classes, enabling simplified UX for lot of tasks that aren't explicitly covered when using LoRAs. LGTM! 🚀

@younesbelkada younesbelkada merged commit 42ab106 into huggingface:main Jul 15, 2023
@younesbelkada younesbelkada deleted the auto-peft-model-custom branch July 15, 2023 12:19
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