Install any skill in seconds. Free to start, no credit card required.
Get Started Free →GGUF format and llama.cpp quantization for efficient CPU/GPU inference. Use when deploying models on consumer hardware, Apple Silicon, or when needing flexible quantization from 2-8 bit without GPU requirements.
.claude/skills/openlair-gguf-quantization/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 141% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 318% | 0% |
| case-21 | ✓→✓ | = Same ✓ | 103% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 404% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 160% | 0% |
The GGUF (GPT-Generated Unified Format) is the standard file format for llama.cpp, enabling efficient inference on CPUs, Apple Silicon, and GPUs with flexible quantization options.
Use GGUF when:
Key advantages:
Use alternatives instead:
bash# Clone llama.cpp git clone https://github.com/ggml-org/llama.cpp cd llama.cpp # Build (CPU) make # Build with CUDA (NVIDIA) make GGML_CUDA=1 # Build with Metal (Apple Silicon) make GGML_METAL=1 # Install Python bindings (optional) pip install llama-cpp-python
bash# Install requirements pip install -r requirements.txt # Convert HuggingFace model to GGUF (FP16) python convert_hf_to_gguf.py ./path/to/model --outfile model-f16.gguf # Or specify output type python convert_hf_to_gguf.py ./path/to/model \ --outfile model-f16.gguf \ --outtype f16
bash# Basic quantization to Q4_K_M ./llama-quantize model-f16.gguf model-q4_k_m.gguf Q4_K_M # Quantize with importance matrix (better quality) ./llama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix ./llama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M
bash# CLI inference ./llama-cli -m model-q4_k_m.gguf -p "Hello, how are you?" # Interactive mode ./llama-cli -m model-q4_k_m.gguf --interactive # With GPU offload ./llama-cli -m model-q4_k_m.gguf -ngl 35 -p "Hello!"
| Type | Bits | Size (7B) | Quality | Use Case | |------|------|-----------|---------|----------| | Q2_K | 2.5 | ~2.8 GB | Low | Extreme compression | | Q3_K_S | 3.0 | ~3.0 GB | Low-Med | Memory constrained | | Q3_K_M | 3.3 | ~3.3 GB | Medium | Balance | | Q4_K_S | 4.0 | ~3.8 GB | Med-High | Good balance | | Q4_K_M | 4.5 | ~4.1 GB | High | Recommended default | | Q5_K_S | 5.0 | ~4.6 GB | High | Quality focused | | Q5_K_M | 5.5 | ~4.8 GB | Very High | High quality | | Q6_K | 6.0 | ~5.5 GB | Excellent | Near-original | | Q8_0 | 8.0 | ~7.2 GB | Best | Maximum quality |
| Type | Description | |------|-------------| | Q4_0 | 4-bit, basic | | Q4_1 | 4-bit with delta | | Q5_0 | 5-bit, basic | | Q5_1 | 5-bit with delta |
Recommendation: Use K-quant methods (Q4_K_M, Q5_K_M) for best quality/size ratio.
bash# 1. Download model huggingface-cli download meta-llama/Llama-3.1-8B --local-dir ./llama-3.1-8b # 2. Convert to GGUF (FP16) python convert_hf_to_gguf.py ./llama-3.1-8b \ --outfile llama-3.1-8b-f16.gguf \ --outtype f16 # 3. Quantize ./llama-quantize llama-3.1-8b-f16.gguf llama-3.1-8b-q4_k_m.gguf Q4_K_M # 4. Test ./llama-cli -m llama-3.1-8b-q4_k_m.gguf -p "Hello!" -n 50
bash# 1. Convert to GGUF python convert_hf_to_gguf.py ./model --outfile model-f16.gguf # 2. Create calibration text (diverse samples) cat > calibration.txt << 'EOF' The quick brown fox jumps over the lazy dog. Machine learning is a subset of artificial intelligence. Python is a popular programming language. # Add more diverse text samples... EOF # 3. Generate importance matrix ./llama-imatrix -m model-f16.gguf \ -f calibration.txt \ --chunk 512 \ -o model.imatrix \ -ngl 35 # GPU layers if available # 4. Quantize with imatrix ./llama-quantize --imatrix model.imatrix \ model-f16.gguf \ model-q4_k_m.gguf \ Q4_K_M
bash#!/bin/bash MODEL="llama-3.1-8b-f16.gguf" IMATRIX="llama-3.1-8b.imatrix" # Generate imatrix once ./llama-imatrix -m $MODEL -f wiki.txt -o $IMATRIX -ngl 35 # Create multiple quantizations for QUANT in Q4_K_M Q5_K_M Q6_K Q8_0; do OUTPUT="llama-3.1-8b-${QUANT,,}.gguf" ./llama-quantize --imatrix $IMATRIX $MODEL $OUTPUT $QUANT echo "Created: $OUTPUT ($(du -h $OUTPUT | cut -f1))" done
pythonfrom llama_cpp import Llama # Load model llm = Llama( model_path="./model-q4_k_m.gguf", n_ctx=4096, # Context window n_gpu_layers=35, # GPU offload (0 for CPU only) n_threads=8 # CPU threads ) # Generate output = llm( "What is machine learning?", max_tokens=256, temperature=0.7, stop=["</s>", "\n\n"] ) print(output["choices"][0]["text"])
pythonfrom llama_cpp import Llama llm = Llama( model_path="./model-q4_k_m.gguf", n_ctx=4096, n_gpu_layers=35, chat_format="llama-3" # Or "chatml", "mistral", etc. ) messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is Python?"} ] response = llm.create_chat_completion( messages=messages, max_tokens=256, temperature=0.7 ) print(response["choices"][0]["message"]["content"])
pythonfrom llama_cpp import Llama llm = Llama(model_path="./model-q4_k_m.gguf", n_gpu_layers=35) # Stream tokens for chunk in llm( "Explain quantum computing:", max_tokens=256, stream=True ): print(chunk["choices"][0]["text"], end="", flush=True)
bash# Start server ./llama-server -m model-q4_k_m.gguf \ --host 0.0.0.0 \ --port 8080 \ -ngl 35 \ -c 4096 # Or with Python bindings python -m llama_cpp.server \ --model model-q4_k_m.gguf \ --n_gpu_layers 35 \ --host 0.0.0.0 \ --port 8080
pythonfrom openai import OpenAI client = OpenAI( base_url="http://localhost:8080/v1", api_key="not-needed" ) response = client.chat.completions.create( model="local-model", messages=[{"role": "user", "content": "Hello!"}], max_tokens=256 ) print(response.choices[0].message.content)
bash# Build with Metal make clean && make GGML_METAL=1 # Run with Metal acceleration ./llama-cli -m model.gguf -ngl 99 -p "Hello" # Python with Metal llm = Llama( model_path="model.gguf", n_gpu_layers=99, # Offload all layers n_threads=1 # Metal handles parallelism )
bash# Build with CUDA make clean && make GGML_CUDA=1 # Run with CUDA ./llama-cli -m model.gguf -ngl 35 -p "Hello" # Specify GPU CUDA_VISIBLE_DEVICES=0 ./llama-cli -m model.gguf -ngl 35
bash# Build with AVX2/AVX512 make clean && make # Run with optimal threads ./llama-cli -m model.gguf -t 8 -p "Hello" # Python CPU config llm = Llama( model_path="model.gguf", n_gpu_layers=0, # CPU only n_threads=8, # Match physical cores n_batch=512 # Batch size for prompt processing )
bash# Create Modelfile cat > Modelfile << 'EOF' FROM ./model-q4_k_m.gguf TEMPLATE """{{ .System }} {{ .Prompt }}""" PARAMETER temperature 0.7 PARAMETER num_ctx 4096 EOF # Create Ollama model ollama create mymodel -f Modelfile # Run ollama run mymodel "Hello!"
~/.cache/lm-studio/models/bash# Place in models folder cp model-q4_k_m.gguf text-generation-webui/models/ # Start with llama.cpp loader python server.py --model model-q4_k_m.gguf --loader llama.cpp --n-gpu-layers 35
Model loads slowly:
bash# Use mmap for faster loading ./llama-cli -m model.gguf --mmap
Out of memory:
bash# Reduce GPU layers ./llama-cli -m model.gguf -ngl 20 # Reduce from 35 # Or use smaller quantization ./llama-quantize model-f16.gguf model-q3_k_m.gguf Q3_K_M
Poor quality at low bits:
bash# Always use imatrix for Q4 and below ./llama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix ./llama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-21 | pass→pass | 14,558 | 12,717 | -13% | 1 | 1 | 0% | 2,892 | 5,858 | +103% | 0 | 0 | — |
case-01 | fail→pass | 11,496 | 8,442 | -27% | 1 | 1 | 0% | 2,113 | 5,084 | +141% | 0 | 0 | — |
case-02 | pass→pass | 3,907 | 2,676 | -32% | 1 | 1 | 0% | 786 | 3,960 | +404% | 0 | 0 | — |
case-03 | pass→pass | 8,723 | 4,499 | -48% | 1 | 1 | 0% | 1,671 | 4,339 | +160% | 0 | 0 | — |
case-22 | fail→fail | 9,090 | 6,628 | -27% | 1 | 1 | 0% | 2,000 | 4,909 | +145% | 0 | 0 | — |
case-04 | pass→pass | 5,955 | 2,931 | -51% | 1 | 1 | 0% | 1,127 | 3,969 | +252% | 0 | 0 | — |
case-05 | fail→pass | 5,137 | 2,794 | -46% | 1 | 1 | 0% | 945 | 3,950 | +318% | 0 | 0 | — |
case-06 | pass→pass | 10,684 | 7,569 | -29% | 1 | 1 | 0% | 1,745 | 4,814 | +176% | 0 | 0 | — |
case-07 | pass→pass | 4,939 | 2,930 | -41% | 1 | 1 | 0% | 982 | 4,006 | +308% | 0 | 0 | — |
case-08 | pass→pass | 6,561 | 2,879 | -56% | 1 | 1 | 0% | 1,100 | 3,952 | +259% | 0 | 0 | — |
case-09 | pass→pass | 3,597 | 2,844 | -21% | 1 | 1 | 0% | 721 | 4,009 | +456% | 0 | 0 | — |
case-10 | pass→pass | 7,424 | 6,100 | -18% | 1 | 1 | 0% | 1,383 | 4,607 | +233% | 0 | 0 | — |
case-11 | pass→pass | 3,745 | 2,599 | -31% | 1 | 1 | 0% | 747 | 3,922 | +425% | 0 | 0 | — |
case-12 | pass→pass | 2,899 | 2,905 | +0% | 1 | 1 | 0% | 508 | 3,896 | +667% | 0 | 0 | — |
case-13 | pass→pass | 7,640 | 4,990 | -35% | 1 | 1 | 0% | 1,520 | 4,428 | +191% | 0 | 0 | — |
case-14 | pass→pass | 5,315 | 4,081 | -23% | 1 | 1 | 0% | 932 | 4,247 | +356% | 0 | 0 | — |
case-15 | pass→pass | 10,544 | 6,979 | -34% | 1 | 1 | 0% | 1,850 | 4,755 | +157% | 0 | 0 | — |
case-16 | pass→pass | 9,936 | 7,909 | -20% | 1 | 1 | 0% | 2,012 | 4,917 | +144% | 0 | 0 | — |
case-17 | pass→pass | 5,365 | 4,623 | -14% | 1 | 1 | 0% | 995 | 4,281 | +330% | 0 | 0 | — |
case-18 | pass→pass | 4,965 | 3,807 | -23% | 1 | 1 | 0% | 835 | 4,126 | +394% | 0 | 0 | — |
case-19 | pass→pass | 6,537 | 2,484 | -62% | 1 | 1 | 0% | 1,295 | 3,879 | +200% | 0 | 0 | — |
case-20 | pass→pass | 9,944 | 3,740 | -62% | 1 | 1 | 0% | 1,833 | 4,232 | +131% | 0 | 0 | — |
case-23 | pass→pass | 10,228 | 5,531 | -46% | 1 | 1 | 0% | 2,135 | 4,566 | +114% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 23 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.