Skip to content
,
llama.cpp from scratch · Part 1

What is llama.cpp? A free program that runs AI models on your computer

10 min read
Featured image: What Is llama.cpp? A program, not an AI company, with the official llama.cpp icon. Editorial illustration for Analytics Made Simple.

llama.cpp is not a company. It is a small, fast program, written in C and C++, that loads a saved AI model (its “weights,” the numbers that make it work) and runs it on your own computer chip. Lots of other apps sit on top of it. llama.cpp is the part that actually does the math.

Say you’re pitching your IT team on running AI in-house instead of paying a cloud vendor by the month, and llama.cpp shows up on the architecture slide. Someone always asks the obvious question: which company do we sign a contract with? For llama.cpp, the honest answer throws people off. There is no sales team, no contract, and no monthly bill. You compile the program once, on your own machine, and it’s yours to keep.

Why finance always asks who owns it

Picture a familiar scene: a small financial-analytics firm is proposing a move away from cloud AI vendors, so client data can stay on servers the firm owns and controls. During a quarterly review of the company’s tech plans, the systems team lays out a plan to run everything on thirty machines with two graphics cards each. Every diagram labels “llama.cpp” as the engine at the center of it all.

The finance lead jumps in with the questions finance always asks first:

  • Who owns this vendor, and what’s their monthly pricing?
  • If we run this on sixty machines, is someone going to audit our server (a computer that runs programs for other people or programs to use) room for unlicensed seats?
  • What happens if this startup runs out of funding in eighteen months and shuts off the login servers?
  • Could a bigger company buy them out and triple our support costs next year?

The technical lead’s answer resets the whole conversation. llama.cpp isn’t a company. There’s no sales team, no investors, no license agreement, no phone-home tracking, and no cloud server it depends on. One engineer wrote it as open-source code, and it runs directly on our own hardware with nothing else required. Once we compile it, it belongs to us for good.

If you’ve spent years signing off on software contracts, that can sound too good to be true. But it’s one of the more important shifts in how software gets built, and it’s worth understanding properly rather than taking on faith.

A company selling AI access compared with llama.cpp, an MIT-licensed program you run yourself
llama.cpp is a program, not a vendor: no sales team, no license fee, and nothing to shut off.

How one weekend project became critical software

To see why llama.cpp works the way it does, it helps to know exactly when it was built. In late February 2023, Meta released the weights for its first LLaMA models. They came in four sizes: 7, 13, 30, and 65 billion parameters, roughly the number of tunable settings inside the model. Running the larger ones needed a rack of expensive data-center graphics cards, hundreds of gigabytes of memory, and a stack of Python software with dozens of interlocking pieces.

For a developer working alone on a laptop, that was simply out of reach. The usual Python tools used far more memory than a laptop had, and most laptops don’t have the kind of graphics chip those tools expect.

Then Georgi Gerganov got involved. He’s a Bulgarian software engineer who had already built whisper.cpp, a fast, no-extras rewrite of OpenAI’s speech-recognition model that ran well on Apple’s chips. When LLaMA’s weights leaked online in early March 2023, he rewrote the model’s core math in plain C and C++, stripped down to the essentials.

On March 10, 2023, he published the first version of the code, under the name llama.cpp, in a public repository (a shared project folder that tracks every change anyone makes). It did something many people did not expect. It ran the 7-billion-parameter LLaMA model on an ordinary Apple M1 laptop’s processor, producing readable text at a normal reading pace, with no Python and no outside libraries at all.

The project spread fast. Over the following months, hundreds of programmers pitched in, and by October 2026 the project listed about 2,000 contributors on GitHub. They added support for Intel and AMD processors (AMD makes chips that compete with Intel’s), Apple’s graphics hardware, Nvidia’s toolkit for using graphics cards to do non-graphics math (CUDA), other cross-platform graphics tools, and new ways to shrink the model’s numbers so they take up less memory.

How llama.cpp turns a file into a reply: map the GGUF file, plan the math, run on your chip, pick and stream words
The four steps llama.cpp runs for every reply, as described in this post.

