[torch] Add gemma4 LLM template and GPTQ algo config for MoE quantization - #40
Open
jimmy-adams wants to merge 1 commit into
Open
[torch] Add gemma4 LLM template and GPTQ algo config for MoE quantization#40jimmy-adams wants to merge 1 commit into
jimmy-adams wants to merge 1 commit into
Conversation
Enable mxfp4_weight_only + GPTQ on Gemma4 via built-in template exclude patterns and per-expert GPTQ module lists. Co-authored-by: Cursor <cursoragent@cursor.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #39
Summary
Add built-in
gemma4template and GPTQ algo config so Gemma4 MoE models (e.g.google/gemma-4-26B-A4B) can be quantized via the standardquantize_quark.pyCLI without hand-rolled configs.Diff: +41 lines in 2 files (
template.py,algo_configs.py).Changes
template.py—gemma4*language_model.*{k,v}_proj*language_model.*q_projlm_head,router.projSplitFusedExpertsfor fusedgate_up_proj/down_projalgo_configs.py—gemma4GPTQself_attn.*, densemlp.*, and unfusedexperts.*.{gate,up,down}_projmodel.language_model.layersValidation (mxfp4_weight_only RTN)
Verified on full
google/gemma-4-26B-A4Bcheckpoint:QuarkExpertsunfused, 11,725 Linear quantizedKnown limitation (out of scope)
Unfused per-expert GPTQ on 128-expert Gemma4 can fail with
Hessian not positive-definiteon cold experts (insufficient calibration tokens). RTN / weight-only paths work; GPTQ improvements (fused-expert path or cold-expert fallback) tracked separately.Test plan
mxfp4_weight_onlyRTN on Gemma4-26B-A4B — passMade with Cursor