Skip to content

quant : keep qwen4exp control tensors unquantized - #33685

Open
fish2lab wants to merge 1 commit into
ggml-org:masterfrom
fish2lab:quant/qwen4exp-protect-control-tensors
Open

fish2lab wants to merge 1 commit into
ggml-org:masterfrom
fish2lab:quant/qwen4exp-protect-control-tensors

Conversation

@fish2lab

@fish2lab fish2lab commented Dec 4, 2026

Copy link
Copy Markdown

Overview

Exclude hc_*, ssm_beta, ssm_alpha, and ple_conv1d from default quantization for LLM_ARCH_QWEN4EXP in tensor_allows_quantization(). Without this rule, llama-quantize quantizes these small hyper-connection, linear-attention gate, and depthwise-conv tensors unless overridden manually with --tensor-type, whereas ggml-org/Qwen4-35B-A3B-GGUF keeps them in BF16 (reporting ~25-29% lower KL divergence for <1% size overhead).

This matches the existing exclusions for neighboring hybrid architectures in src/llama-quant.cpp:

if (arch == LLM_ARCH_GLM5_NEXT) {
quantize &= name.find("hc_") == std::string::npos;
quantize &= name.find("indexer.attn_q_b") == std::string::npos;
quantize &= name.find("indexer.attn_k") == std::string::npos;
quantize &= name.find("indexer.proj") == std::string::npos;
quantize &= name.find("indexer_compressor_gate") == std::string::npos;
quantize &= name.find("indexer_compressor_ape") == std::string::npos;
quantize &= name.find("ssm_f_a.weight") == std::string::npos;
quantize &= name.find("ssm_f_b.weight") == std::string::npos;
quantize &= name.find("ssm_g_a.weight") == std::string::npos;
quantize &= name.find("ssm_g_b.weight") == std::string::npos;
quantize &= name.find("ssm_beta.weight") == std::string::npos;
quantize &= name.find("attn_kv_a_mqa.weight") == std::string::npos;
quantize &= name.find("attn_k_b.weight") == std::string::npos;
quantize &= name.find("attn_v_b.weight") == std::string::npos;
}
// xing4_0: do not quantize the MHC hyper-connection gate matrices
// (the 1D hc_*_base / hc_*_scale tensors are already excluded by the n_dims < 2 rule)
if (arch == LLM_ARCH_XING4_0) {
quantize &= name.find("hc_") == std::string::npos;
}
// raon1_mini: mHC selectors and small RDA gate projections
if (arch == LLM_ARCH_RAON1_MINI) {
quantize &= name.find("hc_") == std::string::npos;
quantize &= name.find("ssm_f_a.weight") == std::string::npos;
quantize &= name.find("ssm_f_b.weight") == std::string::npos;
quantize &= name.find("ssm_beta.weight") == std::string::npos;
quantize &= name.find("ssm_rda.weight") == std::string::npos;
}

indexer.k_proj.weight and indexer.q_proj.weight are already excluded globally above, and 1D norm tensors are already skipped by ggml_n_dims(tensor) < 2. Matching hc_, ssm_beta, ssm_alpha, and ple_conv1d covers both merged and unmerged variants (hc_*_down_inject, output_hc_*, nextn.hc_head_*, ssm_beta_alpha, and ple_conv1d whose ne[0] = 4 previously fell back to F16).

Verification

Built llama-quantize and test-quantize-fns on macOS arm64 (Release), ran test-quantize-fns (all passing), and compared unpatched master (a4e5552) vs patched llama-quantize across Q4_K_M, Q8_0, and Q2_K on a synthetic BF16 qwen4exp GGUF containing all merged/unmerged control tensors:

  • output_hc_{down,up}, blk.0.hc_{attn,ffn}_*, blk.1.nextn.hc_head_{down,up}: Q4_K/Q8_0/Q2_K -> BF16
  • blk.0.ssm_{beta_alpha,beta,alpha}: Q4_K/Q8_0/Q2_K -> BF16
  • blk.0.ple_conv1d: F16 -> BF16
  • All other tensors (token_embd, output, ssm_out, attn_qkv_gate, ple_{key,value}, ffn_*_exps): unchanged

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Gemini was used to inspect src/llama-quant.cpp / src/models/qwen4exp.cpp, implement the 8-line exclusion block, and run the synthetic before/after quantization check; all changes were reviewed by the author.

Written with Gemini

@fish2lab
fish2lab requested a review from a team as a code owner December 4, 2026 10:40
@ngxson

ngxson commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

whereas ggml-org/Qwen4-35B-A3B-GGUF keeps them in BF16 (reporting ~25-29% lower KL divergence for <1% size overhead).

please post complete results from llama-bench and llama-perplexity. The < 1% really depends on hw and quant type

This branch has not been deployed

No deployments
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.

2 participants