Lesson 2 covered running an already-quantized model through Ollama or llama-server. This lesson covers where that GGUF file actually comes from when you're starting with a model straight from HuggingFace — the two-step convert-then-quantize process that llama.cpp itself uses.
The actual conversion pipeline
1. Clone llama.cpp and install its Python requirements. The conversion script is part of the llama.cpp repository, not a standalone package — you need the repo checked out to run it.
2. Run convert_hf_to_gguf.py against the HuggingFace model directory. This reads the model's config, tokenizer, and safetensors weights and writes out a single FP16 (or BF16) GGUF file — no quantization yet, just a format change.
3. Quantize the FP16 GGUF down with llama-quantize. This is the separate step that actually shrinks the file — Q4_K_M for a good size/quality balance, Q8_0 if you want to stay closer to full precision.
# 1. Convert HuggingFace weights to an FP16 GGUF (llama.cpp repo required)
python llama.cpp/convert_hf_to_gguf.py \
./my-model-hf-directory \
--outtype f16 \
--outfile ./my-model-f16.gguf
# 2. Quantize the FP16 GGUF down to 4-bit (separate step, separate tool)
./llama-quantize \
./my-model-f16.gguf \
./my-model-q4_k_m.gguf \
Q4_K_M
| Step | Tool | What changes |
|---|---|---|
| 1. Format conversion | convert_hf_to_gguf.py |
HuggingFace safetensors → single GGUF file, still full precision |
| 2. Quantization | llama-quantize |
Full-precision GGUF → smaller quantized GGUF (e.g. Q4_K_M) |
Once you have the quantized GGUF, it's the exact file format Lesson 2's Ollama and llama-server commands expect — this is the step that produces the .gguf file those tools load.
Practical Challenge
Pick a small HuggingFace model (under 2B parameters) confirmed on llama.cpp's supported-architectures list, convert it to FP16 GGUF, then quantize it to both Q4_K_M and Q8_0 and compare the resulting file sizes.
Concept Check
Sources & Further Reading
- llama.cpp — convert_hf_to_gguf.py — the actual conversion script referenced in this article's commands.
- llama.cpp (GitHub) — includes
llama-quantizeand the list of supported model architectures.
AI