-
Notifications
You must be signed in to change notification settings - Fork 31.5k
Include output embedding as well with include_embedding flag
#37935
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbf88b5
Include output embedding as well with `include_embedding` flag
jerryzh168 b66730f
format
jerryzh168 927ef1f
rename include_embedding to include_input_output_embeddings
jerryzh168 2299706
Merge branch 'main' into quantize-lm-head
jerryzh168 cf64410
Merge branch 'main' into quantize-lm-head
jerryzh168 040e2e0
Merge branch 'main' into quantize-lm-head
MekkCyber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 not sure if it's a good idea to quantize the
lm_headwhen the flaginclude_embeddingis set 🤔 , it's a bit misleadingThere 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.
lm_head is the output embedding right?
e.g. https://github.com/vllm-project/vllm/blob/aea302be6c3c323207502a973fe341c3bcf7288f/vllm/model_executor/models/llama.py#L457
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.
also:
transformers/src/transformers/models/llama/modeling_llama.py
Lines 736 to 743 in 46c0e1f
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.
Yes it is, but it's still a
nn.Linearnot ann.EmbeddingThere 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.
About
embeddingsandlm_head, there are some edge cases we need to be aware of.If they are tied:
lm_headas is, the memory consumption will increase (due to thelm-head) but maybe we have latency improvement ?. Maybe you also want to quantize the lm-head differently ?Do we have a specific use case for 2) as I think this is what you wanted to do @jerryzh168 ?
Uh oh!
There was an error while loading. Please reload this page.
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.
yeah we have a use case in ExecuTorch, where we quantize both input embedding and lm_head, and we quantize them differently, the way we are doing it right now is:
(1) manually break ties
(2) quantize the input embedding and lm_head separately
see details in https://huggingface.co/pytorch/Phi-4-mini-instruct-8da4w#quantization-recipe
right now we need to set
modules_to_not_convertand this PR will allow use to removemodules_to_not_convertAlso I feel we might be able to remove the untie_embedding_weights flag now since we have an alternative solution.
Please also take a look our solution for manually untying the weights, it might be useful to have some API for it as well
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.
@MekkCyber how about changing the name to
include_input_output_embeddingsto be more specific on what we are referring to?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.
Yes, I think it’s fine as long as the user is aware that they’re quantizing the lm_head.
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.
makes sense, just updated