-
-
Notifications
You must be signed in to change notification settings - Fork 20.5k
[Bugfix] Consolidate Gemma2/3 GGUF fixes for correctness on Blackwell #37220
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
Open
kitaekatt
wants to merge
5
commits into
vllm-project:main
Choose a base branch
from
kitaekatt:fix/gemma-gguf-consolidated
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fff7e08
fix(gguf): Consolidate Gemma2/3 GGUF fixes for correctness on Blackwell
kitaekatt c3ac087
Merge branch 'main' into fix/gemma-gguf-consolidated
kitaekatt c7a1a30
refactor: Extract _get_norm_cls helper to reduce duplication
kitaekatt 5befed8
Merge remote-tracking branch 'upstream/main' into fix/gemma-gguf-cons…
kitaekatt 86fa040
refactor(gguf): Extract maybe_patch_gguf_tokenizer helper
kitaekatt 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,12 +7,16 @@ | |
|
|
||
| from transformers import AutoTokenizer, PreTrainedTokenizer, PreTrainedTokenizerFast | ||
|
|
||
| from vllm.logger import init_logger | ||
| from vllm.transformers_utils.config import get_sentence_transformer_tokenizer_config | ||
| from vllm.transformers_utils.gguf_utils import extract_eos_token_id_from_gguf | ||
|
|
||
| from .protocol import TokenizerLike | ||
|
|
||
| HfTokenizer: TypeAlias = PreTrainedTokenizer | PreTrainedTokenizerFast | ||
|
|
||
| logger = init_logger(__name__) | ||
|
|
||
|
|
||
| def get_cached_tokenizer(tokenizer: HfTokenizer) -> HfTokenizer: | ||
| """ | ||
|
|
@@ -81,6 +85,9 @@ def from_pretrained( | |
| download_dir: str | None = None, | ||
| **kwargs, | ||
| ) -> HfTokenizer: | ||
| # Save gguf_file before AutoTokenizer.from_pretrained() pops it from kwargs | ||
| gguf_file = kwargs.get("gguf_file") | ||
|
|
||
| try: | ||
| tokenizer = AutoTokenizer.from_pretrained( | ||
| path_or_repo_id, | ||
|
|
@@ -122,4 +129,23 @@ def from_pretrained( | |
| } | ||
| tokenizer.add_special_tokens(special_tokens_map) | ||
|
|
||
| # Patch EOS token ID from GGUF metadata if available | ||
| # GGUF files may have a different EOS token ID than HF tokenizer config | ||
| # (e.g., Gemma uses <end_of_turn> ID 106 as EOS, but HF reports <eos> ID 1) | ||
| # Note: gguf_file was saved above before | ||
| # AutoTokenizer.from_pretrained() popped it | ||
| if gguf_file: | ||
| gguf_path = Path(path_or_repo_id) / gguf_file | ||
| gguf_eos_id = extract_eos_token_id_from_gguf(str(gguf_path)) | ||
| if gguf_eos_id is not None: | ||
| hf_eos_id = tokenizer.eos_token_id | ||
| if hf_eos_id != gguf_eos_id: | ||
| logger.info( | ||
| "Patching tokenizer eos_token_id from %d to %d " | ||
| "(using GGUF metadata)", | ||
| hf_eos_id, | ||
| gguf_eos_id, | ||
| ) | ||
| tokenizer.eos_token_id = gguf_eos_id | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we provided a repo id instead of local path here? BTW, I prefer to add an extra def maybe_patch_gguf_tokenizer(
tokenizer,
path_or_repo_id: str,
**kwargs,
):
...
maybe_patch_gguf_tokenizer(...) |
||
|
|
||
| return get_cached_tokenizer(tokenizer) | ||
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
Oops, something went wrong.
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.
The logic to determine the normalization class based on the quantization config is duplicated in
Gemma2DecoderLayerandGemma2Modelwithin this file, and also multiple times invllm/model_executor/models/gemma3.py. This code duplication increases maintenance overhead and the risk of introducing inconsistencies in the future if the logic needs to be updated.To improve this, you could extract the logic into a module-level helper function. For example:
This helper can then be called from all the locations where this logic is needed, making the code more DRY and easier to maintain.
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.
Can you address this?
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.
Done in c7a1a30 — extracted
_get_norm_cls()helper in bothgemma2.pyandgemma3.py. All 5 occurrences now use it.