Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gptqmodel/models/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
from .definitions.gemma3 import Gemma3ForConditionalGenerationGPTQ, Gemma3QModel # noqa: E402
from .definitions.gemma3n import Gemma3nForConditionalGenerationGPTQ, Gemma3nTextQModel # noqa: E402
from .definitions.gemma4 import Gemma4ForConditionalGenerationGPTQ, Gemma4TextQModel # noqa: E402
from .definitions.gemma4_unified import Gemma4UnifiedForConditionalGenerationGPTQ # noqa: E402
from .definitions.gemma4_unified import Gemma4UnifiedForConditionalGenerationGPTQ, Gemma4UnifiedTextQModel # noqa: E402
from .definitions.glm import GlmQModel # noqa: E402
from .definitions.glm4_moe import GLM4MoEGPTQ # noqa: E402
from .definitions.glm4_moe_lite import Glm4MoeLiteQModel # noqa: E402
Expand Down Expand Up @@ -256,6 +256,7 @@
"gemma3n": Gemma3nForConditionalGenerationGPTQ,
"gemma4_text": Gemma4TextQModel,
"gemma4": Gemma4ForConditionalGenerationGPTQ,
"gemma4_unified_text": Gemma4UnifiedTextQModel,
"gemma4_unified": Gemma4UnifiedForConditionalGenerationGPTQ,
"phi": PhiQModel,
"phi3": Phi3QModel,
Expand Down
2 changes: 1 addition & 1 deletion gptqmodel/models/definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from .gemma3 import Gemma3QModel
from .gemma3n import Gemma3nForConditionalGenerationGPTQ, Gemma3nTextQModel
from .gemma4 import Gemma4ForConditionalGenerationGPTQ, Gemma4TextQModel
from .gemma4_unified import Gemma4UnifiedForConditionalGenerationGPTQ
from .gemma4_unified import Gemma4UnifiedForConditionalGenerationGPTQ, Gemma4UnifiedTextQModel
from .glm import GlmQModel
from .glmasr import GlmASRGPTQ
from .glm_ocr import GlmOCRGPTQ
Expand Down
66 changes: 50 additions & 16 deletions gptqmodel/models/definitions/gemma4_unified.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ def _prepare_gemma4_unified_replay_kwargs(model_def, layer, layer_input, additio
return additional_inputs


# Shared decoder layout for both the composite (``gemma4_unified``) and text-only
# (``gemma4_unified_text``) variants: the standard Gemma sandwich-norm decoder with
# per-projection q/k/v norms. Unlike the per-layer-input Gemma 4 variants there is no
# per-layer input gate/projection, so those module-tree entries are intentionally absent.
_GEMMA4_UNIFIED_DECODER = {
"input_layernorm": ("input_layernorm:!",),
"self_attn": (
"q_norm:!",
"q_proj:0",
"k_norm:!",
"k_proj:0",
"v_norm:!",
"v_proj:0",
"o_proj:1",
),
"post_attention_layernorm": ("post_attention_layernorm:!",),
"pre_feedforward_layernorm": ("pre_feedforward_layernorm:!",),
"mlp": ("gate_proj:0", "up_proj:0", "down_proj:1"),
"post_feedforward_layernorm": ("post_feedforward_layernorm:!",),
}


class Gemma4UnifiedForConditionalGenerationGPTQ(BaseQModel):
"""Quantization definition for Gemma 4 unified (multimodal) checkpoints.

Expand All @@ -75,22 +97,34 @@ class Gemma4UnifiedForConditionalGenerationGPTQ(BaseQModel):
"language_model",
"layers",
"#",
{
"input_layernorm": ("input_layernorm:!",),
"self_attn": (
"q_norm:!",
"q_proj:0",
"k_norm:!",
"k_proj:0",
"v_norm:!",
"v_proj:0",
"o_proj:1",
),
"post_attention_layernorm": ("post_attention_layernorm:!",),
"pre_feedforward_layernorm": ("pre_feedforward_layernorm:!",),
"mlp": ("gate_proj:0", "up_proj:0", "down_proj:1"),
"post_feedforward_layernorm": ("post_feedforward_layernorm:!",),
},
_GEMMA4_UNIFIED_DECODER,
]

def prepare_layer_replay_kwargs(self, layer, layer_input, additional_inputs, target_device):
"""Refresh Gemma 4 unified rope kwargs during cached layer replay."""

return _prepare_gemma4_unified_replay_kwargs(self, layer, layer_input, additional_inputs, target_device)


class Gemma4UnifiedTextQModel(BaseQModel):
"""Quantization definition for text-only Gemma 4 unified checkpoints (``gemma4_unified_text``).

``Gemma4UnifiedTextModel`` is the standalone language stack of the unified family, so its
decoder layers live at ``model.layers`` (no ``language_model`` nesting) with the norm and
rotary embedding at ``model.norm`` / ``model.rotary_emb``. The quantizable layout is identical
to the composite variant, mirroring how ``gemma4_text`` parallels ``gemma4``.
"""

layer_modules_strict = False
support_batch_quantize = False
pre_lm_head_norm_module = "model.norm"
rotary_embedding = "model.rotary_emb"

module_tree = [
"model",
"layers",
"#",
_GEMMA4_UNIFIED_DECODER,
]

def prepare_layer_replay_kwargs(self, layer, layer_input, additional_inputs, target_device):
Expand Down