Skip to content

nathan-albin/quant-reasoning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Effects of quantization on mathematical reasoning

Does model quantization degrade mathematical reasoning more than a cheap metric like perplexity would reveal? This repo is a small, focused empirical study of that question. Testing Qwen2.5-7B-Instruct across fp16, int8, and int4, I found that perplexity barely moves from fp16 to int8 (+0.2%) while both reasoning benchmarks take a small but real hit, and the gap widens sharply at int4 (MATH-500 drops 7.9%). The takeaway: a quantization that leaves perplexity essentially unchanged can still measurably erode complex reasoning, which makes perplexity an unreliable proxy for reasoning quality. The test case here is deliberately narrow, but the effect is consistent across both math benchmarks.

Results

All three benchmarks below score 200 examples each, comparing Qwen/Qwen2.5-7B-Instruct (fp16) against its GPTQ-Int8 and AWQ (int4) quantizations.

Metric FP16 INT8 (GPTQ) Δ vs FP16 INT4 (AWQ) Δ vs FP16
WikiText-2 perplexity ↓ 10.82 10.83 +0.2% 11.85 +9.6%
GSM8K accuracy ↑ 92.5% 91.0% −1.6% 89.0% −3.8%
MATH-500 accuracy ↑ 70.0% 69.0% −1.4% 64.5% −7.9%

Perplexity and accuracy across precisions

Takeaway: Perplexity stays essentially even from fp16 to int8, but both reasoning tasks take a small but real hit that grows at int4. Errors accumulate over longer reasoning chains, so the harder, longer-form MATH-500 problems degrade more than GSM8K, whose fp16 baseline (92.5%) is already very strong.

Setup

Copy the environment config example and edit it:

cp config.example.env .env

The code uses the uv package manager. It will install the necessary packages the first time you run something, or you can set up the environment ahead of time with:

uv sync

How to generate these results

Perplexity tests

eval/perplexity.py implements a simple perplexity checker using the Salesforce/wikitext dataset.

# environment setup
set -a; source .env; set +a

# run the three test sets
uv run eval/perplexity.py --model $MODEL_FP16 --label fp16
uv run eval/perplexity.py --model $MODEL_INT8 --label int8 --quantization gptq
uv run eval/perplexity.py --model $MODEL_INT4 --label int4 --quantization awq

Easy mathematical reasoning tests (GSM8K)

eval/gsm8k.py tests models on their ability to answer openai/GSM8K questions, with prompts routed through the tokenizer's chat template for instruction-tuned models.

# environment setup
set -a; source .env; set +a

# run the three test sets
uv run eval/gsm8k.py --model $MODEL_FP16 --label fp16
uv run eval/gsm8k.py --model $MODEL_INT8 --label int8 --quantization gptq
uv run eval/gsm8k.py --model $MODEL_INT4 --label int4 --quantization awq

Harder mathematical reasoning tests (MATH-500)

eval/math500.py tests models on HuggingFaceH4/MATH-500 questions.

# environment setup
set -a; source .env; set +a

# run the three test sets
uv run eval/math500.py --model $MODEL_FP16 --label fp16
uv run eval/math500.py --model $MODEL_INT8 --label int8 --quantization gptq
uv run eval/math500.py --model $MODEL_INT4 --label int4 --quantization awq

Figure

Once the nine JSON files exist in results/, eval/plot_results.py generates the visualization:

uv run eval/plot_results.py

About

Does int8/int4 quantization hurt LLM math reasoning more than perplexity? A controlled Qwen2.5-7B study (vLLM + GSM8K + MATH-500) suggesting perplexity may be an unreliable proxy for more complex reasoning tasks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages