How Do You Convert a Model to GGUF With llama.cpp?
By Hans Kuepper · Founder of PromptQuorum · Discovery engine for open-weight & open-source AI
Convert a model to GGUF with llama.cpp's convert_hf_to_gguf.py script, which reads a source model's weights and metadata and writes them into the single-file GGUF format. Run the script against a Hugging Face-format model directory with a full-precision output type (f16 or bf16), optionally quantize the result with llama-quantize, and the `.gguf` file loads in llama.cpp, Ollama, or LM Studio.
Key Takeaways
- ✓GGUF conversion reads a Hugging Face-format model's weights and metadata and writes them into a single portable .gguf file
- ✓Convert to f16/f32 first if you plan to try multiple quantization levels — quantizing from an already-quantized conversion loses more quality than quantizing from full precision
- ✓The output type you choose at conversion time determines both file size and inference quality — there is no free lunch between the two
- ✓Most conversion errors trace back to an incompatible or incomplete source model directory, not the conversion script itself

Quick Answer
Run llama.cpp's convert_hf_to_gguf.py against a Hugging Face-format model directory with an output type such as f16 or bf16 (full precision). The script itself only quantizes to q8_0, so for levels like Q4_K_M run llama-quantize on the resulting file afterward. The .gguf output loads directly in llama.cpp, Ollama, or LM Studio.
- ▸Source model must be in Hugging Face format (safetensors or PyTorch checkpoint) before conversion
- ▸Output types the conversion script accepts: f32, f16, bf16, q8_0, tq1_0, tq2_0, or auto (the default, which picks the highest-fidelity 16-bit type)
- ▸Quantize to Q4_K_M, Q5_K_M and other levels with llama-quantize, starting from the f16 or bf16 file — not during conversion
The Conversion Process
Conversion has three practical steps: prepare the source model, run the conversion script with an output type, and — if you converted to full precision — quantize afterward.
- ▸1. Prepare the source model: the conversion script expects a Hugging Face-format directory containing the model's weight files (safetensors is preferred over legacy PyTorch `.bin` checkpoints) plus its config and tokenizer files. A partially downloaded or manually assembled directory missing the tokenizer files is the single most common cause of conversion failures.
- ▸2. Run the conversion script with an output type: `python convert_hf_to_gguf.py
--outfile model-f16.gguf --outtype f16` produces a full-precision GGUF file; install the Python dependencies from the repository's `requirements.txt` first. The accepted output types are f32, f16, bf16, q8_0, tq1_0, tq2_0 and auto (the default, which picks the highest-fidelity 16-bit type). Only q8_0 is a conventional quantization, so quantizing during conversion gives you less control than converting to f16 or bf16 first. - ▸3. Quantize separately for more control (optional but recommended): starting from the f16 or bf16 GGUF file, run `llama-quantize model-f16.gguf model-Q4_K_M.gguf Q4_K_M` to produce a quantized variant. Repeat with other types (Q5_K_M, Q6_K, Q8_0) from the same full-precision file to compare quality/size tradeoffs without re-running the conversion. An optional `--imatrix` file can reduce the accuracy loss at low bit widths.
Common Conversion Errors
Most conversion failures fall into a small number of categories, almost always traceable to the source model rather than the script itself.
- ▸Unrecognized architecture: the conversion script maintains an internal list of supported model architectures. A very new or unusual architecture may not be supported yet — check the tool's supported-architecture list before assuming the model files are broken.
- ▸Missing tokenizer files: conversion needs the tokenizer configuration alongside the weights. A model directory with only weight files and no tokenizer files will fail partway through conversion.
- ▸Mismatched file format expectations: legacy PyTorch `.bin` checkpoints sometimes need an extra conversion step to safetensors first, depending on the tool version — prefer downloading models that already ship in safetensors format to avoid this entirely.
- ▸Insufficient disk space or RAM during conversion: conversion loads the full-precision model into memory before writing it out, so it needs roughly the same RAM as the model's full-precision size, plus the disk space for both the source files and the output GGUF file simultaneously.
- ▸Unsupported `--outtype`: passing `Q4_K_M` or another K-quant type to `convert_hf_to_gguf.py` is rejected as an invalid choice. Convert to f16 or bf16 first, then quantize the result with `llama-quantize`.