LLM RAM Reduction: Up to 75% Savings with Memory Mapping

Memory mapping combined with 4-bit quantization allows Large Language Models (LLMs) to run with significantly less RAM, reducing the memory footprint of a 7B parameter model from a typical 14GB down to 4GB, a saving of 70-75%. This also enables 100x faster model loading by avoiding unnecessary memory page copying.

The top 3

  1. Memory Mapping's Core: Instant Loads, Half RAM: Memory mapping (mmap) allows LLMs, especially in `llama.cpp`, to load models directly from disk by streaming only necessary parts, avoiding full model copies to RAM. This technique initially enabled `llama.cpp` to load LLaMA models 100x faster and use half the memory compared to traditional I/O.
  2. Quantization Synergy: Up to 87.5% RAM Reduction: Alongside memory mapping, model quantization significantly amplifies RAM savings by reducing weight precision. For example, a 7-billion-parameter LLM can shrink from 28 GB (full precision) to just 3.5 GB with INT4 quantization, achieving up to an 87.5% memory reduction, enabling deployment on devices with limited memory.
  3. KV Cache Quantization: Up to 50% Generation RAM Savings: Beyond model weights, `llama.cpp` further optimizes memory by applying 8-bit or lower precision quantization to the Key-Value (KV) cache during text generation. This specific technique can cut memory usage by up to 50% on average during inference, making long context windows more feasible on consumer hardware.

Sources

Open the full topic