Evaluating Hallucinations in LLMs After Low-Bit Quantization: Methods and Practice
When large language models are compressed through low-bit quantization, they often produce more factual errors, broken reasoning chains, repetitive output, and malformed structured content. This article explains why quantization causes output quality degradation, covers common mitigation techniques such as group-wise quantization, orthogonal transforms, and mixed precision, and presents a practical evaluation framework with five core dimensions—factuality, hallucination rate, logical consistency, format compliance, and repetition—along with a decision workflow for deploying compressed models in production.
Evaluating Hallucinations in LLMs After Low-Bit Quantization: Methods and Practice
Why Compressed Models Start “Hallucinating”
After compression, large language models commonly show increased factual errors, broken reasoning chains, meaningless repetition in answers, and failures in structured output formats such as JSON and tables. These phenomena are collectively known as output quality degradation. To understand why, it helps to look at the physical scale of parameter storage.
Take a 27-billion-parameter model as an example. Theoretical weight sizes at different storage precisions are:
- 16-bit floating point: 27×10^9 × 2 bytes ≈ 54 GB
- 4-bit integer: 27×10^9 × 0.5 bytes ≈ 13.5 GB
- Ternary representation (~1.58 bits): 27×10^9 × 1.58 / 8 bytes ≈ 5.3 GB
Actual files are slightly larger because they also contain quantization scale factors, unquantized sensitive layers, and metadata. The cost of size reduction is a smaller set of representable values, which leads to information loss.
Importantly, the loss is not uniform. The same bit width affects some layers and tasks far more than others. Therefore, when evaluating a compression scheme, you cannot rely solely on model size and a single aggregate score—you need to check which capabilities actually degrade.
Sources of Quantization Error
Rounding Error in Uniform Quantization
Using symmetric uniform quantization as an example, a weight w is mapped to an integer grid:
q = round(w / Δ), ŵ = q × Δ
where Δ is the step size. The rounding error is bounded by Δ/2. The step size depends on the value range: a wider range means a larger step size and a larger average error at the same bit width.
Outliers Amplify Error
LLMs contain a small number of channels or dimensions whose magnitudes are far larger than the rest. If an entire tensor shares a single scale factor, the step size gets stretched by these outliers, and many ordinary weights are rounded to zero or a few values. The subtle information carried by those weights is lost entirely, which shows up as shifted attention distributions or abnormal intermediate activations.
Errors Accumulate Across Layers
Small per-layer errors propagate through residual connections and subsequent layers, and may be progressively amplified in deep networks. Small per-layer test error therefore does not guarantee overall model stability. Evaluation should focus on end-to-end outputs, not just layer-wise numerical error.
Common Mitigation Strategies
Group-wise Quantization
Weights are divided into fixed-size groups, each with its own scale factor. Smaller groups have narrower value ranges and higher precision, but higher storage overhead for the extra scales. In practice, engineers balance group size against storage cost.
Orthogonal Transforms
Apply an orthogonal matrix R (where R^T R = I) to the weight matrix W and transform the input accordingly at compute time:
y = Wx = (WR)(R^T x)
The theoretical output is unchanged, but the transformed weights spread their energy across more dimensions, flattening outliers and shrinking the quantization step size. A matching transform must be applied on the activation side, otherwise results will be wrong.
Ternary Representation
Ternary representation restricts each weight to {-1, 0, +1}, combined with group-wise scale factors to restore the value range. Each weight carries log2(3) ≈ 1.58 bits of information. Because of the extremely limited value set, ternary methods depend heavily on training and calibration strategies, and quantization constraints usually need to be considered during training or fine-tuning.
Mixed Precision and Sensitive Layer Protection
Embedding layers, output layers, and some attention projections are more precision-sensitive. A common practice is to keep these layers at higher precision while compressing the rest to extremely low bits. This adds little storage overhead while preserving most critical capabilities.
Calibration Data
Post-training quantization relies on calibration data to estimate value distributions. The calibration set should cover the input types of the target workload, including long texts, code, multilingual content, and structured data. If the calibration data diverges from the actual task distribution, quantized performance will drop noticeably in those scenarios.
Evaluation: How to Judge Whether Output Is Stable
Define Evaluation Dimensions
Cover at least the following five dimensions:
- Factuality: Use Q&A items with verifiable answers and compute accuracy.
- Hallucination rate: Ask the model to answer “cannot confirm” for non-existent information, and measure how often it fabricates answers.
- Logical consistency: Create semantically equivalent paraphrases of the same question and check whether conclusions stay consistent.
- Format compliance: Check whether JSON, tables, code, and similar outputs can be parsed or executed directly.
- Repetition and truncation: Measure n-gram repetition rates in answers, and the proportion of outputs truncated due to repetition loops or abnormal stopping.
Control Variables
When comparing compression schemes, keep the following conditions identical:
- The same set of prompts and evaluation items
- The same decoding parameters (temperature 0 recommended, or a fixed random seed)
- The same inference framework and hardware environment
- The same maximum context length
If variables are not unified, score differences may come from the environment rather than the model itself.
Use the Full-Precision Version as Baseline
Relative retention is computed as:
Retention rate = compressed model score / full-precision model score
This metric is easier to compare across tasks than absolute scores. But it only reflects the average level, so you should also break results down by task category—otherwise an aggregate score can hide severe degradation in a specific task type.
Example Code
Below is a simplified evaluation framework that computes accuracy and repetition rate. model_fn is the function that calls the model under test; implement it according to your own inference interface.
from dataclasses import dataclass@dataclassclass EvalItem:prompt: strgold: strcategory: strdef normalize(text: str) -> str:return " ".join(text.lower().split())def is_correct(pred: str, gold: str) -> bool:return normalize(gold) in normalize(pred)def repetition_rate(text: str, n: int = 4) -> float:tokens = text.split()grams = [tuple(tokens[i:i + n]) for i in range(len(tokens) - n + 1)]if not grams:return 0.0return 1 - len(set(grams)) / len(grams)def evaluate(model_fn, items: list[EvalItem]) -> dict:stats = {}for item in items:pred = model_fn(item.prompt)bucket = stats.setdefault(item.category, {"total": 0, "correct": 0, "rep": 0.0})bucket["total"] += 1bucket["correct"] += int(is_correct(pred, item.gold))bucket["rep"] += repetition_rate(pred)report = {}for cat, b in stats.items():report[cat] = {"accuracy": b["correct"] / b["total"],"avg_repetition": b["rep"] / b["total"],}return reportdef retention(compressed: float, baseline: float) -> float:return compressed / baseline if baseline else 0.0
When running evaluations, sample each item multiple times and report both the mean and the variance. A single run cannot distinguish model capability from random fluctuation.
Sample Size and Statistical Significance
With a small number of items, accuracy fluctuates heavily. Use bootstrapping to estimate confidence intervals; only when the intervals of two schemes clearly do not overlap can you conclude that their difference is practically meaningful.
Pre-Deployment Decision Workflow
- Identify the core capabilities your business needs, such as Q&A, code generation, or structured extraction.
- Build an internal evaluation set covering these capabilities, including long texts and edge cases.
- Use the full-precision model as the baseline and measure per-task retention rates for each compression scheme.
- Check format compliance and repetition rates to confirm outputs can be consumed directly by downstream systems.
- Measure latency and throughput on the target hardware. Whether smaller size translates into speed gains depends on whether the inference kernels support the given bit width.
- Keep small-scale manual spot checks for critical workflows, and log anomalous samples for the next round of calibration.
Common Pitfalls
Relying only on perplexity. Perplexity reflects average language modeling loss and does not fully correspond to task-specific accuracy. A slight perplexity increase may have almost no impact on some tasks but a clear impact on others.
Testing only short texts. Quantization error accumulates over long contexts. Testing only on prompts of a few hundred words tends to overestimate stability.
Trusting a single score. Aggregate scores can smooth over category-level differences. Always review factuality, formatting, long-text, and other per-dimension results.
Ignoring calibration distribution. When calibration data does not match production data, the compressed model will behave abnormally in real scenarios.
Overlooking inference overhead. Smaller size does not mean faster inference. If the inference environment lacks the corresponding compute support, extra dequantization overhead may actually appear.
Practical Recommendations
- Include output stability as a launch gate for model releases, treated with the same weight as size and latency.
- Update the evaluation set regularly as the business evolves, to avoid overfitting to a fixed set of items.
- Keep a rollback path for every compression scheme so you can quickly switch back to the original precision if problems arise.
- Record the environment, parameters, and random seeds for every evaluation to ensure reproducibility.
Low-bit quantization is an engineering decision that requires trade-offs. With a rigorous evaluation methodology, controlled variables, and complete per-dimension metrics, you can reliably determine whether a compression scheme fits a given business scenario.