Why it avoids extra software

What sets llama.cpp apart from almost every other AI project? It refuses to depend on much of anything else.

Most AI software is fragile because of how much it relies on other pieces of code. Install a typical Python AI toolkit, and your project folder downloads hundreds of connected packages, each one maintained by someone else. That folder can easily reach ten to thirty gigabytes. Update one small piece, and the whole setup can break.

llama.cpp skips all of that. It’s written in plain C and C++, the same languages most operating systems are built in. It doesn’t need Python. It doesn’t need extra math libraries unless you choose to add them yourself. Point it at a bare computer with nothing but a standard compiler installed, and it builds into one small program in under thirty seconds:

# Clone the clean source repository
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp

# Configure build with CMake (zero third-party libraries needed)
cmake -B build

# Compile the native high-performance binary
cmake --build build --config Release -j

What you get is one file, called llama-cli, that talks directly to your operating system and processor. It reads the model’s saved weights from a single-file format (GGUF, a common way to package a model so it runs on ordinary computers), lines the numbers up in memory itself, and runs the math close to the chip’s top speed.

llama.cpp in the Local AI Technology Stack matrix
Where llama.cpp sits in the local AI toolchain: the bare engine at the bottom, friendlier tools like Ollama and LM Studio built on top of it, next to the much heavier Python stack for comparison.

The engine most local AI tools run on

Plenty of people use local AI every day without knowing llama.cpp is doing the actual work. The earlier post in this series looked at two friendly tools, Ollama and LM Studio, that made local AI easy for non-programmers through simple menus and a clean command line (the text window where you type commands).

Both tools look polished, but underneath, they hand the real computing work to llama.cpp:

  • Ollama: a management layer written in Go, a programming language built for background services. It handles downloading models, running them in the background, and giving you a clean command line. When you type “ollama run,” that Go program quietly starts a copy of llama.cpp and hands it the model.
  • LM Studio: a desktop app built with Electron, the same web-based toolkit behind many modern desktop apps. When you drag a slider to offload work to your graphics card, or search for a model file, the interface is really just talking to llama.cpp running in the background.
  • Jan, GPT4All, Faraday, and LangChain: nearly every desktop AI app, privacy-focused assistant, and small embedded device you’ll come across uses llama.cpp to do the actual work.

Knowing that clears up a lot of confusion. The friendly apps are convenient, but they also add layers that can hide what’s actually slowing you down, limit which settings you can change, or add overhead you don’t need. Learn llama.cpp directly, and you control the number of processor threads, how memory gets loaded, batch sizes, how much work goes to the graphics card, and the exact build settings.

The llama.cpp Architectural Stack swimlanes diagram
The four layers llama.cpp runs on: the chip itself, the GGML math library built for it, the inference engine, and the app layer people see. llama.cpp runs models compressed from 2-bit to 8-bit.

How it works: the GGML math library

Why does llama.cpp run so well on ordinary hardware? Look at its mathematical core: a small library built specifically for running AI models rather than general-purpose math (GGML). Compared to standard scientific computing tools, GGML makes a few unusual choices:

  • One block of memory, reused: Most AI software grabs and frees small chunks of memory constantly while running a model, which slows things down and leaves memory scattered in pieces. GGML instead sets aside one large block up front, called a scratchpad, and reuses it throughout the whole conversation.
  • Shrunk numbers, built in from the start: In most AI libraries, shrinking a model’s numbers to save space (a technique called quantization) is bolted on after the fact. GGML treats those shrunk formats, at 4, 5, or 6 bits instead of the usual 16 or 32, as native data types. It can multiply them directly without converting back to full-size numbers first, which keeps things fast and light on memory.
  • Loading without copying (memory mapping): When llama.cpp opens a sixteen-gigabyte model file, it doesn’t read the whole thing into memory the normal way. It asks the operating system to memory-map the file, a trick called “mmap” that lets a program treat a file on disk as though it were already loaded. The computer then pulls in pieces of the file from your drive only as needed, so the program starts almost instantly and never keeps two copies of the same data in memory.

