LLM Quantization in Practice: Compressing Model Size Without Losing Intelligence

    This article explains how large language model quantization reduces storage and compute precision while preserving output quality. It covers the mathematical foundations of quantization, including scale factors, zero points, symmetric and asymmetric mapping, bit-width trade-offs, and quantization granularity. It compares post-training quantization (PTQ) and quantization-aware training (QAT), then details key techniques for limiting accuracy loss, such as layer-wise reconstruction, activation-aware weight protection, smooth migration, grouping, and stochastic rounding. It also addresses KV cache quantization for long contexts and outlines a practical workflow from defining constraints and building evaluation sets to calibration, PTQ sweeps, bottleneck-layer tuning, and production monitoring. The goal is to lower deployment cost to an acceptable level without sacrificing meaningful model capability.

    1. Why Large Models Must Be Compressed

    Large language models are resource-hungry by nature: as parameter counts grow, so do the floating-point operations and GPU memory required for weights, activations, and attention scores. A 70-billion-parameter model stored in 32-bit floating point needs roughly 280 GB just for its weights, before accounting for inference caches, temporary tensors, and framework overhead. The result is that growth in model capability is tightly constrained by the cost of hardware.

    The premise of quantization is simple: reduce the precision used to store and compute numerical values. Everything inside a model is a number, and mathematically those numbers are continuous and high-precision, while computers prefer fixed, discrete representations. Quantization builds a controllable bridge between the two, using fewer bits to represent the value distribution and turning “requires a full rack to run” into “runs on a workstation or even an edge device.”

    Quantization is not merely cutting bit-width. It is a complete methodology involving numerical mapping, error control, calibration strategies, and engineering implementation. Done well, it delivers substantial gains in model size, memory footprint, and latency with almost no perceptible loss in output quality. Done poorly, it produces the classic “runs but gets dumber” symptoms: broken long-form reasoning, degraded instruction following, and clear drops in code and math ability.

    2. The Mathematical Skeleton: Scale, Zero Point, and Mapping

    At its core, quantization linearly maps a floating-point range to an integer range. The most common form is:

    1. q = round(x / scale + zero_point)
    2. x_hat = scale * (q - zero_point)

    Here, scale is the scaling factor that determines how much real value each integer step represents, and zero_point aligns floating-point 0 with integer 0, avoiding systematic bias from asymmetric positive and negative ranges.

    Symmetric quantization fixes the zero point at 0. It is simple to map, has low multiplication overhead, and works well for weights, whose distributions are approximately zero-centered. Asymmetric quantization allows the zero point to be any integer, fitting naturally shifted distributions such as activations that stay positive after a nonlinearity. The trade-off is more complex dequantization and operator implementations.

    Bit-width selection follows a curve of diminishing returns: 16-bit is nearly lossless but offers limited compression; 8-bit is the sweet spot for most tasks, cutting size and memory to about a quarter; 4-bit pushes compression to the extreme but is highly sensitive to outliers and requires smarter algorithms. Below 4 bits, techniques such as stochastic rounding and group-shared scaling become barely usable, and engineering complexity rises sharply.

    Another key dimension is quantization granularity. Per-tensor is the cheapest in compute but has the largest error; per-channel captures scale differences across output channels; per-group (for example, sharing one set of parameters every 64 or 128 weights) balances compression and accuracy and is the mainstream approach for current 4-bit schemes.

    3. Post-Training Quantization vs. Quantization-Aware Training

    Post-training quantization (PTQ) happens after training is complete. It needs only a small amount of unlabeled or weakly labeled calibration data, is low-cost and fast, and is the default starting point for most scenarios. Its success depends on whether the calibration set represents the real input distribution and whether outliers are handled properly.

    Quantization-aware training (QAT) inserts pseudo-quantization nodes during training or fine-tuning so the model learns to adapt to low-precision representation. It can usually reduce accuracy loss at 4 bits or even lower to a small margin. The cost is full training resources, longer cycles, and a more complex pipeline, making it suitable for teams with strict accuracy requirements and ample compute.

    The practical rule is straightforward: start with PTQ and establish an evaluation baseline; only when key metrics such as instruction following, long-context consistency, and structured-output accuracy regress unacceptably should you invest in QAT or a hybrid route of light fine-tuning plus quantization.

    4. Key Techniques for Suppressing Accuracy Loss

    Layer-wise optimization and error compensation. Layer-wise reconstruction makes each layer’s quantized output approximate its floating-point output as closely as possible, using the remaining error to correct subsequent computation and preventing error from accumulating and amplifying in deep networks.

    Activation-aware weight protection. A small number of “salient weights” have outsized impact on outputs. Ranking channels by activation magnitude, keeping higher precision for salient channels and compressing the rest to low bit-width, can significantly reduce quality regression at 4 bits.

    Smooth migration. Outliers in activations are hard to quantize, while weight distributions are relatively flat. Migrating part of the activation’s “difficulty” to weights proportionally along the channel dimension makes both easier to quantize; this is the core idea behind low-bit activation quantization.

    Grouping and stochastic rounding. Smaller groups make scaling factors fit local value ranges more closely; stochastic rounding turns the bias of deterministic rounding into noise, which is actually more stable at very low bit-widths.

    5. KV Cache Quantization: The Hidden Cost of Long Contexts

    In autoregressive inference, the historical key-value cache grows linearly with context length and often consumes more memory than weights in long-context scenarios. Quantizing the cache to 8-bit or 4-bit can significantly extend the supported context length and improve throughput. The key points are that the cache grows dynamically, so quantization parameters need online updates, and outlier channels in attention need targeted protection to avoid degrading retrieval and copy abilities.

    6. A Practical Quantization Workflow

    1. Define constraints: target hardware compute/memory, latency budget, context length, and accuracy floor.
    2. Build an evaluation set covering general understanding, instruction following, long-form consistency, structured output, and domain tasks to form a comparable baseline.
    3. Construct calibration data sampled from the real business distribution, representative in both length and topic, avoiding a single template.
    4. Run a PTQ sweep first: compare 8-bit, 4-bit, different groupings, and symmetric/asymmetric combinations, recording size, memory, throughput, and metrics.
    5. Locate bottleneck layers: raise precision or switch to a mixed-precision scheme for layers with clear regression.
    6. If necessary, introduce QAT or light fine-tuning, then run a full regression again.
    7. After launch, continuously monitor quality drift with logging services and alerting, combined with canary releases and fast rollback.

    7. Value Scenarios and Common Pitfalls

    Edge and on-premises deployment, low-cost cloud inference, and long-context processing are the three directions where quantization pays off most directly: fitting models into smaller devices, running larger models on a single card, and supporting longer conversations with the same memory.

    There are three common pitfalls: declaring success based on a single perplexity metric while ignoring instruction following and structured output; a calibration set disconnected from real traffic, causing online quality to drop sharply; and treating quantization as a pure inference optimization while overlooking whether operators and hardware backends actually accelerate low-precision computation. In general capability systems such as Baidu AI Cloud, model compression typically works with containerized deployment, elastic scaling, and logging and alerting to form a closed loop from evaluation to launch.

    The goal of quantization has never been “smaller” but “pushing deployment cost into a range the business can bear under an acceptable loss of intelligence.” Get the mapping principles, calibration strategy, and evaluation system right, and compression will not come at the cost of “losing its mind.”