Experimental layer-wise quantization of deepseek-ai/DeepSeek-R1-Distill-Llama-8B

Using LLaMA C++ release b5120 for quantization.

Original model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B

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-Llama-8B-IQ3_M 3.78 N/A 3.69 2.5%
DeepSeek-R1-Distill-Llama-8B-IQ3_S N/A N/A 3.43 N/A
DeepSeek-R1-Distill-Llama-8B-IQ4_NL 4.68 N/A 4.39 6.1%
DeepSeek-R1-Distill-Llama-8B-Q3_K_L 4.32 N/A 3.76 13.0%
DeepSeek-R1-Distill-Llama-8B-Q3_K_M 4.02 4.02 3.56 11.3%
DeepSeek-R1-Distill-Llama-8B-Q3_K_S 3.66 N/A 3.31 9.7%
DeepSeek-R1-Distill-Llama-8B-Q4_K_M 4.92 4.92 4.41 10.5%
DeepSeek-R1-Distill-Llama-8B-Q4_K_S 4.69 N/A 4.28 8.8%
DeepSeek-R1-Distill-Llama-8B-Q5_K_M 5.73 5.73 5.38 6.2%
DeepSeek-R1-Distill-Llama-8B-Q5_K_S 5.60 N/A 5.24 6.4%
DeepSeek-R1-Distill-Llama-8B-Q6_K 6.60 6.60 6.57 0.5%
DeepSeek-R1-Distill-Llama-8B-Q8_0 8.54 8.54 7.73 9.4%

Perplexity and KL Divergence scores

