Experimental layer-wise quantization of google/gemma-3-12b-it

Using LLaMA C++ release b5490 for quantization.

Original model: google/gemma-3-12b-it

From the original model creators:

Terms of Use: Terms

Authors: Google DeepMind

Model Information Summary description and brief definition of inputs and outputs.

Description Gemma is a family of lightweight, state-of-the-art open models from Google, built from the same research and technology used to create the Gemini models. Gemma 3 models are multimodal, handling text and image input and generating text output, with open weights for both pre-trained variants and instruction-tuned variants. Gemma 3 has a large, 128K context window, multilingual support in over 140 languages, and is available in more sizes than previous versions. Gemma 3 models are well-suited for a variety of text generation and image understanding tasks, including question answering, summarization, and reasoning. Their relatively small size makes it possible to deploy them in environments with limited resources such as laptops, desktops or your own cloud infrastructure, democratizing access to state of the art AI models and helping foster innovation for everyone.

Inputs and outputs Input:

Text string, such as a question, a prompt, or a document to be summarized Images, normalized to 896 x 896 resolution and encoded to 256 tokens each Total input context of 128K tokens for the 4B, 12B, and 27B sizes, and 32K tokens for the 1B size Output:

Generated text in response to the input, such as an answer to a question, analysis of image content, or a summary of a document Total output context of 8192 tokens Usage

PLEASE READ THIS BEFORE USING THESE EXPERIMENTAL VERSIONS!

An area of personal interest is finding ways to optimize the inference performance of LLMs when deployed in resource-constrained environments like commodity hardware, desktops, laptops, mobiles, edge devices, etc. There are many approaches to accomplish this, including architecture simplification and knowledge distillation, but my focus has been primarily on quantization and pruning.

The method used to produce these experimental versions is covered in Squeezing Tensor Bits: the quest for smaller LLMs, but at a high level it involves using a custom version of llama-imatrix and llama-quantize to identify influential tensors, and quantize the most important layers to higher bit precision and the less important to lower bits. This process was partly inspired by Dumitru's et al Layer-Wise Quantization: A Pragmatic and Effective Method for Quantizing LLMs Beyond Integer Bit-Levels.

As of version b5125 llama-quantize can now perform tensor-wide quantization (TWQ), whereby user-defined tensors are quantized at a specific level, or perform layer-wise quantization (LWQ) by selecting different quantization types per tensor/layer. For example, --tensor-type attn_v=q6_k will quantize all Attention Value tensors at q6_k (TWQ), and --tensor-type "\.([0-9]|1[01257]|31)\.attn_k=q4_k" will quantize Attention Key tensors on layers 0 to 9, 10, 11, 12, 15, 17 and 31 at q4_k, leaving the remaining layers at their default value (LWQ).

The modified version of llama-imatrix generates useful statistics to guide the tensor selection process, --show-statistics will display:

  • ฮฃ(Bias): the sum of all activations over the tensor (i.e. the Importance Scores)
  • Min & Max: minimum and maximum activation values
  • ฮผ & ฯƒ: activations' mean and standard deviation
  • % Active: proportion of elements whose average activation exceeds a very small threshold (1e-6). Helpful to determine how alive/dormant the tensor is during inference
  • N: number of activations in the tensor
  • Entropy: entropy of the activation distribution, in bits (standard Shannon entropy measurement)
  • E (norm): Normalized entropy.
  • ZD Score: z-score distribution as described in 3.1 Layer Importance Scores in the Layer-Wise Quantization paper
  • CosSim: cosine similarity between same type tensors with respect to the previous layer (i.e. blk.7.attn_k and blk.6.attn_k)

Please note that statistics are calculated for each individial tensor and should be used to compare between tensors of the same type only. For example, assuming that attn_k in layer 10 has a higher influence during inference than attn_k in layer 7 because its ฮฃ(Bias) is larger makes sense, whilst concluding the same between attn_k and ffn_down does not.

