Zuhal Karadavut
Theme

LLM inference, evaluation and retrieval

sql-under-compression

When a small open code model is quantized for llama.cpp, how many correct SQL answers does it lose, and what does it save in file size, memory and speed?

Answer

4-bit costs answers, 8-bit does not. On all 1,034 questions of the Spider development set, Qwen2.5-Coder-1.5B-Instruct at q4_k_m answers 614 correctly against 647 at f16: 3.2 points lower, with 59 questions lost and 26 gained (exact sign test, p < 0.001). The q4_k_m file is a third of the f16 size and generates 2.6 times the tokens per second.

Questions lost and gained against f16 (questions)
← lostgained →q8_065results-full-dev/q8_0.jsonq5_k_m1420results-full-dev/q5_k_m.jsonq4_k_m5926results-full-dev/q4_k_m.json

How it was measured

  • Every precision gets the same questions, decoded greedily (temperature 0, at most 256 new tokens). The prompt holds the CREATE TABLE statements of the database and the question, nothing else.
  • An answer is right if its first SQL statement returns the same rows as the reference query on the SQLite database. This is execution accuracy.
  • Each precision is paired with f16 question by question. Only the questions where the two differ enter the exact two-sided sign test.
  • Size, peak memory (VmHWM) and tokens per second come from a run with all four precisions one after the other on one GitHub machine with 2 virtual CPUs, so different CPUs do not mix with the effect of compression.
  • q4_k_m needs more RAM than q5_k_m (2.03 against 1.56 GB), because llama.cpp keeps a repacked copy of its weights (596.53 MiB).

Proof

Every file is pinned to the commit the numbers come from, so the links cannot drift.

Reproduce it

pip install -r requirements.txt
python fetch_spider.py data
python compress.py q4_k_m model
python evaluate.py model data/spider 1034 output/q4_k_m.json
python make_table.py output

Or in the Actions tab: run the benchmark workflow with all questions and the four precisions. The published accuracy run took 1 hour 41 minutes on four GitHub machines at once.

The repository on GitHub

Limits

  • One small model on a public dataset it has very probably seen in training. The point is the comparison between precisions, not the absolute accuracy.
  • My first run with 200 questions could not see the 4-bit loss (p = 0.42). Only the full set could.
  • Speed is one run on one shared machine. Other machines give other speeds.

Built with

  • Python
  • llama.cpp
  • llama-cpp-python
  • pruna
  • SQLite
  • GitHub Actions