-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Fix LlamaModel_fast_forward signature to match HF Transformers (Support inputs_embeds) #3623
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
Summary of ChangesHello @MercuryYen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the flexibility of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly updates the LlamaModel_fast_forward function signature to make input_ids optional, aligning with the Hugging Face Transformers API. This change enables the use of inputs_embeds without input_ids, fixing a TypeError. The change is well-motivated and correctly implemented. I've added one comment regarding a minor improvement to related error messages for consistency. Since the error messages are outside the diff, I've added the comment to the changed line for visibility.
| def LlamaModel_fast_forward( | ||
| self, | ||
| input_ids: torch.LongTensor, | ||
| input_ids: Optional[torch.LongTensor] = None, |
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.
This change correctly makes input_ids optional, aligning with the Hugging Face API and enabling the use of inputs_embeds alone.
While reviewing, I noticed a minor inconsistency in the error messages within this function. The error messages on lines 802 and 810 refer to decoder_input_ids and decoder_inputs_embeds, but the function's parameters are input_ids and inputs_embeds.
For better clarity, you might want to update these error messages to use the correct parameter names. For example:
- Line 802:
"Unsloth: You cannot specify both input_ids and inputs_embeds at the same time" - Line 810:
"Unsloth: You have to specify either input_ids or inputs_embeds"
Since these lines are outside the current diff, I'm mentioning it here for your consideration.
|
Thanks a lot @MercuryYen ! |
Summary
This PR updates the
LlamaModel_fast_forwardfunction signature inunsloth/models/llama.pyto makeinput_idsoptional, defaulting toNone.Motivation
Currently, Unsloth requires
input_idsto be present, which prevents the model from acceptinginputs_embedsonly. This change aligns the Unsloth implementation with the original Hugging Face Transformers source code, whereinput_idsis optional.This fixes an issue where missing
input_idswould raise aTypeErroreven if embeddings were provided.Reference
This restores parity with the upstream implementation referenced in the code comments:
https://github.com/huggingface/transformers/blob/f7650253c477dd48c3cf3ff3d7b4f44f93ee62b9/src/transformers/models/llama/modeling_llama.py#L382