The steps follow llama.cpp's official quantize and build documentation, Ollama's import guide and Hugging Face's GGUF documentation.
Many popular models are published on Hugging Face in GGUF format, ready for llama.cpp, LM Studio or Ollama. But sometimes the model you want, a fine-tune or a brand-new release, is only available as the original Safetensors weights, or nobody has published the quantisation level you need. In that case you can make the GGUF yourself. If you're not sure what GGUF and quantisation are, start with our LLM quantization and GGUF explainer and our GGUF vs Safetensors comparison.
The quick alternative: GGUF-my-repo
If you'd rather not install anything, both llama.cpp's quantize documentation and Hugging Face's GGUF documentation point to the GGUF-my-repo space on Hugging Face, which converts and quantises a model for you in the browser. llama.cpp's documentation says it syncs from llama.cpp's main branch every six hours. The rest of this guide covers doing it on your own PC, which works offline once the model is downloaded and gives you full control over the options.
What you need
llama.cpp's source code, for the conversion script, and a build of its tools, for llama-quantize. llama.cpp's build guide starts with git clone https://github.com/ggml-org/llama.cpp and builds with CMake (cmake -B build, then cmake --build build --config Release). On Windows, our guide to setting up WSL2 for local AI is one route; our llama.cpp on Windows guide covers running it natively.
Python, to run the conversion script and its requirements.
Disk space and RAM. You'll keep the original weights, a full-precision GGUF and the quantised file, so allow several times the model's size. The conversion script has a --use-temp-file option that its help text describes as helpful when running out of memory.
The model. Our guide to downloading models from Hugging Face explains how. Some models require you to accept a licence on Hugging Face first.
Step 1: Install the Python requirements
From the llama.cpp folder, install the requirements as llama.cpp's documentation shows:
python3 -m pip install -r requirements.txt
The documentation notes that, for compatibility, these install version 4 of the transformers library, but more and more models, such as Gemma 4, need transformers 5. It says you can safely upgrade with pip install -U transformers.
You can check whether a model architecture is supported by running python convert_hf_to_gguf.py --print-supported-models. If your model's architecture isn't listed, conversion won't work until llama.cpp adds support.
Step 2: Convert the model to a high-precision GGUF
llama.cpp's documentation describes quantisation as a two-phase process: convert the original model to GGUF first, then quantise the converted file. Its example converts a model straight from a Hugging Face repository:
python convert_hf_to_gguf.py --outfile gemma-4-E2B-it-bf16.gguf --outtype bf16 --remote google/gemma-4-E2B-it
Notes from the documentation:
If you've already downloaded the model, give the local folder path instead and remove --remote. The script's help text describes --remote as experimental: it reads the Safetensors weights remotely without downloading them to disk.
Most models are distributed in 16-bit format, and in that case --outtype auto (or leaving --outtype out) works well. The script's other output types include f32, f16, bf16 and q8_0.
Step 3: Quantise it to fit your GPU
Now shrink the file with llama-quantize. llama.cpp's example produces a Q4_K_M file:
./build/bin/llama-quantize gemma-4-E2B-it-bf16.gguf gemma-4-E2B-it-Q4_K_M.gguf Q4_K_M
The documentation explains that quantisation reduces the precision of the weights, which shrinks the model and can speed it up, but may cost some accuracy. It says that loss can be minimised with a suitable importance matrix (imatrix) file, passed with --imatrix. It also warns that --allow-requantize, for re-quantising an already quantised file, can severely reduce quality compared with quantising from 16-bit or 32-bit, so always quantise from your high-precision GGUF.
Which level should you choose? Pick the highest-quality quantisation that fits comfortably in your VRAM with room left for the context. Our guide to checking whether a model fits your GPU explains the maths. llama.cpp's documentation also lists --target-size and --target-bpw options that choose quantisation types automatically to hit a file size or bits-per-weight target, which is handy if you know exactly how much VRAM you have.
Step 4 (optional): Convert the vision part
If the model accepts images or audio, the conversion above only covers the language model. llama.cpp's documentation says you need a separate mmproj file for the multimodal components, made by running the conversion script with --mmproj, and recommends keeping it in a high-quality format such as bf16 or q8_0 because it's small and affects output quality:
python convert_hf_to_gguf.py --mmproj --outfile mmproj-gemma-4-E2B-it-Q8_0.gguf --outtype q8_0 --remote google/gemma-4-E2B-it
Step 5: Run it
In llama.cpp, the documentation's example loads the quantised model and the mmproj file together:
./build/bin/llama cli -m ./gemma-4-E2B-it-Q4_K_M.gguf --mmproj ./mmproj-gemma-4-E2B-it-Q8_0.gguf --image <image file> --prompt "Describe this image"
For a text-only model, leave out --mmproj and --image. Current llama.cpp documentation uses the llama cli form of the command; our llama.cpp 1.0 news story covers what changed in the latest major release.
In Ollama, create a file called Modelfile containing FROM /path/to/your-model-Q4_K_M.gguf, then run ollama create my-model and ollama run my-model. Ollama's import guide says it doesn't quantise GGUF models during import, so quantise first as above. Our guide to creating a custom Ollama model with a Modelfile covers the other settings you can add.
In LM Studio, which also uses GGUF models, see our guide to running AI models locally with Ollama and LM Studio.
Common problems
"Model architecture not supported": run --print-supported-models and update llama.cpp; new architectures are added regularly.
Errors from transformers on new models: upgrade it with pip install -U transformers, as llama.cpp's documentation suggests.
The process is killed part-way through: you're probably out of RAM. Try --use-temp-file, close other apps or convert on a machine with more memory.
The quantised model is poor: try a higher quantisation level, use an imatrix file, and make sure you quantised from the bf16 or f16 file rather than re-quantising.
Our verdict
Converting a model to GGUF yourself takes two commands once llama.cpp is set up: convert_hf_to_gguf.py to make a high-precision GGUF, then llama-quantize to shrink it to a size that fits your graphics card. Check the architecture is supported first, upgrade transformers for newer models, convert the mmproj file separately for vision models, and always quantise from the bf16 or f16 file. If you'd rather skip the setup, Hugging Face's GGUF-my-repo space does the same job in your browser.