This article explores critical techniques for shrinking large language models (LLMs) to make them more manageable for deployment, especially on consumer-grade hardware, while minimizing performance degradation. It delves into the architectural considerations of LLM parameter storage and introduces quantization, pruning, and knowledge distillation as key strategies to reduce model size and inference cost.
Read original on ByteByteGoDeploying large language models (LLMs) presents significant architectural challenges, primarily due to their immense size. A 70 billion parameter model can occupy 140 GB of memory, far exceeding the capacity of typical consumer-grade GPUs (24-48 GB). This memory constraint directly impacts inference costs, latency, and accessibility. The core issue lies in the storage of model weights, which constitute the bulk of an LLM's size and intelligence. Effective system design for LLMs requires strategies to reduce this footprint without sacrificing model quality.
LLMs' intelligence is encoded in billions of parameters or weights, typically stored as 16-bit floating-point numbers. These weights form complex matrices across many layers within an architecture like the Transformer. While the architecture code and context window are relatively small, the weights determine how the model processes input and generates output. To shrink a model, therefore, requires intelligently reducing the number or precision of these weights, as individual weights don't hold meaning in isolation but rather through their relationships.
Key Insight
Not all weights contribute equally to an LLM's output. Many are close to zero and have minimal impact, offering opportunities for reduction. Furthermore, a model's quality is primarily judged by its behavior, not its internal structure, allowing for architectural modifications if the output remains consistent.
Three primary techniques address the challenge of LLM size, often applied in combination to achieve significant reductions:
Quantization works by reducing the numerical precision of model weights. While training often uses 32-bit floating-point (FP32) for high precision, inference can often tolerate lower precision like 16-bit (FP16 or BF16) or even 8-bit/4-bit integers. The process typically involves: 1. Mapping Ranges: Dividing a block of weights into a fixed number of steps based on their minimum and maximum values. 2. Rounding Values: Rounding each original weight to the closest available step, converting floats to integers. 3. Scale Factor: Storing a single scale factor per block, which allows approximate reconstruction of original float values during inference. This method sacrifices some precision but drastically reduces storage, making LLM inference more efficient. The impact on model intelligence is often minimal, as the overall relationships between weights are largely preserved.