base_model:
- deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
datasets:
- eaddario/imatrix-calibration
language:
- en
license:
- mit
pipeline_tag: text-generation
tags:
- gguf
- quant
- experimental
Experimental GGUF quantized versions of deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
Using LLaMA C++ release b4783 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, edge devices, etc. There are many approaches to accomplish this, including architecture simplification and knowledge distillation, but for now I'm focusing primarily on quantization and pruning.
The process of quantization reduces the precision of the model's weights, leading to significant reductions in model size, memory needs and computational requirements (a good thing), but this however comes at the expense of a loss in the model's capabilities and accuracy (a bad thing!).
Another approach is to prune the model, that is, to selectively zero-out groups of parameters. Although significant reductions can be achieved this way, the risk of severely degrading the model's performance is markedly higher than when quantizing, as the process requires a deep understanding of the model's architecture in order to identify which tensors can be safely zero'ed. For all means and purposes, pruning is the equivalent of lobotomizing the LLM!
A successful outcome is when the overall size is reduced with no, or negligible, loss of capabilities (i.e. language understanding, math and logic problem-solving, conversation, coding, domain-specific knowledge, etc.) compared to the original version. On that regard, the method I'm using seems to yield some modest but encouraging results, and the versions available in this repo are on average 8% smaller than other, high-quality, sources with negligible loss of capability. As I continue to improve the process and develop tools to automate it, I aim to achieve further reductions in the 10-15% range, maybe more.
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 quantized 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:
- Convert the 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
- Quantize & prune versions of the base model
- 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 | Unsloth | Repo | Shrinkage |
---|---|---|---|---|
DeepSeek-R1-Distill-Qwen-7B-IQ3_M | 3.57 | N/A | 3.25 | 9.0% |
DeepSeek-R1-Distill-Qwen-7B-IQ3_S | N/A | N/A | 3.18 | N/A |
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL | 4.44 | N/A | 4.10 | 7.7% |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L | 4.09 | N/A | 3.76 | 8.1% |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M | 3.81 | 3.81 | 3.48 | 8.7% |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S | 3.49 | N/A | 3.22 | 7.7% |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M | 4.68 | 4.68 | 4.34 | 7.3% |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S | 4.46 | N/A | 4.12 | 7.6% |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M | 5.44 | 5.44 | 5.04 | 7.4% |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S | 5.32 | N/A | 4.91 | 7.7% |
DeepSeek-R1-Distill-Qwen-7B-Q6_K | 6.25 | 6.25 | 5.77 | 7.7% |
DeepSeek-R1-Distill-Qwen-7B-Q8_0 | 8.10 | 8.10 | 7.35 | 9.3% |
Perplexity and KL Divergence scores
Model | μPPL | 𝜌PPL | μKLD | RMS Δp |
---|---|---|---|---|
DeepSeek-R1-Distill-Qwen-7B-IQ3_M | 33.173614 ±0.334504 | 96.33% | 0.347117 ±0.000948 | 13.391 ±0.052 |
DeepSeek-R1-Distill-Qwen-7B-IQ3_S | 33.128433 ±0.335060 | 96.34% | 0.345716 ±0.000950 | 13.304 ±0.052 |
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL | 27.258871 ±0.268444 | 98.83% | 0.099355 ±0.000288 | 7.613 ±0.033 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L | 32.110566 ±0.327098 | 96.81% | 0.302751 ±0.000829 | 12.323 ±0.049 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M | 31.864547 ±0.323662 | 96.68% | 0.312659 ±0.000862 | 12.556 ±0.050 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S | 28.239199 ±0.276339 | 97.23% | 0.230055 ±0.000737 | 11.536 ±0.050 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M | 27.014257 ±0.265039 | 98.93% | 0.091236 ±0.000260 | 7.254 ±0.031 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S | 26.983473 ±0.264651 | 98.87% | 0.095828 ±0.000276 | 7.425 ±0.032 |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M | 26.940408 ±0.264293 | 99.15% | 0.072675 ±0.000201 | 6.485 ±0.027 |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S | 27.014468 ±0.265311 | 99.14% | 0.073713 ±0.000204 | 6.529 ±0.028 |
DeepSeek-R1-Distill-Qwen-7B-Q6_K | 26.741406 ±0.261816 | 99.21% | 0.067920 ±0.000187 | 6.257 ±0.026 |
DeepSeek-R1-Distill-Qwen-7B-Q8_0 | 26.727656 ±0.261689 | 99.24% | 0.065824 ±0.000180 | 6.173 ±0.025 |
DeepSeek-R1-Distill-Qwen-7B-F16 | 24.931431 ±0.241228 | 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. Q4_K_M quantizations from Bartowski and Unsloth included for comparison.
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 |
---|---|---|---|---|---|
DeepSeek-R1-Distill-Qwen-7B-IQ3_M | 48.9333 ±1.8265 | 56.00 | 30.4000 ±1.6807 | 29.4667 ±1.6658 | 56.5333 ±1.8113 |
DeepSeek-R1-Distill-Qwen-7B-IQ3_S | 48.2667 ±1.8259 | 56.53 | 31.2000 ±1.6929 | 28.4000 ±1.6477 | 57.3333 ±1.8072 |
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL | 52.1333 ±1.8253 | 57.20 | 31.7333 ±1.7007 | 26.5333 ±1.6132 | 59.2000 ±1.7958 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L | 51.6000 ±1.8260 | 57.20 | 31.2000 ±1.6929 | 28.6667 ±1.6523 | 58.1333 ±1.8026 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M | 52.1333 ±1.8253 | 56.40 | 30.9333 ±1.6889 | 29.0667 ±1.6591 | 59.0667 ±1.7967 |
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S | 51.6000 ±1.8260 | 56.40 | 31.4667 ±1.6968 | 27.0667 ±1.6235 | 59.2000 ±1.7958 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M | 51.6000 ±1.8260 | 57.87 | 33.4667 ±1.7242 | 26.5333 ±1.6132 | 61.4667 ±1.7783 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Bartowski) | 51.7333 ±1.8259 | 58.40 | 33.4667 ±1.7242 | 26.6667 ±1.6158 | 63.3333 ±1.7608 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Unsloth) | 51.3333 ±1.8263 | 58.40 | 32.4000 ±1.7100 | 27.6000 ±1.6334 | 62.0000 ±1.7736 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S | 51.0667 ±1.8265 | 57.33 | 33.2000 ±1.7207 | 26.2667 ±1.6080 | 61.3333 ±1.7794 |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M | 52.2667 ±1.8251 | 58.27 | 31.6000 ±1.6988 | 25.6000 ±1.5947 | 60.4000 ±1.7870 |
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S | 51.7333 ±1.8259 | 58.40 | 32.0000 ±1.7045 | 25.2000 ±1.5864 | 59.4667 ±1.7939 |
DeepSeek-R1-Distill-Qwen-7B-Q6_K | 52.4000 ±1.8249 | 58.27 | 32.8000 ±1.7155 | 26.1333 ±1.6054 | 59.6000 ±1.7930 |
DeepSeek-R1-Distill-Qwen-7B-Q8_0 | 52.5333 ±1.8246 | 58.40 | 32.0000 ±1.7045 | 26.0000 ±1.6027 | 58.8000 ±1.7984 |
DeepSeek-R1-Distill-Qwen-7B-F16 | 53.0667 ±1.8235 | 58.00 | 32.4000 ±1.7100 | 26.6667 ±1.6158 | 60.5333 ±1.7860 |
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 | 4.04 GiB | 7.62 B | Metal,BLAS | 6 | pp512 | 355.65 ± 0.13 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M | 4.04 GiB | 7.62 B | Metal,BLAS | 6 | tg128 | 28.68 ± 0.04 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M | 4.04 GiB | 7.62 B | Metal,BLAS | 6 | pp1024+tg1024 | 47.56 ± 0.07 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Bartowski) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | pp512 | 354.92 ± 0.56 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Bartowski) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | tg128 | 28.14 ± 0.05 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Bartowski) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | pp1024+tg1024 | 47.10 ± 0.03 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Unsloth) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | pp512 | 355.16 ± 0.22 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Unsloth) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | tg128 | 28.19 ± 0.03 |
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M (Unsloth) | 4.36 GiB | 7.62 B | Metal,BLAS | 6 | pp1024+tg1024 | 46.99 ± 0.36 |
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 orignal 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 gguf file format.