Thereโ€™s a pull request to merge these changes back into the core llama.cpp project. This may or may not ever happen so, until then, the modified version will be available on GitHub.

For testing and comparison I use models produced by Unsloth (Daniel and Michael Han do some really advanced level stuff!) and Bartowski (see credits below) but when they don't provide versions of the required model, all tests and comparisons are done against naive quantizations obtained by simply running llama-quantize with no further optimization. In this case however, whilst both have versions of this model, Unsloth's uses a different vocabulary size on their quants (262144 vs 262208) which makes a like-for-like comparison invalid.

All experimental versions were generated using an appropriate imatrix created from calibration datasets available at eaddario/imatrix-calibration. At its core, an Importance Matrix (imatrix) is a table or, more broadly, a structured representation that scores the relative importance of different features or parameters in a machine learning model. It essentially quantifies the "impact" each feature has on a specific outcome, prediction, or relationship being modeled, and it helps to counterbalance the negative effects of quantization and pruning.

The process to generate these models is roughly as follows:

  1. Convert the the original model's tensors to GGUF F16*
  2. Estimate the Perplexity score for the F16 model (baseline) using the wikitext-2-raw-v1 dataset, and save the logits
  3. Generate an imatrix from selected calibration datasets
  4. Determine tensor and layer Importance Score contribution using the modified version of llama-imatrix
  5. Select an appropiate quant level for each tensor and quantize the model using llama-quantize
  6. Calculate Perplexity, KL Divergence, ARC (Easy+Challenge), HellaSwag, MMLU, Truthful QA and WinoGrande scores for each quantized model
  7. Keep versions with the best scores
  8. Repeat until all desired quants are created. I find that quantizations below Q3/IQ3 are not fit for my purposes and therefore do not usually generate them, but happy to provide other quants on request.

*BF16 would be preferred, but Apple's GPUs don't support it yet, and therefore any operations are executed in the CPU, making it unacceptably slow. This is expected to change in the near term but until then, if you are using Apple kit avoid using any models tagged BF16

Models

Sizes (in GB)

Model Bartowski Repo Shrinkage
gemma-3-12b-it-IQ3_M 5.66 5.41 4.4%
gemma-3-12b-it-IQ3_S 5.21 5.23 -0.4%
gemma-3-12b-it-IQ4_NL 6.89 6.39 7.3%
gemma-3-12b-it-Q3_K_L 6.48 5.52 14.8%
gemma-3-12b-it-Q3_K_M 6.01 5.22 13.1%
gemma-3-12b-it-Q3_K_S 5.46 4.99 8.6%
gemma-3-12b-it-Q4_K_M 7.30 6.43 11.9%
gemma-3-12b-it-Q4_K_S 6.94 6.40 7.8%
gemma-3-12b-it-Q5_K_M 8.44 7.61 9.8%
gemma-3-12b-it-Q5_K_S 8.23 7.58 7.9%
gemma-3-12b-it-Q6_K 9.66 9.37 3.0%
gemma-3-12b-it-Q8_0 12.50 11.40 8.8%

Perplexity and KL Divergence scores

