llama.cpp's K-Quants: Smarter 4-bit for Better Quality

llama.cpp's K-quantization formats, such as Q4_K_M, achieve a superior speed-accuracy balance by employing mixed precision. These formats store most weights at 4-bit but allocate 6-bit precision to the most sensitive layers, which can recover 5-8% more quality compared to older, uniform 4-bit formats like Q4_0, at a similar memory footprint.

The top 3

  1. K-Quants' Dual-Level Quantization Breakthrough: llama.cpp's K-Quants achieve superior quality by employing a two-level block quantization system, grouping small blocks into 256-weight super-blocks with double-quantized scales for finer precision control.
  2. Mixed-Precision: K-Quants' Quality Secret: K-Quants like Q4_K_M enhance quality by selectively applying higher precision (e.g., 6-bit) to critical layers, such as parts of attention.wv and feed_forward.w2 tensors, while keeping other weights at 4-bit, optimizing the balance between fidelity and file size.
  3. K-Quant Formats: Quality-Size Trade-offs: Comparing 7B models, Q6_K offers excellent quality with a perplexity increase of only +0.0216 and ~5.0 GB size, while Q4_K_M provides a good balance at +0.1084 perplexity increase and ~4.3 GB, significantly better than older Q4_0's +0.2499.

Sources

Open the full topic