CloudCodeTree LogoCloudCodeTree
AI NewsTutorialsAbout
CloudCodeTree Logo
CloudCodeTree
  • AI News
  • Tutorials
  • About
← Back to AI News
Four Commands Shrink Any Open Model to Fit Your Laptop: GGUF Quantization with llama.cpp

Four Commands Shrink Any Open Model to Fit Your Laptop: GGUF Quantization with llama.cpp

Chris Harper

2 min read

Aug 4, 2026 · 12:03 UTC

AI
Tutorial
Self-Hosting
LLM

GGUF quantization compresses 16-bit weights to 4-bit, shrinking a 7B model from 14GB to under 5GB with minimal quality loss — runnable on a MacBook, a gaming GPU, or a CPU.

What you'll be able to do after this:

  • Convert any Hugging Face model to GGUF and quantize it to Q4_K_M in under 10 minutes
  • Understand what Q4_K_M, Q5_K_M, and Q8_0 trade off and which to pick for your use case
  • Serve your quantized model as a local OpenAI-compatible API endpoint for use in any agent workflow

Large language models ship as 16-bit floating-point files. A 7B-parameter model weighs roughly 14GB at full precision, requiring 16GB+ of VRAM to load. GGUF quantization compresses each weight from 16 bits to 4 (or 5, or 8), shrinking the same model to 4–5GB while preserving most of its reasoning quality.

llama.cpp is the standard tool. Here's the full end-to-end workflow:

# 1. Build llama.cpp from source
git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
cmake -B build && cmake --build build --config Release -j$(nproc)

# 2. Download a model from Hugging Face (example: Llama 3.1 8B)
pip install huggingface_hub
huggingface-cli download meta-llama/Meta-Llama-3.1-8B-Instruct --local-dir ./llama-3.1-8b

# 3. Convert to FP16 GGUF (required intermediate step)
python convert_hf_to_gguf.py ./llama-3.1-8b --outtype f16 --outfile llama-3.1-8b-f16.gguf

# 4. Quantize to Q4_K_M
./build/bin/llama-quantize llama-3.1-8b-f16.gguf llama-3.1-8b-q4km.gguf Q4_K_M

Choosing a quantization level. The _K_M suffix stands for "K-quants, medium" — attention and embedding layers stay at higher precision while feed-forward layers are aggressively quantized. Use Q4_K_M as your default. Step up to Q5_K_M if you have the VRAM and want near-lossless quality. Q8_0 is effectively lossless but almost as large as FP16. Avoid Q3 and below for anything beyond simple chat — quality degrades noticeably.

Once quantized, run it:

# Interactive chat session
./build/bin/llama-cli -m llama-3.1-8b-q4km.gguf -n 512 --conversation

# Or serve a local OpenAI-compatible API on port 8080
./build/bin/llama-server -m llama-3.1-8b-q4km.gguf --port 8080

The llama-server endpoint is drop-in compatible with the OpenAI API: point any SDK or agent harness at http://localhost:8080/v1/chat/completions and it works without any code changes.

Sources: GGUF Quantization Tutorial: Run Fine-Tuned LLMs on CPU with llama.cpp — YouTube · llama.cpp quantize README — GitHub · Quantize Llama models with llama.cpp — Towards Data Science