-
Notifications
You must be signed in to change notification settings - Fork 2.1k
add support for Feature Extraction using PEFT #647
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
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
The documentation is not available anymore as the PR was closed or merged. |
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'm still new to a lot of this, so I can't give a full review.
Here are some observations:
- I couldn't discern how the notebook
peft_prompt_tuning_seq2seq_with_generate.ipynbrelates to embeddings. Could this be elaborated? Also, it contains a big error message in the first cell. - The notebook
peft_lora_embedding_semantic_similarity.ipynbalso contains an error message at the end. If it takes too long to run, could the number of epochs or the dataset size be reduced? Or at least theKeyboardInterruptcould be caught gracefully to avoid showing the error. - In general, at least for me personally, it would be helpful if the notebooks could add a few sentences to explain what is going on and what the use case is.
- There are no tests for the new class. Are we okay with that? Will it be added later?
- Similarly, there is also no documentation for the new class (doc entry, docstring), even though this seems to be a big addition.
|
Hello @BenjaminBossan , the example is using PEFT Embedding Task to get embedding for queries and products and then uses them to get the cosine similarity between them to know whether the query and product are similar/relevant. Also, the first cell didn't have any error, it is just using dataset from cache. Yes, will be adding tests and docs. Also working on a full example on this. |
You mean in
Fantastic. I'll do another review once they are added. |
Those were due to |
Ah I see, so just disregard my comments about that notebook. |
stevhliu
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.
Thanks for adding a guide for such a cool use-case, this is great! 👏
Remember to add the docs to the toctree to properly build it!
Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
Done |
younesbelkada
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.
Very nice addition and learned a lot! I left 2 questions !
BenjaminBossan
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.
I focused on the documentation part for this review, will review the code once the tests pass.
Great docs overall, thanks for putting so much work into this. I have a few minor comments. Please take a look.
|
|
||
| ## Setup | ||
|
|
||
| Start by installing 🤗 PEFT from [source](https://moon-ci-docs.huggingface.co/docs/peft/pr_647/en/install#source), and then navigate to the directory containing the training scripts for fine-tuning DreamBooth with LoRA: |
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.
Should this be linking to moon-ci? Also, is it necessary to install from source? We plan to have the release very soon.
Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com>
Co-authored-by: Benjamin Bossan <BenjaminBossan@users.noreply.github.com>
younesbelkada
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.
Still looking great, thanks !
BenjaminBossan
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.
Overall, this looks good to me, nice work.
I have one concern left, however. According to the coverage report. the following lines are not covered by tests:
Lines 1614 to 1644 in e2f7ff8
| batch_size = input_ids.shape[0] | |
| if attention_mask is not None: | |
| # concat prompt attention mask | |
| prefix_attention_mask = torch.ones(batch_size, peft_config.num_virtual_tokens).to(attention_mask.device) | |
| attention_mask = torch.cat((prefix_attention_mask, attention_mask), dim=1) | |
| if kwargs.get("position_ids", None) is not None: | |
| warnings.warn("Position ids are not supported for parameter efficient tuning. Ignoring position ids.") | |
| kwargs["position_ids"] = None | |
| if kwargs.get("token_type_ids", None) is not None: | |
| warnings.warn("Token type ids are not supported for parameter efficient tuning. Ignoring token type ids") | |
| kwargs["token_type_ids"] = None | |
| kwargs.update( | |
| { | |
| "attention_mask": attention_mask, | |
| "output_attentions": output_attentions, | |
| "output_hidden_states": output_hidden_states, | |
| "return_dict": return_dict, | |
| } | |
| ) | |
| if peft_config.peft_type == PeftType.PREFIX_TUNING: | |
| past_key_values = self.get_prompt(batch_size) | |
| return self.base_model(input_ids=input_ids, past_key_values=past_key_values, **kwargs) | |
| else: | |
| if inputs_embeds is None: | |
| inputs_embeds = self.word_embeddings(input_ids) | |
| prompts = self.get_prompt(batch_size=batch_size) | |
| prompts = prompts.to(inputs_embeds.dtype) | |
| inputs_embeds = torch.cat((prompts, inputs_embeds), dim=1) | |
| return self.base_model(inputs_embeds=inputs_embeds, **kwargs) |
I double-checked locally and indeed I never hit those lines. When inspecting, only LoRA and IA³ are being tested. So should the tests be extended to include prompt learning or what could be done here?
…e/peft into smangrul/add-emb-task
latest commit should fix this |
BenjaminBossan
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.
Thanks for the fixes, this LGTM now.
|
This is great! Thanks for the support and for knocking off that old issue of mine. |
* add support for embedding with peft * add example and resolve code quality issues * update notebook example post fixing the loss * adding full example with inference notebook * quality ✨ * add tests, docs, guide and rename task_type to be inline with Hub * fixes * fixes * Apply suggestions from code review Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> * Update peft_model.py * fixes * final fixes * Update _toctree.yml * fixes and make style and make quality * deberta exception with checkpointing * Update docs/source/task_guides/semantic-similarity-lora.md Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> * Update docs/source/task_guides/semantic-similarity-lora.md Co-authored-by: Benjamin Bossan <BenjaminBossan@users.noreply.github.com> * resolve comments * testing prompt learning methods * Update testing_common.py * fix the tests --------- Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com> Co-authored-by: Younes Belkada <49240599+younesbelkada@users.noreply.github.com> Co-authored-by: Benjamin Bossan <BenjaminBossan@users.noreply.github.com>
What does this PR do?
AutoModelto get embeddings followed by postprocessing using that. One of the most popular use case of it is Semantic Similarity via Bi-Encoder models.ToDo: