help-calc

08 Numbers and Units

Install llama.cpp: Step-by-Step Guide

Card 08-0226 · Updated · Standard formula, shown below

The calculator on this page is switched off while it is checked. The formula is below, and the worked example shows how to do the sum by hand.

This guide walks you through installing llama.cpp, a popular open-source library for running large language models (LLMs) locally on your own hardware. You’ll learn how to set it up on Windows, macOS, and Linux, and how to build it with optional GPU acceleration. By the end, you’ll be able to run a model and start generating text offline.

Formula

The calculator above estimates the RAM you need to run a quantized model, and whether it fits entirely in your GPU’s VRAM. The formula is:

Minimum RAM = VRAM + (Model Size × Quantization Bits / 8) × 1.1

Where:

  • Model Size – the original size of the model in GB (e.g., 7B parameter model is about 14 GB in FP16).
  • Quantization Bits – usually 4 or 8; lower bits mean smaller memory footprint but lower quality.
  • VRAM – your GPU’s video memory in GB.

The 1.1 factor accounts for overhead and context memory. The second output checks if the quantized model fits in VRAM alone.

Worked Example

Using the default values: Model Size = 7 GB, VRAM = 8 GB, Quantization = 4 bits.

First, compute the quantized model size: 7 × 4 / 8 = 3.5 GB.

Then, minimum RAM = 8 + (3.5 × 1.1) = 8 + 3.85 = 11.85 GB.

The calculator rounds to 11.9 GB. For the GPU fit check: 3.5 ≤ 8, so it fits. This matches the output.

When to Use This Calculator

Use this before downloading a model to ensure your system can run it. It helps you choose the right quantization level. If the model doesn’t fit in VRAM, llama.cpp will offload layers to CPU, which is slower but still works.

Common Mistakes

  • Ignoring that model sizes are often quoted in FP16, not the quantized size. A 7B model is ~14 GB, not 7 GB.
  • Forgetting that context window also consumes memory. The calculator adds a 10% buffer, but long contexts can exceed that.
  • Assuming GPU VRAM is the only memory needed – llama.cpp still uses system RAM for the model if it doesn’t fit.
  • Using 8-bit quantization when your GPU has little VRAM – it doubles the memory compared to 4-bit.

Tips

  • Start with a 4-bit quantized model – it’s a good balance of quality and performance.
  • Check your GPU’s VRAM with a tool like nvidia-smi on Windows/Linux or system_profiler on macOS.
  • If you have multiple GPUs, add their VRAM together for the total.
  • Use the official llama.cpp release builds first; they are pre-compiled and easier than building from source.

Limitations

The formula is a rough estimate. Actual memory usage varies by model architecture, context length, and batch size. It does not account for the memory needed by the operating system or other applications. For very large models, you may need to rely on CPU offloading, which the calculator does not fully model.

Frequently Asked Questions

What is llama.cpp?

It’s a C++ implementation of Meta’s LLaMA models, designed to run efficiently on CPU and GPU, with support for many open-source models.

Do I need a GPU?

No, llama.cpp runs on CPU alone, but it’s slower. A GPU with enough VRAM speeds up generation significantly.

What does quantization mean?

It reduces the precision of the model weights (e.g., from 16-bit to 4-bit) to save memory and speed up inference, at a small cost to quality.

How do I know if my model fits in VRAM?

Use the calculator: if the quantized model size is less than your VRAM, it fits. Otherwise, it will be partially offloaded to CPU.

Can I run models larger than my RAM?

No, the model must fit in RAM (or be swapped, which is impractically slow). The calculator gives you the minimum RAM needed.

Why does my model use more memory than expected?

Context window, batch size, and model overhead add to memory. The 10% buffer helps, but for very long contexts, you may need to reduce the context size.

Related

Formula used
in mem | Model size (GB) | GB | 7 | 0 | 100
in vram | GPU VRAM (GB) | GB | 8 | 0 | 100
in q | Quantization (bits) | - | 4 | 2 | 8
out ram | Minimum RAM needed | GB | vram + (mem * (q / 8)) * 1.1 | 1
out gpu | Fits in GPU? | - | (mem * (q / 8))

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More on this shelf

The whole Numbers and Units shelf →