Skip to main content
PromptQuorumBuilt for humans. Structured for AI.

How Do You Convert a Model to GGUF With llama.cpp?

By · 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
How Do You Convert a Model to GGUF With llama.cpp?

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
Technique & Concept ExplainersIntermediate

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`.

Frequently Asked Questions

Should I quantize during conversion or convert to full precision first?▾
Convert to full precision (f16) first if you plan to compare multiple quantization levels — quantizing separately afterward from the same f16 source gives more accurate results than quantizing directly from a source model during conversion, and lets you produce several quantized variants without repeating the conversion step.
Why does my converted GGUF file fail to load in Ollama or LM Studio even though conversion succeeded?▾
A successful conversion doesn't guarantee the loading tool supports that specific architecture or GGUF version. GGUF format and architecture support both evolve over time, and an older tool version may not recognize a file produced by a newer conversion script — keep both tools updated together.
How much disk space does conversion need?▾
Budget for the source model's full size plus the output GGUF file's size simultaneously — for a full-precision conversion, that roughly doubles the model's footprint during the process. Quantized output files are smaller, but you still need the source files present until conversion finishes.
Can I convert a model that's already been fine-tuned?▾
Yes — the conversion process works the same way on a fine-tuned model as a base model, as long as the fine-tuned weights are saved in a standard Hugging Face-compatible format. If the fine-tune used adapter weights (like LoRA) rather than full weights, merge the adapter into the base model first, then convert the merged result.
How do I convert safetensors to GGUF?▾
Download the complete model repository so the folder holds the .safetensors weight files plus config.json and the tokenizer files, then run `python convert_hf_to_gguf.py --outfile model-f16.gguf --outtype f16`. The script reads safetensors directly, so no intermediate format is needed. Run `llama-quantize` on the result if you want a smaller file.
Should I use f16 or bf16 as the output type?▾
Use bf16 when the source model was published in bfloat16, because it keeps that format's numeric range; f16 is the usual choice otherwise. The default, auto, picks the highest-fidelity 16-bit type for you, so omitting `--outtype` is often fine.
How long does GGUF conversion take and what does it cost?▾
Conversion is free: llama.cpp is open source and the script runs locally, so the only costs are disk space and RAM. There is no fixed duration — the script reads and rewrites the weights, so time depends on model size and disk speed, and quantizing with `llama-quantize` is a second pass on top.
MCP