Skip to content

How-ToGPU

How to Convert a Hugging Face Model to GGUF and Quantise It With llama.cpp

How to convert a Hugging Face model to GGUF with llama.cpp's convert_hf_to_gguf.py, quantise it with llama-quantize to fit your graphics card, handle vision models' mmproj files, and load the result in llama.cpp or Ollama.

By , Systems & Technical Editor

5 min read

How to Convert a Hugging Face Model to GGUF and Quantise It With llama.cpp

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.

The bottom line

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.

Sources

  1. 01llama.cpp on GitHub, quantize README
  2. 02llama.cpp on GitHub, convert_hf_to_gguf.py
  3. 03llama.cpp on GitHub, How to build
  4. 04Ollama documentation, Importing a model
  5. 05Hugging Face Hub documentation, GGUF

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

Integrated vs Dedicated Graphics: Do You Need a Graphics Card?

Versus

Integrated vs Dedicated Graphics: Do You Need a Graphics Card?

Integrated graphics are built into the CPU and share system RAM, so they suit office work, video, small PCs and light games, and make a useful backup. A dedicated graphics card has its own GPU and VRAM, so it's what you need for modern games at good settings, high-refresh monitors and most local AI.

Callum Reid5 min

Best Free FPS Counter Software for PC in 2026

Best Picks

Best Free FPS Counter Software for PC in 2026

MSI Afterburner with RTSS is the best free FPS counter for most enthusiasts, working with NVIDIA and AMD cards and fully customisable. The NVIDIA app and AMD Software overlays are the easiest built-in options and show lows as well as averages, Steam's Performance Overlay separates generated frames, Intel PresentMon is best for spotting CPU or GPU bottlenecks, and Xbox Game Bar is already in Window

Hannah Vance6 min

DirectX 11 vs DirectX 12 vs Vulkan: Which Should You Pick in Games?

Versus

DirectX 11 vs DirectX 12 vs Vulkan: Which Should You Pick in Games?

DirectX 12 and Vulkan are lower-level graphics APIs designed to cut CPU overhead and scale across more CPU cores, and DirectX 12 unlocks features such as ray tracing and the DirectX 12 Ultimate set. DirectX 11 is older and more driver-managed but remains a useful fallback for older GPUs or when a DX12 mode misbehaves. Vulkan is cross-platform and key on Linux. Start with the game's default.

Callum Reid6 min

How to Fix Missing DLL Errors in Windows 11 (VCRUNTIME140, MSVCP140 and More)

How-To

How to Fix Missing DLL Errors in Windows 11 (VCRUNTIME140, MSVCP140 and More)

Most "DLL was not found" errors in Windows 11 mean a program needs a Microsoft runtime that isn't installed. Install the latest Visual C++ v14 Redistributable (x64 and x86) for VCRUNTIME140 and MSVCP140 errors, older Visual C++ packages for 120, 110 or 100 files, and the DirectX End-User Runtime for d3dx9 or xinput1_3 errors. Then verify game files or run DISM and SFC. Avoid DLL download sites.

Marcus Thorne7 min