Model ฮผPPL ๐œŒPPL ฮผKLD RMS ฮ”p
gemma-3-12b-it-IQ3_M 9.819911 ยฑ0.080440 95.67% 0.189526 ยฑ0.001269 12.497 ยฑ0.068
gemma-3-12b-it-IQ3_S 9.844402 ยฑ0.079485 94.86% 0.232563 ยฑ0.001411 13.899 ยฑ0.069
gemma-3-12b-it-IQ4_NL 9.784609 ยฑ0.080899 97.10% 0.121353 ยฑ0.000786 10.126 ยฑ0.059
gemma-3-12b-it-Q3_K_L 10.193888 ยฑ0.083697 94.26% 0.261491 ยฑ0.001586 14.559 ยฑ0.072
gemma-3-12b-it-Q3_K_M 9.860796 ยฑ0.078875 93.95% 0.273903 ยฑ0.001588 15.007 ยฑ0.072
gemma-3-12b-it-Q3_K_S 10.351147 ยฑ0.082692 92.32% 0.360147 ยฑ0.001863 17.074 ยฑ0.072
gemma-3-12b-it-Q4_K_M 9.788871 ยฑ0.080127 97.05% 0.127527 ยฑ0.000807 10.439 ยฑ0.060
gemma-3-12b-it-Q4_K_M-bartowski 9.197963 ยฑ0.073909 98.63% 0.045560 ยฑ0.000416 6.400 ยฑ0.054
gemma-3-12b-it-Q4_K_S 9.791993 ยฑ0.080114 97.02% 0.129268 ยฑ0.000813 10.528 ยฑ0.060
gemma-3-12b-it-Q5_K_M 9.492645 ยฑ0.076969 98.44% 0.060229 ยฑ0.000376 7.340 ยฑ0.046
gemma-3-12b-it-Q5_K_S 9.495540 ยฑ0.077022 98.44% 0.060458 ยฑ0.000376 7.343 ยฑ0.045
gemma-3-12b-it-Q6_K 9.380805 ยฑ0.075743 98.88% 0.041053 ยฑ0.000229 6.061 ยฑ0.037
gemma-3-12b-it-Q8_0 9.350086 ยฑ0.075331 99.00% 0.036289 ยฑ0.000190 5.712 ยฑ0.034
gemma-3-12b-it-F16 9.042786 ยฑ0.071503 100% N/A N/A

ARC, HellaSwag, MMLU, Truthful QA and WinoGrande scores

Scores generated using llama-perplexity with 750 tasks per test, and a context size of 768 tokens.

For the test data used in the generation of these scores, follow the appropiate links: HellaSwag, ARC, MMLU, Truthful QA and WinoGrande

Model ARC HellaSwag MMLU Truthful QA WinoGrande Avg Score
gemma-3-12b-it-IQ3_M 69.0667 +/- 1.6889 79.60 43.0667 +/- 1.8093 36.9333 +/- 1.7635 73.7333 +/- 1.6080 60.48
gemma-3-12b-it-IQ3_S 67.2000 +/- 1.7155 79.20 43.4667 +/- 1.8113 40.4000 +/- 1.7930 73.2000 +/- 1.6184 60.69
gemma-3-12b-it-IQ4_NL 68.8000 +/- 1.6929 79.06 43.0667 +/- 1.8093 39.0667 +/- 1.7827 73.7333 +/- 1.6080 60.75
gemma-3-12b-it-Q3_K_L 68.6667 +/- 1.6949 78.26 43.4667 +/- 1.8113 39.4667 +/- 1.7860 72.6667 +/- 1.6284 60.51
gemma-3-12b-it-Q3_K_M 68.0000 +/- 1.7045 78.93 42.9333 +/- 1.8086 39.8667 +/- 1.7890 71.7333 +/- 1.6453 60.29
gemma-3-12b-it-Q3_K_S 66.9333 +/- 1.7190 78.80 42.9333 +/- 1.8086 40.0000 +/- 1.7900 70.2667 +/- 1.6702 59.79
gemma-3-12b-it-Q4_K_M 70.6667 +/- 1.6636 80.67 42.8000 +/- 1.8079 40.1333 +/- 1.7910 74.0000 +/- 1.6027 61.65
gemma-3-12b-it-Q4_K_M-bartowski 69.6000 +/- 1.6807 81.07 43.6000 +/- 1.8119 41.0667 +/- 1.7976 75.7333 +/- 1.5664 62.21
gemma-3-12b-it-Q4_K_S 70.2667 +/- 1.6702 80.67 43.0667 +/- 1.8093 40.2667 +/- 1.7920 74.4000 +/- 1.5947 61.73
gemma-3-12b-it-Q5_K_M 68.4000 +/- 1.6988 81.47 45.0667 +/- 1.8180 40.2667 +/- 1.7920 75.3333 +/- 1.5751 62.11
gemma-3-12b-it-Q5_K_S 68.6667 +/- 1.6949 81.46 44.5333 +/- 1.8160 40.1333 +/- 1.7910 74.9333 +/- 1.5836 61.95
gemma-3-12b-it-Q6_K 68.9333 +/- 1.6909 81.07 44.4000 +/- 1.8155 41.0667 +/- 1.7976 75.0667 +/- 1.5808 62.11
gemma-3-12b-it-Q8_0 68.0000 +/- 1.7045 80.93 44.0000 +/- 1.8138 40.9333 +/- 1.7967 75.4667 +/- 1.5722 61.87
gemma-3-12b-it-F16 69.2000 +/- 1.6869 81.20 45.3333 +/- 1.8190 41.4667 +/- 1.8002 74.8000 +/- 1.5864 62.40