Try it yourself: a quick test

Here’s a plain example. This short Python script talks to a llama.cpp server running on your own machine. Instead of going through a cloud vendor’s software kit, it connects straight to llama.cpp’s built-in web server and measures how fast it responds:

import time
import requests
import json

# Configuration for native llama.cpp HTTP server daemon
LLAMA_SERVER_URL = "http://127.0.0.1:8080/completion"

def query_native_llamacpp(prompt: str, max_tokens: int = 150):
    payload = {
        "prompt": prompt,
        "n_predict": max_tokens,
        "temperature": 0.2,
        "top_p": 0.95,
        "stop": ["\n\n", "User:", "###"]
    }

    print(f"--- Sending Inference Request to Native llama.cpp ---\nPrompt: {prompt}\n")
    start_time = time.time()

    try:
        response = requests.post(
            LLAMA_SERVER_URL,
            headers={"Content-Type": "application/json"},
            json=payload,
            timeout=30
        )
        response.raise_for_status()
        data = response.json()

        elapsed = time.time() - start_time
        content = data.get("content", "").strip()
        tokens_evaluated = data.get("tokens_evaluated", 0)
        tokens_predicted = data.get("tokens_predicted", 0)

        # Calculate exact hardware metrics
        gen_speed = tokens_predicted / elapsed if elapsed > 0 else 0

        print(f"Generated Output:\n{content}\n")
        print("--- Telemetry Summary ---")
        print(f"Prompt Tokens: {tokens_evaluated}")
        print(f"Generated Tokens: {tokens_predicted}")
        print(f"Total Duration: {elapsed:.2f} seconds")
        print(f"Generation Speed: {gen_speed:.1f} tokens/second")

    except requests.exceptions.ConnectionError:
        print("Error: llama-server is not running on localhost:8080.")
        print("Launch it using: ./build/bin/llama-server -m <model.gguf> -c 2048")

if __name__ == "__main__":
    sample_prompt = "Explain why zero-dependency C++ software provides higher reliability than Python runtimes:"
    query_native_llamacpp(sample_prompt)

That’s the whole point of the design. The server answering these requests isn’t a Python program running through a typical web framework. It’s a single compiled program that handles the web request itself, reads the incoming data directly in memory, and streams back each word with almost no extra overhead.

Common questions about llama.cpp

Is llama.cpp connected to Meta?
No. It started out by running Meta’s LLaMA model, but Georgi Gerganov and the other people who maintain it have no business relationship with Meta. Today it runs models from many different companies, including Mistral, Qwen, DeepSeek, Gemma, Phi, Command R, and Falcon.

Can I use it in a product I sell?
Yes. It’s released under a short, common open-source license (MIT) that lets anyone use, change, sell, and build on the code without paying a fee or asking permission.

Do I need a graphics card?
No. Running well on a plain processor (the main chip in every computer) was a goal from day one. Without a graphics card, llama.cpp automatically uses speed-up features built into modern Intel, AMD, and ARM chips (ARM designs the chips used in most phones and Apple’s own computers), spread across every processor core it can find, and still produces text at a readable pace.

What’s the difference between llama.cpp and Ollama?
llama.cpp is the bare engine that does the actual math. Ollama is the friendlier layer built around it: model downloads, a command line, background management. Think of llama.cpp as the engine and Ollama as the car built around it.

Your next step

Build llama.cpp or install it with a package manager, download one small GGUF model, and run the short test script from this post against llama-server. Getting one reply from the bare engine makes every later post in this series easier to follow.

Sources

Series notes

This is Part 1 of llama.cpp from scratch. Next: install paths for normal people.

Written by

Jose S

Founder & Lead Analyst · Analytics Made Simple

Hands-on data strategist, analytics engineering lead, and educator. Writing practical, no-fluff guides to help everyday teams, analysts, and engineers master SQL, AI systems, and modern data architectures.

Keep going

Same lessons in your feed

Short diagrams, hooks, and weekly tutorials on Substack, Instagram, X, and Facebook.

Google Search Prefer our practical guides in Google Search & Top Stories: