New Tool Radar

AI Concepts

How to Check Perplexity After Quantizing a Model to Measure How Much Quality Was Lost

Measure perplexity on held-out text before and after quantizing, compare the two numbers, and reject a quantized model whose perplexity jumped.

Schematic with three steps: Measure the baseline perplexity first; Measure the quantized model the same way; Decide with a limit, not a feeling.

Quantization trades accuracy for memory, and you need a number for the accuracy side of that trade. Perplexity on held-out text is the standard check: a lower perplexity means the model predicts the text better. The GPTQ paper reports that its method can quantize models to 3 or 4 bits per weight with negligible accuracy degradation relative to the uncompressed baseline, and still reasonable accuracy at 2 bits. Your model may behave differently, so measure it yourself instead of trusting the paper numbers.

What you need

  • Held-out text the model was not trained or calibrated on
  • The full-precision model, for the baseline score
  • The quantized model, loaded the same way

Step 1: Measure the baseline perplexity first

Run the full-precision model over the held-out text and record its perplexity. Use the same text, the same tokenization and the same scoring for every later comparison, or the numbers cannot be compared.

Step 2: Measure the quantized model the same way

Load the quantized model and score the identical held-out text. A small rise in perplexity is the expected cost of fewer bits; a large jump means the quantization damaged the model.

Step 3: Decide with a limit, not a feeling

Set a limit before you measure, for example that perplexity may rise by no more than a small amount you choose. If the quantized model passes, keep it; if it fails, try a larger group size, a different method, or keep the sensitive layers at higher precision.

Worked example: synthetic perplexity check after quantizing

The table below is a synthetic example. It shows the expected result of measuring perplexity; no model was scored.

Model Bits Perplexity
Full precision 16 10.2
Quantized, group 128 4 10.6
Quantized, group 32 4 10.4
Quantized, aggressive 2 14.8

Expected result (UNTESTED). 4-bit quantization raises perplexity only slightly, while 2-bit quantization jumps it sharply. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Perplexity measures prediction on text, not task quality: a model can have good perplexity and still fail your task.
  • The GPTQ paper numbers are for the models and datasets in that paper; your model may degrade more or less.
  • Perplexity must be measured on held-out text: scoring the calibration data flatters the quantized model.
  • A 175-billion-parameter model quantized with GPTQ took about four GPU hours in the paper, so budget time for large models.

Sources

See all