Many models ship only as Hugging Face safetensors, while llama.cpp, Ollama, and LM Studio run GGUF files. The converter script in the llama.cpp source tree turns a downloaded model folder into a GGUF file, ready for quantizing or loading directly.
What you need
- Git, Python 3.12, and a llama.cpp checkout
- Disk space for the source model plus the GGUF, about three times the model size
- A small public model to practise on, such as SmolLM2-135M
Step 1: Set up the converter
Clone llama.cpp with git clone https://github.com/ggml-org/llama.cpp, enter the folder, create a virtual environment with python3 -m venv .venv, activate it, and install the converter requirements with pip install -r requirements/requirements-convert_hf_to_gguf.txt huggingface_hub.
Step 2: Download the model folder
Run hf download HuggingFaceTB/SmolLM2-135M –local-dir models/smollm2-135m. Check the folder holds config.json, tokenizer files, and model.safetensors; a missing file stops the conversion.
Step 3: Convert and test the GGUF
Run python3 convert_hf_to_gguf.py models/smollm2-135m –outfile models/smollm2-135m-f16.gguf –outtype f16. Inspect the result with python3 gguf-py/gguf/scripts/gguf_dump.py, then load it with llama-cli -m models/smollm2-135m-f16.gguf -p ‘Once upon a time’ -n 32 –single-turn.
Worked example: convert SmolLM2-135M to F16 GGUF
The table below is a synthetic example. The commands and the 269.1M output size come from the cited conversion guide; the model is its documented example.
| Step | Command or file | Expected result |
|---|---|---|
| Download | hf download HuggingFaceTB/SmolLM2-135M | model.safetensors present |
| Convert | convert_hf_to_gguf.py –outtype f16 | 269.1M GGUF, 272 tensors |
| Test | llama-cli -m …-f16.gguf -p ‘Once upon a time’ | Model generates text |
Expected result (UNTESTED). the converter reports Model successfully exported, gguf_dump.py lists the metadata, and llama-cli generates text from the GGUF. This check was not run live; the commands and sizes come from the cited conversion guide.
Limits
- Only architectures the converter supports can be converted; very new ones need a current checkout.
- Conversion and quantization run on CPU; a GPU only speeds up testing.
- Use bf16 for most modern models and f16 for older float16 ones.
- Always quantize from the 16-bit GGUF, never re-quantize an already quantized file.
