eaddario's picture
Update README.md
86be943 verified
|
raw
history blame
19.1 kB
metadata
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 b4998 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 that I'm using to produce these experimental versions is explained in Squeezing Tensor Bits: the quest for smaller LLMs, but at a high level it involves using a custom version of the llama-quantize tool to selectively quantize different tensors at different levels.

There’re two pull requests (#12511 & #12512) to merge these changes back into the core llama.cpp project. This may or may not ever happen but until then, the modified version will be available on my GitHub.

In addition to llama-quantize, there’s a version of llama-perplexity that allows you to continue generating test scores even if there’s a context window overflow (original behaviour is to stop).

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. Select an appropiate quant level for each tensor using a modified version of llama-quantize
  5. Calculate Perplexity, KL Divergence, ARC (Easy+Challenge), HellaSwag, MMLU, Truthful QA and WinoGrande scores for each quantized model
  6. Keep versions with the best scores
  7. 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.29 7.8%
DeepSeek-R1-Distill-Qwen-7B-IQ3_S N/A N/A 3.09 N/A
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 4.44 N/A 4.09 7.9%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 4.09 N/A 3.23 21.0%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 3.81 3.81 3.18 16.5%
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 3.49 N/A 3.12 10.6%
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 4.68 4.68 4.22 9.8%
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S 4.46 N/A 4.10 8.1%
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 5.44 5.44 5.06 7.0%
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 5.32 N/A 4.92 7.5%
DeepSeek-R1-Distill-Qwen-7B-Q6_K 6.25 6.25 5.81 7.0%
DeepSeek-R1-Distill-Qwen-7B-Q8_0 8.10 8.10 7.36 9.1%

Perplexity and KL Divergence scores

Model μPPL 𝜌PPL μKLD RMS Δp
DeepSeek-R1-Distill-Qwen-7B-IQ3_M 29.649250 ±0.294595 96.03% 0.327503 ±0.001046 14.505 ±0.057
DeepSeek-R1-Distill-Qwen-7B-IQ3_S 29.629428 ±0.297710 95.87% 0.342098 ±0.001134 14.049 ±0.058
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 27.257341 ±0.278686 98.29% 0.141175 ±0.000478 9.225 ±0.042
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 24.231749 ±0.227987 97.26% 0.226427 ±0.000710 11.830 ±0.050
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 25.241862 ±0.238190 96.17% 0.310675 ±0.000978 13.592 ±0.056
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 25.258309 ±0.236501 95.63% 0.352969 ±0.001095 14.453 ±0.058
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 23.557663 ±0.224589 99.09% 0.070963 ±0.000232 6.641 ±0.032
DeepSeek-R1-Distill-Qwen-7B-Q4_K_S 23.530143 ±0.224303 99.09% 0.071101 ±0.000236 6.637 ±0.032
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 23.038797 ±0.218976 99.47% 0.041530 ±0.000125 5.010 ±0.023
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 23.109739 ±0.219906 99.46% 0.041738 ±0.000126 5.034 ±0.023
DeepSeek-R1-Distill-Qwen-7B-Q6_K 23.115197 ±0.220246 99.55% 0.034778 ±0.000104 4.579 ±0.021
DeepSeek-R1-Distill-Qwen-7B-Q8_0 23.093601 ±0.219879 99.58% 0.032917 ±0.000099 4.449 ±0.020
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 51.8072 ±1.8294 57.33 32.6667 ±1.7137 31.4985 ±2.5727 55.6000 ±1.8155 45.78
DeepSeek-R1-Distill-Qwen-7B-IQ3_S 46.7202 ±1.8267 57.47 32.2667 ±1.7082 28.7500 ±2.5341 57.3333 ±1.8072 44.51
DeepSeek-R1-Distill-Qwen-7B-IQ4_NL 51.8717 ±1.8281 57.86 32.4000 ±1.7100 28.2609 ±2.5131 60.8000 ±1.7838 46.24
DeepSeek-R1-Distill-Qwen-7B-Q3_K_L 52.2727 ±1.8275 57.87 31.4667 ±1.6968 31.4985 ±2.5727 59.3333 ±1.7948 46.49
DeepSeek-R1-Distill-Qwen-7B-Q3_K_M 48.8621 ±1.8302 55.87 32.1333 ±1.7063 33.3333 ±2.6603 61.2000 ±1.7805 46.28
DeepSeek-R1-Distill-Qwen-7B-Q3_K_S 48.3266 ±1.8296 56.80 31.7333 ±1.7007 34.3750 ±2.6593 58.9333 ±1.7976 46.03
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 49.0642 ±1.8291 56.00 33.7333 ±1.7276 28.0000 ±2.4944 60.1333 ±1.7890 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 50.8701 ±1.8304 61.07 32.2667 ±1.7082 28.9231 ±2.5189 61.0667 ±1.7816 46.84
DeepSeek-R1-Distill-Qwen-7B-Q5_K_M 52.0750 ±1.8291 60.93 31.3333 ±1.6949 26.7081 ±2.4694 60.9333 ±1.7827 46.40
DeepSeek-R1-Distill-Qwen-7B-Q5_K_S 52.6104 ±1.8281 59.47 31.7333 ±1.7007 26.6871 ±2.4536 59.6000 ±1.7930 46.02
DeepSeek-R1-Distill-Qwen-7B-Q6_K 52.2088 ±1.8288 60.53 36.2667 ±1.7567 28.0864 ±2.5006 62.1333 ±1.7724 47.85
DeepSeek-R1-Distill-Qwen-7B-Q8_0 51.5395 ±1.8298 58.27 31.7333 ±1.7007 27.9635 ±2.4782 56.9333 ±1.8093 45.29
DeepSeek-R1-Distill-Qwen-7B-F16 53.2798 ±1.8267 57.73 35.2000 ±1.7451 29.1793 ±2.5100 58.6667 ±1.7993 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.92 GiB 7.62 B Metal,BLAS 6 pp512 360.61 ± 0.59
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 3.92 GiB 7.62 B Metal,BLAS 6 tg128 29.26 ± 0.14
DeepSeek-R1-Distill-Qwen-7B-Q4_K_M 3.92 GiB 7.62 B Metal,BLAS 6 pp1024+tg1024 48.72 ± 0.14
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.