Skip to content

Comments

fix(gemma2): Add quant_config to embedding layer for GGUF support#30424

Draft
kitaekatt wants to merge 1 commit intovllm-project:mainfrom
kitaekatt:fix/gemma2-embedding-quant-config
Draft

fix(gemma2): Add quant_config to embedding layer for GGUF support#30424
kitaekatt wants to merge 1 commit intovllm-project:mainfrom
kitaekatt:fix/gemma2-embedding-quant-config

Conversation

@kitaekatt
Copy link
Contributor

Summary

  • Adds quant_config parameter to VocabParallelEmbedding in Gemma2 model
  • Enables proper GGUF quantized embedding handling

Problem

Gemma2 GGUF models produce garbage output despite loading successfully:

Input: "Say hello in 5 words"
Output: " GHFW側から ThinkmariKeywords!");\rJahre Iliad幺个人..."

Root Cause

Without quant_config, VocabParallelEmbedding uses UnquantizedEmbeddingMethod which calls F.embedding() directly on quantized bytes, interpreting them as float values.

This is the exact same bug that was fixed for DeepSeek in commit aa375dca9 ("#12836 - Missing quant_config in deepseek embedding layer").

The Fix

 self.embed_tokens = VocabParallelEmbedding(
     config.vocab_size,
     config.hidden_size,
+    quant_config=quant_config,
+    prefix=f"{prefix}.embed_tokens",
 )

Comparison

Model quant_config Passed? GGUF Works?
Gemma2 ❌ NO (before fix) ❌ Garbage
Gemma3 ✅ YES ✅ Works
Llama ✅ YES ✅ Works
DeepSeek ✅ YES (after #12836) ✅ Works

Affected Models

All Gemma2 GGUF variants:

  • gemma-2-2b-it-GGUF
  • gemma-2-9b-GGUF
  • gemma-2-27b-GGUF

Test Plan

  • Gemma2 GGUF model loads without errors
  • Inference produces coherent output (not garbage)
  • Compare output quality with Gemma3 GGUF or safetensors Gemma2

🤖 Generated with Claude Code

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 addresses a critical bug where Gemma2 GGUF models would produce garbage output. The root cause was correctly identified: the VocabParallelEmbedding layer was missing the quant_config parameter, causing quantized weights to be misinterpreted. The provided fix, which passes both quant_config and the layer prefix to the embedding layer, is correct and aligns with the implementation in other models.

While reviewing, I noticed that vllm/model_executor/models/gemma.py seems to have the same vulnerability. Applying a similar fix there would likely resolve the issue for Gemma1 GGUF models as well, ensuring consistent behavior across the Gemma model family. This is a great fix, well done!

@kitaekatt kitaekatt force-pushed the fix/gemma2-embedding-quant-config branch from d41b71f to 5837f8e Compare December 15, 2025 20:30
@kitaekatt kitaekatt marked this pull request as ready for review December 15, 2025 20:30
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.

@kitaekatt kitaekatt marked this pull request as draft December 15, 2025 20:37
@kitaekatt kitaekatt force-pushed the fix/gemma2-embedding-quant-config branch from 5837f8e to 472b770 Compare December 29, 2025 20:43
@kitaekatt kitaekatt force-pushed the fix/gemma2-embedding-quant-config branch from 472b770 to 096b878 Compare January 19, 2026 17:27
The Gemma2 model was missing the quant_config parameter in the
VocabParallelEmbedding initialization, causing GGUF quantized
embeddings to be misinterpreted as float values.

Without quant_config, GGUF models use UnquantizedEmbeddingMethod
which calls F.embedding() directly on quantized bytes, resulting
in garbage output during inference.

This is the same bug that was fixed for DeepSeek in commit aa375dc
("Missing quant_config in deepseek embedding layer (vllm-project#12836)").

The fix adds:
- quant_config parameter to enable GGUFEmbeddingMethod selection
- prefix parameter for proper weight mapping

Fixes Gemma2 GGUF models (gemma-2-2b-it-GGUF, etc.) producing garbage
output like: " GHFW側から ThinkmariKeywords!")...

Signed-off-by: Christina <truffle@gmail.com>
@kitaekatt kitaekatt force-pushed the fix/gemma2-embedding-quant-config branch from 096b878 to 530a043 Compare February 5, 2026 00:18
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.

1 participant