Experimental layer-wise quantization of deepseek-ai/DeepSeek-R1-Distill-Qwen-7B

Using LLaMA C++ release b5120 for quantization.

Original model: deepseek-ai/DeepSeek-R1-Distill-Qwen-7B

From the original model creators:

DeepSeek-R1-Zero, a model trained via large-scale reinforcement learning (RL) without supervised fine-tuning (SFT) as a preliminary step, demonstrated remarkable performance on reasoning. With RL, DeepSeek-R1-Zero naturally emerged with numerous powerful and interesting reasoning behaviors. However, DeepSeek-R1-Zero encounters challenges such as endless repetition, poor readability, and language mixing. To address these issues and further enhance reasoning performance, we introduce DeepSeek-R1, which incorporates cold-start data before RL. DeepSeek-R1 achieves performance comparable to OpenAI-o1 across math, code, and reasoning tasks. To support the research community, we have open-sourced DeepSeek-R1-Zero, DeepSeek-R1, and six dense models distilled from DeepSeek-R1 based on Llama and Qwen. DeepSeek-R1-Distill-Qwen-32B outperforms OpenAI-o1-mini across various benchmarks, achieving new state-of-the-art results for dense models.

NOTE: Before running DeepSeek-R1 series models locally, we kindly recommend reviewing the Usage Recommendation section.

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 custom versions of llama-imatrix and llama-quantize to identify the 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.

There’re two pull requests (imatrix & quantize) to merge these changes back into the core llama.cpp project. This may or may not ever happen so, until then, the modified versions 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).

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 a modified version of llama-imatrix
  5. Select an appropiate quant level for each tensor using a modified version of 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 Unsloth Repo Shrinkage
DeepSeek-R1-Distill-Qwen-7B-IQ3_M 3.57 N/A 3.48 2.5%
DeepSeek-R1-Distill-Qwen-7B-IQ3_S N/A N/A 3.26 N/A
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 4.44 N/A 4.18 5.9%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 4.09 N/A 3.54 13.4%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 3.81 3.81 3.37 11.5%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 3.49 N/A 3.14 10.0%
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 4.68 4.68 4.18 10.7%
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S 4.46 N/A 4.06 9.0%
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 5.44 5.44 5.09 6.4%
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 5.32 N/A 4.97 6.6%
DeepSeek-R1-Distill-Qwen-7B-Q6_K 6.25 6.25 6.23 0.3%
DeepSeek-R1-Distill-Qwen-7B-Q8_0 8.10 8.10 7.27 10.2%

Perplexity and KL Divergence scores