Model μPPL 𝜌PPL μKLD RMS Δp
DeepSeek-R1-Distill-Llama-8B-IQ3_M 16.574922 ±0.145677 94.24% 0.367217 ±0.001523 15.613 ±0.067
DeepSeek-R1-Distill-Llama-8B-IQ3_S 17.505471 ±0.156184 92.97% 0.465573 ±0.001748 17.507 ±0.069
DeepSeek-R1-Distill-Llama-8B-IQ4_NL 14.243482 ±0.113690 96.12% 0.240811 ±0.001175 13.331 ±0.064
DeepSeek-R1-Distill-Llama-8B-Q3_K_L 15.685298 ±0.134793 94.79% 0.321187 ±0.001430 14.828 ±0.069
DeepSeek-R1-Distill-Llama-8B-Q3_K_M 15.756085 ±0.134240 94.45% 0.341147 ±0.001464 15.306 ±0.069
DeepSeek-R1-Distill-Llama-8B-Q3_K_S 16.481412 ±0.138861 92.23% 0.469890 ±0.001833 17.842 ±0.072
DeepSeek-R1-Distill-Llama-8B-Q4_K_M 13.991103 ±0.118848 98.03% 0.121711 ±0.000730 9.041 ±0.056
DeepSeek-R1-Distill-Llama-8B-Q4_K_S 14.070792 ±0.119167 97.72% 0.139625 ±0.000813 9.709 ±0.058
DeepSeek-R1-Distill-Llama-8B-Q5_K_M 13.259667 ±0.110576 98.94% 0.062326 ±0.000539 6.358 ±0.053
DeepSeek-R1-Distill-Llama-8B-Q5_K_S 13.254089 ±0.110505 98.85% 0.068798 ±0.000581 6.644 ±0.053
DeepSeek-R1-Distill-Llama-8B-Q6_K 13.223880 ±0.110295 99.19% 0.047895 ±0.000556 5.514 ±0.059
DeepSeek-R1-Distill-Llama-8B-Q8_0 13.204903 ±0.110236 99.26% 0.043927 ±0.000549 5.242 ±0.061
DeepSeek-R1-Distill-Llama-8B-F16 13.052024 ±0.108483 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-Llama-8B-IQ3_M 49.0667 ±1.8266 70.80 34.6667 ±1.7389 30.4000 ±1.6807 66.1333 ±1.7292 50.21
DeepSeek-R1-Distill-Llama-8B-IQ3_S 48.0000 ±1.8255 70.67 32.1333 ±1.7063 28.5333 ±1.6500 65.0667 ±1.7420 48.88
DeepSeek-R1-Distill-Llama-8B-IQ4_NL 51.6000 ±1.8260 74.53 33.7333 ±1.7276 34.8000 ±1.7405 67.8667 ±1.7063 52.51
DeepSeek-R1-Distill-Llama-8B-Q3_K_L 51.8667 ±1.8257 70.80 34.8000 ±1.7405 31.2000 ±1.6929 67.7333 ±1.7082 51.28
DeepSeek-R1-Distill-Llama-8B-Q3_K_M 52.6667 ±1.8244 70.80 35.0667 ±1.7436 30.5333 ±1.6828 67.7333 ±1.7082 51.36
DeepSeek-R1-Distill-Llama-8B-Q3_K_S 51.4667 ±1.8262 71.87 32.8000 ±1.7155 31.4667 ±1.6968 67.7333 ±1.7082 51.07
DeepSeek-R1-Distill-Llama-8B-Q4_K_M 49.8667 ±1.8270 72.40 37.6000 ±1.7699 31.4667 ±1.6968 68.5333 ±1.6968 51.97
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-bartowski 50.3347 ±1.8306 74.40 34.8000 ±1.7405 37.1069 ±2.7133 69.4667 ±1.6828 53.22
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-unsloth 52.4766 ±1.8284 73.20 33.2000 ±1.7207 36.0000 ±2.6667 68.4000 ±1.6988 52.66
DeepSeek-R1-Distill-Llama-8B-Q4_K_S 50.2667 ±1.8269 72.00 36.0000 ±1.7539 31.4667 ±1.6968 67.2000 ±1.7155 51.39
DeepSeek-R1-Distill-Llama-8B-Q5_K_M 51.4667 ±1.8262 73.73 36.2667 ±1.7567 32.2667 ±1.7082 68.4000 ±1.6988 52.43
DeepSeek-R1-Distill-Llama-8B-Q5_K_S 51.4667 ±1.8262 73.73 35.4667 ±1.7481 32.4000 ±1.7100 67.6000 ±1.7100 52.13
DeepSeek-R1-Distill-Llama-8B-Q6_K 50.4000 ±1.8269 74.13 36.1333 ±1.7553 31.3333 ±1.6949 67.6000 ±1.7100 51.92
DeepSeek-R1-Distill-Llama-8B-Q8_0 50.1333 ±1.8270 74.13 37.0667 ±1.7648 32.1333 ±1.7063 67.7333 ±1.7082 52.24
DeepSeek-R1-Distill-Llama-8B-F16 50.0000 ±1.8270 74.40 36.6667 ±1.7608 32.0000 ±1.7045 67.7333 ±1.7082 52.16

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-Llama-8B-Q4_K_M 4.10 GiB 8.03 B Metal,BLAS 6 pp512 310.89 ± 2.20
DeepSeek-R1-Distill-Llama-8B-Q4_K_M 4.10 GiB 8.03 B Metal,BLAS 6 tg128 27.69 ± 0.26
DeepSeek-R1-Distill-Llama-8B-Q4_K_M 4.10 GiB 8.03 B Metal,BLAS 6 pp1024+tg1024 44.43 ± 0.24
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-bartowski 4.58 GiB 8.03 B Metal,BLAS 6 pp512 329.03 ± 0.11
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-bartowski 4.58 GiB 8.03 B Metal,BLAS 6 tg128 25.79 ± 0.92
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-bartowski 4.58 GiB 8.03 B Metal,BLAS 6 pp1024+tg1024 42.35 ± 0.93
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-unsloth 4.58 GiB 8.03 B Metal,BLAS 6 pp512 328.93 ± 0.15
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-unsloth 4.58 GiB 8.03 B Metal,BLAS 6 tg128 26.43 ± 0.01
DeepSeek-R1-Distill-Llama-8B-Q4_K_M-unsloth 4.58 GiB 8.03 B Metal,BLAS 6 pp1024+tg1024 42.38 ± 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

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
2,052
GGUF
Model size
8.03B params
Architecture
llama
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-Llama-8B-GGUF

Quantized
(153)
this model

Dataset used to train eaddario/DeepSeek-R1-Distill-Llama-8B-GGUF