base_model:
- Qwen/Qwen3-30B-A3B
datasets:
- eaddario/imatrix-calibration
language:
- en
license:
- apache-2.0
pipeline_tag: text-generation
tags:
- gguf
- quant
- pruned
- experimental
Experimental layer-wise + pruned (layers 5 and 39) quantization of Qwen/Qwen3-30B-A3B
Using LLaMA C++ release b5580 for quantization.
Original model: Qwen/Qwen3-30B-A3B
From the original model creators:
Qwen3 is the latest generation of large language models in Qwen series, offering a comprehensive suite of dense and mixture-of-experts (MoE) models. Built upon extensive training, Qwen3 delivers groundbreaking advancements in reasoning, instruction-following, agent capabilities, and multilingual support, with the following key features:
- Uniquely support of seamless switching between thinking mode (for complex logical reasoning, math, and coding) and non-thinking mode (for efficient, general-purpose dialogue) within single model, ensuring optimal performance across various scenarios.
- Significantly enhancement in its reasoning capabilities, surpassing previous QwQ (in thinking mode) and Qwen2.5 instruct models (in non-thinking mode) on mathematics, code generation, and commonsense logical reasoning.
- Superior human preference alignment, excelling in creative writing, role-playing, multi-turn dialogues, and instruction following, to deliver a more natural, engaging, and immersive conversational experience.
- Expertise in agent capabilities, enabling precise integration with external tools in both thinking and unthinking modes and achieving leading performance among open-source models in complex agent-based tasks.
- Support of 100+ languages and dialects with strong capabilities for multilingual instruction following and translation.
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, quantize the most important layers to higher bit precision and the less important to lower bits, and remove (prune) one or more layers. 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, and Xin Men's et al ShortGPT: Layers in Large Language Models are More Redundant Than You Expect
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).
A custom version of llama-quantize
is used to prune the model by providing a comma-separated list in the --prune-layers
command line option. The pruning operation will renumber remaining layers to avoid gaps in the sequence, update the relevant model metadata and, if an imatrix is available, it will use the correct importance score vector. This option can be used alongside --tensor-type
to perform tensor/layer-wise quantization on selected tensor types, whilst at the same time pruning others. For example:
llama-quantize --tensor-type attn=q6_k --prune-layers 3,7,11 --imatrix imatrix.dat model-f32.gguf model-q4_k_m.gguf q4_k_m
An enhanced version of llama-imatrix generates useful statistics to guide the tensor and layer selection process. --show-statistics
will display:
Tensor statistics:
- Σ(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)
Layer statistics:
- Σ(Bias): weighted average of the sum of all activations over the tensor (i.e. the Importance Scores)
- ZD Score: weighted average of the z-score distribution as described in 3.1 Layer Importance Scores in the Layer-Wise Quantization paper
- CosSim: weighted average of the cosine similarity of whole layer with respect to the previous layer (i.e. Layer 3 and 2)
Please note that tensor statistics are calculated for each individual 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 are two Pull Request (prune and imatrix) 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 (prune and imatrix).
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 if 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.
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 modelled, and it helps to counterbalance the negative effects of quantization and pruning.
The process to generate these models is roughly as follows:
- Convert the original model's tensors to GGUF F16*
- Estimate the Perplexity score for the F16 model (baseline) using the wikitext-2-raw-v1 dataset, and save the logits
- Generate an imatrix from selected calibration datasets
- Determine tensor and layer Importance Score contribution using the modified version of
llama-imatrix
- Select an appropriate quant level for each tensor and quantize/prune the model using
llama-quantize
. In this model's case, layers 5 and 39 have been pruned - Calculate Perplexity, KL Divergence, ARC (Easy+Challenge), HellaSwag, MMLU, Truthful QA and WinoGrande scores for each quantized model
- Keep versions with the best scores
- 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 | Unsltoth | Repo | Shrinkage |
---|---|---|---|---|
Qwen3-30B-A3B-pruned-IQ3_M | 14.1 | N/A | 13.5 | 4.3% |
Qwen3-30B-A3B-pruned-IQ3_S | 12.7 | N/A | 13.4 | -5.5% |
Qwen3-30B-A3B-pruned-IQ4_NL | 17.4 | 17.3 | 16.3 | 6.3% |
Qwen3-30B-A3B-pruned-Q3_K_L | 14.6 | N/A | 13.5 | 7.5% |
Qwen3-30B-A3B-pruned-Q3_K_M | 14.1 | 14.7 | 12.9 | 8.5% |
Qwen3-30B-A3B-pruned-Q3_K_S | 13.4 | 13.3 | 12.8 | 4.5% |
Qwen3-30B-A3B-pruned-Q4_K_M | 18.6 | 18.6 | 16.3 | 12.4% |
Qwen3-30B-A3B-pruned-Q4_K_S | 18.0 | 17.5 | 16.2 | 10.0% |
Qwen3-30B-A3B-pruned-Q5_K_M | 21.7 | 21.7 | 19.5 | 10.1% |
Qwen3-30B-A3B-pruned-Q5_K_S | 21.1 | 21.1 | 19.5 | 7.6% |
Qwen3-30B-A3B-pruned-Q6_K | 25.1 | 25.1 | 24.2 | 3.6% |
Qwen3-30B-A3B-pruned-Q8_0 | 32.5 | 32.5 | 28.6 | 12.0% |
Perplexity and KL Divergence scores
Model | μPPL | 𝜌PPL | μKLD | RMS Δp |
---|---|---|---|---|
Qwen3-30B-A3B-pruned-IQ3_M | 77.090453 ±1.044822 | 73.55% | 2.063818 ±0.006856 | 35.199 ±0.092 |
Qwen3-30B-A3B-pruned-IQ3_S | 69.935907 ±0.918185 | 72.89% | 1.997500 ±0.006825 | 35.474 ±0.092 |
Qwen3-30B-A3B-pruned-IQ4_NL | 58.059268 ±0.724129 | 73.87% | 1.827625 ±0.006356 | 35.013 ±0.093 |
Qwen3-30B-A3B-pruned-Q3_K_L | 60.855606 ±0.768774 | 73.47% | 1.886749 ±0.006413 | 35.285 ±0.093 |
Qwen3-30B-A3B-pruned-Q3_K_M | 59.072808 ±0.741897 | 73.82% | 1.857932 ±0.006326 | 35.157 ±0.092 |
Qwen3-30B-A3B-pruned-Q3_K_S | 61.676169 ±0.780539 | 73.64% | 1.888847 ±0.006380 | 35.283 ±0.093 |
Qwen3-30B-A3B-pruned-Q4_K_M | 58.664820 ±0.740540 | 74.32% | 1.826410 ±0.006359 | 34.806 ±0.092 |
Qwen3-30B-A3B-Q4_K_M-bartowski | 8.598264 ±0.067271 | 99.52% | 0.016689 ±0.000197 | 4.182 ±0.044 |
Qwen3-30B-A3B-Q4_K_M-unsloth | 8.715955 ±0.068797 | 99.37% | 0.022466 ±0.000223 | 4.803 ±0.044 |
Qwen3-30B-A3B-pruned-Q4_K_S | 57.925186 ±0.730332 | 74.48% | 1.813341 ±0.006327 | 34.669 ±0.092 |
Qwen3-30B-A3B-pruned-Q5_K_M | 57.654440 ±0.728232 | 74.66% | 1.794232 ±0.006308 | 34.464 ±0.092 |
Qwen3-30B-A3B-pruned-Q5_K_S | 57.254362 ±0.721067 | 74.56% | 1.792982 ±0.006300 | 34.527 ±0.092 |
Qwen3-30B-A3B-pruned-Q6_K | 56.914839 ±0.717086 | 74.60% | 1.786199 ±0.006314 | 34.465 ±0.092 |
Qwen3-30B-A3B-pruned-Q8_0 | 57.426860 ±0.724407 | 74.54% | 1.794528 ±0.006338 | 34.514 ±0.092 |
Qwen3-30B-A3B-pruned-F16 | 8.445938 ±0.065177 | 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 appropriate links: HellaSwag, ARC, MMLU, Truthful QA and WinoGrande
Model | ARC | HellaSwag | MMLU | Truthful QA | WinoGrande | Avg Score |
---|---|---|---|---|---|---|
Qwen3-30B-A3B-pruned-IQ3_M | 56.8000 ±1.8100 | 70.27 | 39.0667 ±1.7827 | 30.6667 ±1.6849 | 62.5333 ±1.7686 | 51.87 |
Qwen3-30B-A3B-pruned-IQ3_S | 48.5333 ±1.8262 | 68.67 | 37.0667 ±1.7648 | 32.0000 ±1.7045 | 63.8667 ±1.7553 | 50.03 |
Qwen3-30B-A3B-pruned-IQ4_NL | 61.7333 ±1.7759 | 71.20 | 40.9333 ±1.7967 | 30.9333 ±1.6889 | 65.8667 ±1.7325 | 54.13 |
Qwen3-30B-A3B-pruned-Q3_K_L | 57.8667 ±1.8042 | 71.73 | 38.6667 ±1.7794 | 32.2667 ±1.7082 | 65.2000 ±1.7405 | 53.15 |
Qwen3-30B-A3B-pruned-Q3_K_M | 56.4000 ±1.8119 | 70.80 | 39.3333 ±1.7849 | 31.6000 ±1.6988 | 64.8000 ±1.7451 | 52.59 |
Qwen3-30B-A3B-pruned-Q3_K_S | 58.1333 ±1.8026 | 71.47 | 38.9333 ±1.7816 | 30.9333 ±1.6889 | 63.0667 ±1.7635 | 52.51 |
Qwen3-30B-A3B-pruned-Q4_K_M | 60.5333 ±1.7860 | 71.47 | 41.8667 ±1.8026 | 30.9333 ±1.6889 | 66.1333 ±1.7292 | 54.19 |
Qwen3-30B-A3B-Q4_K_M-bartowski | 63.7333 ±1.7567 | 75.07 | 40.6667 ±1.7948 | 32.0000 ±1.7045 | 70.0000 ±1.6744 | 56.29 |
Qwen3-30B-A3B-Q4_K_M-unsloth | 63.7333 ±1.7567 | 74.53 | 40.8000 ±1.7958 | 32.1333 ±1.7063 | 70.0000 ±1.6744 | 56.24 |
Qwen3-30B-A3B-pruned-Q4_K_S | 60.8000 ±1.7838 | 71.07 | 41.4667 ±1.8002 | 31.0667 ±1.6909 | 66.4000 ±1.7259 | 54.16 |
Qwen3-30B-A3B-pruned-Q5_K_M | 60.4000 ±1.7870 | 70.53 | 41.4667 ±1.8002 | 30.9333 ±1.6889 | 65.3333 ±1.7389 | 53.73 |
Qwen3-30B-A3B-pruned-Q5_K_S | 61.0667 ±1.7816 | 70.93 | 42.0000 ±1.8034 | 30.6667 ±1.6849 | 67.3333 ±1.7137 | 54.40 |
Qwen3-30B-A3B-pruned-Q6_K | 60.8000 ±1.7838 | 71.60 | 42.0000 ±1.8034 | 30.9333 ±1.6889 | 66.2667 ±1.7276 | 54.32 |
Qwen3-30B-A3B-pruned-Q8_0 | 61.2000 ±1.7805 | 71.33 | 42.1333 ±1.8042 | 30.2667 ±1.6787 | 66.1333 ±1.7292 | 54.21 |
Qwen3-30B-A3B-pruned-F16 | 64.6667 ±1.7466 | 76.80 | 41.6000 ±1.8010 | 32.5333 ±1.7119 | 70.8000 ±1.6614 | 57.28 |
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 |
---|---|---|---|---|---|---|
Qwen3-30B-A3B-pruned-Q4_K_M | 15.20 GiB | 29.29 B | Metal,BLAS | 12 | pp512 | 1059.63 ±6.36 |
Qwen3-30B-A3B-pruned-Q4_K_M | 15.20 GiB | 29.29 B | Metal,BLAS | 12 | tg128 | 81.24 ±1.23 |
Qwen3-30B-A3B-pruned-Q4_K_M | 15.20 GiB | 29.29 B | Metal,BLAS | 12 | pp1024+tg1024 | 109.52 ±0.51 |
Qwen3-30B-A3B-Q4_K_M-bartowski | 17.35 GiB | 30.53 B | Metal,BLAS | 12 | pp512 | 1040.48 ±3.58 |
Qwen3-30B-A3B-Q4_K_M-bartowski | 17.35 GiB | 30.53 B | Metal,BLAS | 12 | tg128 | 77.05 ±0.54 |
Qwen3-30B-A3B-Q4_K_M-bartowski | 17.35 GiB | 30.53 B | Metal,BLAS | 12 | pp1024+tg1024 | 103.95 ±0.36 |
Qwen3-30B-A3B-Q4_K_M-unsloth | 17.28 GiB | 30.53 B | Metal,BLAS | 12 | pp512 | 864.89 ±88.42 |
Qwen3-30B-A3B-Q4_K_M-unsloth | 17.28 GiB | 30.53 B | Metal,BLAS | 12 | tg128 | 78.55 ±1.53 |
Qwen3-30B-A3B-Q4_K_M-unsloth | 17.28 GiB | 30.53 B | Metal,BLAS | 12 | pp1024+tg1024 | 104.90 ±0.97 |
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
LLaMa C++ has a large and vibrant community of contributors (~1,200 last time I checked) that actively maintain and extend its functionality, adding new models and architectures almost as fast as they appear (considering the breakneck speed at which the AI/ML field is advancing, this alone is a remarkable feat!), and whilst I'm grateful to each and everyone of them, I want to recognise three people in particular: Thank You! Colin Kealty for the many contributions and for being one of the best sources of high quality quantized models available on Hugging Face, and a really big Thank You! to Georgi Gerganov for his amazing work with llama.cpp and the ggml/gguf libraries, and Iwan Kawrakow for being one of the key authors behind the many quantisation algorithms and the imatrix functionality.