Model μPPL 𝜌PPL μKLD RMS Δp
DeepSeek-R1-Distill-Qwen-7B-IQ3_M 28.740047 ±0.291290 97.19% 0.229742 ±0.000770 11.793 ±0.050
DeepSeek-R1-Distill-Qwen-7B-IQ3_S 30.290800 ±0.307742 96.32% 0.310982 ±0.001014 13.415 ±0.057
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 23.570503 ±0.226124 98.59% 0.102854 ±0.000465 8.080 ±0.046
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 24.160705 ±0.229989 97.75% 0.173336 ±0.000603 10.337 ±0.048
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 24.967196 ±0.239198 97.50% 0.194299 ±0.000681 10.877 ±0.050
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 25.661098 ±0.246635 96.84% 0.243850 ±0.000852 12.143 ±0.054
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 23.125382 ±0.221860 99.24% 0.053997 ±0.000215 5.795 ±0.032
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S 23.156199 ±0.222000 99.18% 0.058337 ±0.000233 6.026 ±0.034
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 22.726887 ±0.217691 99.75% 0.013562 ±0.000062 2.924 ±0.020
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 22.766826 ±0.218244 99.74% 0.014589 ±0.000070 3.024 ±0.020
DeepSeek-R1-Distill-Qwen-7B-Q6_K 22.859294 ±0.219461 99.87% 0.004317 ±0.000022 1.682 ±0.016
DeepSeek-R1-Distill-Qwen-7B-Q8_0 22.840693 ±0.219408 99.90% 0.001614 ±0.000011 1.050 ±0.010
DeepSeek-R1-Distill-Qwen-7B-F16 22.656280 ±0.216110 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
DeepSeek-R1-Distill-Qwen-7B-IQ3_M 50.4000 ±1.8269 55.73 31.3333 ±1.6949 26.4000 ±1.6106 59.7333 ±1.7920 45.78
DeepSeek-R1-Distill-Qwen-7B-IQ3_S 43.8667 ±1.8132 53.87 30.5333 ±1.6828 26.2667 ±1.6080 57.8667 ±1.8042 44.51
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 50.6667 ±1.8268 57.60 32.8000 ±1.7155 28.2667 ±1.6453 60.5333 ±1.7860 46.24
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 48.5333 ±1.8262 56.93 30.4000 ±1.6807 27.0667 ±1.6235 59.8667 ±1.7910 46.49
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 48.1333 ±1.8257 56.27 29.8667 ±1.6723 27.3333 ±1.6284 59.8667 ±1.7910 46.28
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 48.0000 ±1.8255 55.47 28.5333 ±1.6500 26.0000 ±1.6027 59.2000 ±1.7958 46.03
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 52.5333 ±1.8246 58.53 32.1333 ±1.7063 26.2667 ±1.6080 60.9333 ±1.7827 45.39
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-bartowski 50.9358 ±1.8291 60.67 35.8667 ±1.7525 28.7037 ±2.5171 61.0667 ±1.7816 47.45
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-unsloth 50.5348 ±1.8293 57.07 31.0667 ±1.6909 29.5031 ±2.5455 61.2000 ±1.7805 45.87
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S 52.4000 ±1.8249 58.40 31.8667 ±1.7026 25.8667 ±1.6001 61.4667 ±1.7783 46.84
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 52.8000 ±1.8241 59.33 32.6667 ±1.7137 27.2000 ±1.6260 60.1333 ±1.7890 46.40
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 52.9333 ±1.8238 59.60 32.8000 ±1.7155 27.0667 ±1.6235 61.2000 ±1.7805 46.02
DeepSeek-R1-Distill-Qwen-7B-Q6_K 53.0667 ±1.8235 59.07 31.3333 ±1.6949 26.9333 ±1.6209 60.5333 ±1.7860 47.85
DeepSeek-R1-Distill-Qwen-7B-Q8_0 53.0667 ±1.8235 58.67 32.2667 ±1.7082 26.9333 ±1.6209 60.2667 ±1.7880 45.29
DeepSeek-R1-Distill-Qwen-7B-F16 52.9333 ±1.8238 58.67 32.1333 ±1.7063 26.6667 ±1.6158 60.0000 ±1.7900 46.81

Tokens per Second - Benchmarks

Scores generated using llama-bench. Q4_K_M quantizations from Bartowski and Unsloth included for comparison.

model size params backend threads test t/s
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 3.89 GiB 7.62 B Metal,BLAS 6 pp512 333.33 ± 3.02
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 3.89 GiB 7.62 B Metal,BLAS 6 tg128 29.14 ± 0.16
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 3.89 GiB 7.62 B Metal,BLAS 6 pp1024+tg1024 48.07 ± 0.09
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-bartowski 4.36 GiB 7.62 B Metal,BLAS 6 pp512 354.27 ± 0.64
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-bartowski 4.36 GiB 7.62 B Metal,BLAS 6 tg128 27.95 ± 0.04
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-bartowski 4.36 GiB 7.62 B Metal,BLAS 6 pp1024+tg1024 46.60 ± 0.16
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-unsloth 4.36 GiB 7.62 B Metal,BLAS 6 pp512 352.93 ± 0.92
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-unsloth 4.36 GiB 7.62 B Metal,BLAS 6 tg128 27.66 ± 0.08
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M-unsloth 4.36 GiB 7.62 B Metal,BLAS 6 pp1024+tg1024 46.40 ± 0.45

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 in Hugginface, and a really big Thank You! to Georgi Gerganov for his amazing work with llama.cpp and the ggml/gguf libraries.

Downloads last month
1,958
GGUF
Model size
7.62B params
Architecture
qwen2
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/DeepSeek-R1-Distill-Qwen-7B-GGUF

Quantized
(138)
this model

Dataset used to train eaddario/DeepSeek-R1-Distill-Qwen-7B-GGUF