Tokens per Second - Benchmarks

Scores generated using llama-bench. Naive (llama-quantize with no optimization) Q4_K_M quantization included for comparison.

model size params backend threads test t/s
gemma-3-12b-it-Q4_K_M 5.98 GiB 11.77 B Metal,BLAS 12 pp512 504.86 ยฑ 1.32
gemma-3-12b-it-Q4_K_M 5.98 GiB 11.77 B Metal,BLAS 12 tg128 44.13 ยฑ 0.18
gemma-3-12b-it-Q4_K_M 5.98 GiB 11.77 B Metal,BLAS 12 pp1024+tg1024 72.53 ยฑ 0.37
gemma-3-12b-it-Q4_K_M-bartowski 6.79 GiB 11.77 B Metal,BLAS 12 pp512 530.98 ยฑ 0.51
gemma-3-12b-it-Q4_K_M-bartowski 6.79 GiB 11.77 B Metal,BLAS 12 tg128 45.54 ยฑ 0.16
gemma-3-12b-it-Q4_K_M-bartowski 6.79 GiB 11.77 B Metal,BLAS 12 pp1024+tg1024 74.36 ยฑ 0.41

Metrics used

Perplexity: one of the key metrics used in NLP evaluation. It measures the quality of a language model by evaluating how well it predicts the next token given a particular sequence of words. A PPL of 1 indicates an exact match between predicted and actual, whereas values greater than one indicate a degree of "surprise" the generated token differs from the expected.

Kullbackโ€“Leibler (KL) Divergence: a statistical measure of how much a probability distribution differs from another. When quantizing models (or altering the original tensors in any way for that matter), the closest we can preserve the weights' probability distribution to the original model the better, thus the closest to 0 the better.

AI2 Reasoning Challenge (ARC): a benchmark to evaluate the ability of AI models to answer complex science questions that require logical reasoning beyond pattern matching.

HellaSwag: the Harder Endings, Longer contexts, and Low-shot Activities for Situations With Adversarial Generations (bit of a mouthful!) is a benchmark designed to test commonsense natural language inference. It requires the model to predict the most likely ending of a sentence.

MMLU: the Massive Multitask Language Understanding evaluates LLMsโ€™ general knowledge and problem-solving abilities across 57 subjects, including elementary mathematics, US history, computer science, and law.

Truthful QA: evaluates how well LLMs generate truthful responses to questions. It identifies whether AI models can avoid generating false or misleading information, particularly in areas where human knowledge is prone to misconceptions.

Winogrande: based on the Winograd Schema Challenge, is a natural language understanding task requiring models to resolve ambiguities in sentences involving pronoun references.

Credits

A big Thank You! to Colin Kealty for the many contributions and for being one of the best sources of high quality quantized models available on Huggingface, and a really big Thank You! to Georgi Gerganov for his amazing work with llama.cpp and the ggml/gguf libraries.

Downloads last month
235
GGUF
Model size
11.8B params
Architecture
gemma3
Hardware compatibility
Log In to view the estimation

3-bit

4-bit

5-bit

6-bit

8-bit

16-bit

Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for eaddario/gemma-3-12b-it-GGUF

Quantized
(88)
this model

Dataset used to train eaddario/gemma-3-12b-it-GGUF