[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M71PYKJ5FTRA4TNF4WXHCN1D":3,"skill-same:01M71PYKJ5FTRA4TNF4WXHCN1D":81},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":51,"commitSha":52,"skillDirectory":53,"forksCount":13,"repositoryHtmlUrl":54,"repositoryHomepageUrl":6,"ownerHtmlUrl":55,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":56,"install":57,"resources":70},"01M71PYKJ5FTRA4TNF4WXHCN1D","gguf-quantization",null,"GGUF format and llama.cpp quantization for efficient CPU\u002FGPU inference. Use when deploying models on consumer hardware, Apple Silicon, or when needing flexible quantization from 2-8 bit without GPU requirements.","gjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN","gjbvsjjvgm-sketch","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F278511911?v=4","01M71F3JXKZQ70H2KCHHTXKZDA","01M71PENEVFN19DBZFNHJPCHQ7",0,"MIT","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fhermes_sovereign_data\u002Fskills\u002Fmlops\u002Finference\u002Fgguf\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"Quantization","gguf quantization","GGUF","requirements","use","apple silicon","python","Optimization","for","orchestra","Model Compression","CPU Inference","llama.cpp","silicon","CPU","apple","when","cpp","model","bit","2026-11-10 13:02:02",false,"---\nname: gguf-quantization\ndescription: GGUF format and llama.cpp quantization for efficient CPU\u002FGPU inference. Use when deploying models on consumer hardware, Apple Silicon, or when needing flexible quantization from 2-8 bit without GPU requirements.\nversion: 1.0.0\nauthor: Orchestra Research\nlicense: MIT\ndependencies: [llama-cpp-python>=0.2.0]\nmetadata:\n  hermes:\n    tags: [GGUF, Quantization, llama.cpp, CPU Inference, Apple Silicon, Model Compression, Optimization]\n\n---\n\n# GGUF - Quantization Format for llama.cpp\n\nThe 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.\n\n## When to use GGUF\n\n**Use GGUF when:**\n- Deploying on consumer hardware (laptops, desktops)\n- Running on Apple Silicon (M1\u002FM2\u002FM3) with Metal acceleration\n- Need CPU inference without GPU requirements\n- Want flexible quantization (Q2_K to Q8_0)\n- Using local AI tools (LM Studio, Ollama, text-generation-webui)\n\n**Key advantages:**\n- **Universal hardware**: CPU, Apple Silicon, NVIDIA, AMD support\n- **No Python runtime**: Pure C\u002FC++ inference\n- **Flexible quantization**: 2-8 bit with various methods (K-quants)\n- **Ecosystem support**: LM Studio, Ollama, koboldcpp, and more\n- **imatrix**: Importance matrix for better low-bit quality\n\n**Use alternatives instead:**\n- **AWQ\u002FGPTQ**: Maximum accuracy with calibration on NVIDIA GPUs\n- **HQQ**: Fast calibration-free quantization for HuggingFace\n- **bitsandbytes**: Simple integration with transformers library\n- **TensorRT-LLM**: Production NVIDIA deployment with maximum speed\n\n## Quick start\n\n### Installation\n\n```bash\n# Clone llama.cpp\ngit clone https:\u002F\u002Fgithub.com\u002Fggml-org\u002Fllama.cpp\ncd llama.cpp\n\n# Build (CPU)\nmake\n\n# Build with CUDA (NVIDIA)\nmake GGML_CUDA=1\n\n# Build with Metal (Apple Silicon)\nmake GGML_METAL=1\n\n# Install Python bindings (optional)\npip install llama-cpp-python\n```\n\n### Convert model to GGUF\n\n```bash\n# Install requirements\npip install -r requirements.txt\n\n# Convert HuggingFace model to GGUF (FP16)\npython convert_hf_to_gguf.py .\u002Fpath\u002Fto\u002Fmodel --outfile model-f16.gguf\n\n# Or specify output type\npython convert_hf_to_gguf.py .\u002Fpath\u002Fto\u002Fmodel \\\n    --outfile model-f16.gguf \\\n    --outtype f16\n```\n\n### Quantize model\n\n```bash\n# Basic quantization to Q4_K_M\n.\u002Fllama-quantize model-f16.gguf model-q4_k_m.gguf Q4_K_M\n\n# Quantize with importance matrix (better quality)\n.\u002Fllama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix\n.\u002Fllama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M\n```\n\n### Run inference\n\n```bash\n# CLI inference\n.\u002Fllama-cli -m model-q4_k_m.gguf -p \"Hello, how are you?\"\n\n# Interactive mode\n.\u002Fllama-cli -m model-q4_k_m.gguf --interactive\n\n# With GPU offload\n.\u002Fllama-cli -m model-q4_k_m.gguf -ngl 35 -p \"Hello!\"\n```\n\n## Quantization types\n\n### K-quant methods (recommended)\n\n| Type | Bits | Size (7B) | Quality | Use Case |\n|------|------|-----------|---------|----------|\n| Q2_K | 2.5 | ~2.8 GB | Low | Extreme compression |\n| Q3_K_S | 3.0 | ~3.0 GB | Low-Med | Memory constrained |\n| Q3_K_M | 3.3 | ~3.3 GB | Medium | Balance |\n| Q4_K_S | 4.0 | ~3.8 GB | Med-High | Good balance |\n| Q4_K_M | 4.5 | ~4.1 GB | High | **Recommended default** |\n| Q5_K_S | 5.0 | ~4.6 GB | High | Quality focused |\n| Q5_K_M | 5.5 | ~4.8 GB | Very High | High quality |\n| Q6_K | 6.0 | ~5.5 GB | Excellent | Near-original |\n| Q8_0 | 8.0 | ~7.2 GB | Best | Maximum quality |\n\n### Legacy methods\n\n| Type | Description |\n|------|-------------|\n| Q4_0 | 4-bit, basic |\n| Q4_1 | 4-bit with delta |\n| Q5_0 | 5-bit, basic |\n| Q5_1 | 5-bit with delta |\n\n**Recommendation**: Use K-quant methods (Q4_K_M, Q5_K_M) for best quality\u002Fsize ratio.\n\n## Conversion workflows\n\n### Workflow 1: HuggingFace to GGUF\n\n```bash\n# 1. Download model\nhuggingface-cli download meta-llama\u002FLlama-3.1-8B --local-dir .\u002Fllama-3.1-8b\n\n# 2. Convert to GGUF (FP16)\npython convert_hf_to_gguf.py .\u002Fllama-3.1-8b \\\n    --outfile llama-3.1-8b-f16.gguf \\\n    --outtype f16\n\n# 3. Quantize\n.\u002Fllama-quantize llama-3.1-8b-f16.gguf llama-3.1-8b-q4_k_m.gguf Q4_K_M\n\n# 4. Test\n.\u002Fllama-cli -m llama-3.1-8b-q4_k_m.gguf -p \"Hello!\" -n 50\n```\n\n### Workflow 2: With importance matrix (better quality)\n\n```bash\n# 1. Convert to GGUF\npython convert_hf_to_gguf.py .\u002Fmodel --outfile model-f16.gguf\n\n# 2. Create calibration text (diverse samples)\ncat > calibration.txt \u003C\u003C 'EOF'\nThe quick brown fox jumps over the lazy dog.\nMachine learning is a subset of artificial intelligence.\nPython is a popular programming language.\n# Add more diverse text samples...\nEOF\n\n# 3. Generate importance matrix\n.\u002Fllama-imatrix -m model-f16.gguf \\\n    -f calibration.txt \\\n    --chunk 512 \\\n    -o model.imatrix \\\n    -ngl 35  # GPU layers if available\n\n# 4. Quantize with imatrix\n.\u002Fllama-quantize --imatrix model.imatrix \\\n    model-f16.gguf \\\n    model-q4_k_m.gguf \\\n    Q4_K_M\n```\n\n### Workflow 3: Multiple quantizations\n\n```bash\n#!\u002Fbin\u002Fbash\nMODEL=\"llama-3.1-8b-f16.gguf\"\nIMATRIX=\"llama-3.1-8b.imatrix\"\n\n# Generate imatrix once\n.\u002Fllama-imatrix -m $MODEL -f wiki.txt -o $IMATRIX -ngl 35\n\n# Create multiple quantizations\nfor QUANT in Q4_K_M Q5_K_M Q6_K Q8_0; do\n    OUTPUT=\"llama-3.1-8b-${QUANT,,}.gguf\"\n    .\u002Fllama-quantize --imatrix $IMATRIX $MODEL $OUTPUT $QUANT\n    echo \"Created: $OUTPUT ($(du -h $OUTPUT | cut -f1))\"\ndone\n```\n\n## Python usage\n\n### llama-cpp-python\n\n```python\nfrom llama_cpp import Llama\n\n# Load model\nllm = Llama(\n    model_path=\".\u002Fmodel-q4_k_m.gguf\",\n    n_ctx=4096,          # Context window\n    n_gpu_layers=35,     # GPU offload (0 for CPU only)\n    n_threads=8          # CPU threads\n)\n\n# Generate\noutput = llm(\n    \"What is machine learning?\",\n    max_tokens=256,\n    temperature=0.7,\n    stop=[\"\u003C\u002Fs>\", \"\\n\\n\"]\n)\nprint(output[\"choices\"][0][\"text\"])\n```\n\n### Chat completion\n\n```python\nfrom llama_cpp import Llama\n\nllm = Llama(\n    model_path=\".\u002Fmodel-q4_k_m.gguf\",\n    n_ctx=4096,\n    n_gpu_layers=35,\n    chat_format=\"llama-3\"  # Or \"chatml\", \"mistral\", etc.\n)\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"What is Python?\"}\n]\n\nresponse = llm.create_chat_completion(\n    messages=messages,\n    max_tokens=256,\n    temperature=0.7\n)\nprint(response[\"choices\"][0][\"message\"][\"content\"])\n```\n\n### Streaming\n\n```python\nfrom llama_cpp import Llama\n\nllm = Llama(model_path=\".\u002Fmodel-q4_k_m.gguf\", n_gpu_layers=35)\n\n# Stream tokens\nfor chunk in llm(\n    \"Explain quantum computing:\",\n    max_tokens=256,\n    stream=True\n):\n    print(chunk[\"choices\"][0][\"text\"], end=\"\", flush=True)\n```\n\n## Server mode\n\n### Start OpenAI-compatible server\n\n```bash\n# Start server\n.\u002Fllama-server -m model-q4_k_m.gguf \\\n    --host 0.0.0.0 \\\n    --port 8080 \\\n    -ngl 35 \\\n    -c 4096\n\n# Or with Python bindings\npython -m llama_cpp.server \\\n    --model model-q4_k_m.gguf \\\n    --n_gpu_layers 35 \\\n    --host 0.0.0.0 \\\n    --port 8080\n```\n\n### Use with OpenAI client\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"http:\u002F\u002Flocalhost:8080\u002Fv1\",\n    api_key=\"not-needed\"\n)\n\nresponse = client.chat.completions.create(\n    model=\"local-model\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n    max_tokens=256\n)\nprint(response.choices[0].message.content)\n```\n\n## Hardware optimization\n\n### Apple Silicon (Metal)\n\n```bash\n# Build with Metal\nmake clean && make GGML_METAL=1\n\n# Run with Metal acceleration\n.\u002Fllama-cli -m model.gguf -ngl 99 -p \"Hello\"\n\n# Python with Metal\nllm = Llama(\n    model_path=\"model.gguf\",\n    n_gpu_layers=99,     # Offload all layers\n    n_threads=1          # Metal handles parallelism\n)\n```\n\n### NVIDIA CUDA\n\n```bash\n# Build with CUDA\nmake clean && make GGML_CUDA=1\n\n# Run with CUDA\n.\u002Fllama-cli -m model.gguf -ngl 35 -p \"Hello\"\n\n# Specify GPU\nCUDA_VISIBLE_DEVICES=0 .\u002Fllama-cli -m model.gguf -ngl 35\n```\n\n### CPU optimization\n\n```bash\n# Build with AVX2\u002FAVX512\nmake clean && make\n\n# Run with optimal threads\n.\u002Fllama-cli -m model.gguf -t 8 -p \"Hello\"\n\n# Python CPU config\nllm = Llama(\n    model_path=\"model.gguf\",\n    n_gpu_layers=0,      # CPU only\n    n_threads=8,         # Match physical cores\n    n_batch=512          # Batch size for prompt processing\n)\n```\n\n## Integration with tools\n\n### Ollama\n\n```bash\n# Create Modelfile\ncat > Modelfile \u003C\u003C 'EOF'\nFROM .\u002Fmodel-q4_k_m.gguf\nTEMPLATE \"\"\"{{ .System }}\n{{ .Prompt }}\"\"\"\nPARAMETER temperature 0.7\nPARAMETER num_ctx 4096\nEOF\n\n# Create Ollama model\nollama create mymodel -f Modelfile\n\n# Run\nollama run mymodel \"Hello!\"\n```\n\n### LM Studio\n\n1. Place GGUF file in `~\u002F.cache\u002Flm-studio\u002Fmodels\u002F`\n2. Open LM Studio and select the model\n3. Configure context length and GPU offload\n4. Start inference\n\n### text-generation-webui\n\n```bash\n# Place in models folder\ncp model-q4_k_m.gguf text-generation-webui\u002Fmodels\u002F\n\n# Start with llama.cpp loader\npython server.py --model model-q4_k_m.gguf --loader llama.cpp --n-gpu-layers 35\n```\n\n## Best practices\n\n1. **Use K-quants**: Q4_K_M offers best quality\u002Fsize balance\n2. **Use imatrix**: Always use importance matrix for Q4 and below\n3. **GPU offload**: Offload as many layers as VRAM allows\n4. **Context length**: Start with 4096, increase if needed\n5. **Thread count**: Match physical CPU cores, not logical\n6. **Batch size**: Increase n_batch for faster prompt processing\n\n## Common issues\n\n**Model loads slowly:**\n```bash\n# Use mmap for faster loading\n.\u002Fllama-cli -m model.gguf --mmap\n```\n\n**Out of memory:**\n```bash\n# Reduce GPU layers\n.\u002Fllama-cli -m model.gguf -ngl 20  # Reduce from 35\n\n# Or use smaller quantization\n.\u002Fllama-quantize model-f16.gguf model-q3_k_m.gguf Q3_K_M\n```\n\n**Poor quality at low bits:**\n```bash\n# Always use imatrix for Q4 and below\n.\u002Fllama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix\n.\u002Fllama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M\n```\n\n## References\n\n- **[Advanced Usage](references\u002Fadvanced-usage.md)** - Batching, speculative decoding, custom builds\n- **[Troubleshooting](references\u002Ftroubleshooting.md)** - Common issues, debugging, benchmarks\n\n## Resources\n\n- **Repository**: https:\u002F\u002Fgithub.com\u002Fggml-org\u002Fllama.cpp\n- **Python Bindings**: https:\u002F\u002Fgithub.com\u002Fabetlen\u002Fllama-cpp-python\n- **Pre-quantized Models**: https:\u002F\u002Fhuggingface.co\u002FTheBloke\n- **GGUF Converter**: https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fggml-org\u002Fgguf-my-repo\n- **License**: MIT\n","# GGUF - Quantization Format for llama.cpp\n\nThe 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.\n\n## When to use GGUF\n\n**Use GGUF when:**\n- Deploying on consumer hardware (laptops, desktops)\n- Running on Apple Silicon (M1\u002FM2\u002FM3) with Metal acceleration\n- Need CPU inference without GPU requirements\n- Want flexible quantization (Q2_K to Q8_0)\n- Using local AI tools (LM Studio, Ollama, text-generation-webui)\n\n**Key advantages:**\n- **Universal hardware**: CPU, Apple Silicon, NVIDIA, AMD support\n- **No Python runtime**: Pure C\u002FC++ inference\n- **Flexible quantization**: 2-8 bit with various methods (K-quants)\n- **Ecosystem support**: LM Studio, Ollama, koboldcpp, and more\n- **imatrix**: Importance matrix for better low-bit quality\n\n**Use alternatives instead:**\n- **AWQ\u002FGPTQ**: Maximum accuracy with calibration on NVIDIA GPUs\n- **HQQ**: Fast calibration-free quantization for HuggingFace\n- **bitsandbytes**: Simple integration with transformers library\n- **TensorRT-LLM**: Production NVIDIA deployment with maximum speed\n\n## Quick start\n\n### Installation\n\n```bash\n# Clone llama.cpp\ngit clone https:\u002F\u002Fgithub.com\u002Fggml-org\u002Fllama.cpp\ncd llama.cpp\n\n# Build (CPU)\nmake\n\n# Build with CUDA (NVIDIA)\nmake GGML_CUDA=1\n\n# Build with Metal (Apple Silicon)\nmake GGML_METAL=1\n\n# Install Python bindings (optional)\npip install llama-cpp-python\n```\n\n### Convert model to GGUF\n\n```bash\n# Install requirements\npip install -r requirements.txt\n\n# Convert HuggingFace model to GGUF (FP16)\npython convert_hf_to_gguf.py .\u002Fpath\u002Fto\u002Fmodel --outfile model-f16.gguf\n\n# Or specify output type\npython convert_hf_to_gguf.py .\u002Fpath\u002Fto\u002Fmodel \\\n    --outfile model-f16.gguf \\\n    --outtype f16\n```\n\n### Quantize model\n\n```bash\n# Basic quantization to Q4_K_M\n.\u002Fllama-quantize model-f16.gguf model-q4_k_m.gguf Q4_K_M\n\n# Quantize with importance matrix (better quality)\n.\u002Fllama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix\n.\u002Fllama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M\n```\n\n### Run inference\n\n```bash\n# CLI inference\n.\u002Fllama-cli -m model-q4_k_m.gguf -p \"Hello, how are you?\"\n\n# Interactive mode\n.\u002Fllama-cli -m model-q4_k_m.gguf --interactive\n\n# With GPU offload\n.\u002Fllama-cli -m model-q4_k_m.gguf -ngl 35 -p \"Hello!\"\n```\n\n## Quantization types\n\n### K-quant methods (recommended)\n\n| Type | Bits | Size (7B) | Quality | Use Case |\n|------|------|-----------|---------|----------|\n| Q2_K | 2.5 | ~2.8 GB | Low | Extreme compression |\n| Q3_K_S | 3.0 | ~3.0 GB | Low-Med | Memory constrained |\n| Q3_K_M | 3.3 | ~3.3 GB | Medium | Balance |\n| Q4_K_S | 4.0 | ~3.8 GB | Med-High | Good balance |\n| Q4_K_M | 4.5 | ~4.1 GB | High | **Recommended default** |\n| Q5_K_S | 5.0 | ~4.6 GB | High | Quality focused |\n| Q5_K_M | 5.5 | ~4.8 GB | Very High | High quality |\n| Q6_K | 6.0 | ~5.5 GB | Excellent | Near-original |\n| Q8_0 | 8.0 | ~7.2 GB | Best | Maximum quality |\n\n### Legacy methods\n\n| Type | Description |\n|------|-------------|\n| Q4_0 | 4-bit, basic |\n| Q4_1 | 4-bit with delta |\n| Q5_0 | 5-bit, basic |\n| Q5_1 | 5-bit with delta |\n\n**Recommendation**: Use K-quant methods (Q4_K_M, Q5_K_M) for best quality\u002Fsize ratio.\n\n## Conversion workflows\n\n### Workflow 1: HuggingFace to GGUF\n\n```bash\n# 1. Download model\nhuggingface-cli download meta-llama\u002FLlama-3.1-8B --local-dir .\u002Fllama-3.1-8b\n\n# 2. Convert to GGUF (FP16)\npython convert_hf_to_gguf.py .\u002Fllama-3.1-8b \\\n    --outfile llama-3.1-8b-f16.gguf \\\n    --outtype f16\n\n# 3. Quantize\n.\u002Fllama-quantize llama-3.1-8b-f16.gguf llama-3.1-8b-q4_k_m.gguf Q4_K_M\n\n# 4. Test\n.\u002Fllama-cli -m llama-3.1-8b-q4_k_m.gguf -p \"Hello!\" -n 50\n```\n\n### Workflow 2: With importance matrix (better quality)\n\n```bash\n# 1. Convert to GGUF\npython convert_hf_to_gguf.py .\u002Fmodel --outfile model-f16.gguf\n\n# 2. Create calibration text (diverse samples)\ncat > calibration.txt \u003C\u003C 'EOF'\nThe quick brown fox jumps over the lazy dog.\nMachine learning is a subset of artificial intelligence.\nPython is a popular programming language.\n# Add more diverse text samples...\nEOF\n\n# 3. Generate importance matrix\n.\u002Fllama-imatrix -m model-f16.gguf \\\n    -f calibration.txt \\\n    --chunk 512 \\\n    -o model.imatrix \\\n    -ngl 35  # GPU layers if available\n\n# 4. Quantize with imatrix\n.\u002Fllama-quantize --imatrix model.imatrix \\\n    model-f16.gguf \\\n    model-q4_k_m.gguf \\\n    Q4_K_M\n```\n\n### Workflow 3: Multiple quantizations\n\n```bash\n#!\u002Fbin\u002Fbash\nMODEL=\"llama-3.1-8b-f16.gguf\"\nIMATRIX=\"llama-3.1-8b.imatrix\"\n\n# Generate imatrix once\n.\u002Fllama-imatrix -m $MODEL -f wiki.txt -o $IMATRIX -ngl 35\n\n# Create multiple quantizations\nfor QUANT in Q4_K_M Q5_K_M Q6_K Q8_0; do\n    OUTPUT=\"llama-3.1-8b-${QUANT,,}.gguf\"\n    .\u002Fllama-quantize --imatrix $IMATRIX $MODEL $OUTPUT $QUANT\n    echo \"Created: $OUTPUT ($(du -h $OUTPUT | cut -f1))\"\ndone\n```\n\n## Python usage\n\n### llama-cpp-python\n\n```python\nfrom llama_cpp import Llama\n\n# Load model\nllm = Llama(\n    model_path=\".\u002Fmodel-q4_k_m.gguf\",\n    n_ctx=4096,          # Context window\n    n_gpu_layers=35,     # GPU offload (0 for CPU only)\n    n_threads=8          # CPU threads\n)\n\n# Generate\noutput = llm(\n    \"What is machine learning?\",\n    max_tokens=256,\n    temperature=0.7,\n    stop=[\"\u003C\u002Fs>\", \"\\n\\n\"]\n)\nprint(output[\"choices\"][0][\"text\"])\n```\n\n### Chat completion\n\n```python\nfrom llama_cpp import Llama\n\nllm = Llama(\n    model_path=\".\u002Fmodel-q4_k_m.gguf\",\n    n_ctx=4096,\n    n_gpu_layers=35,\n    chat_format=\"llama-3\"  # Or \"chatml\", \"mistral\", etc.\n)\n\nmessages = [\n    {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n    {\"role\": \"user\", \"content\": \"What is Python?\"}\n]\n\nresponse = llm.create_chat_completion(\n    messages=messages,\n    max_tokens=256,\n    temperature=0.7\n)\nprint(response[\"choices\"][0][\"message\"][\"content\"])\n```\n\n### Streaming\n\n```python\nfrom llama_cpp import Llama\n\nllm = Llama(model_path=\".\u002Fmodel-q4_k_m.gguf\", n_gpu_layers=35)\n\n# Stream tokens\nfor chunk in llm(\n    \"Explain quantum computing:\",\n    max_tokens=256,\n    stream=True\n):\n    print(chunk[\"choices\"][0][\"text\"], end=\"\", flush=True)\n```\n\n## Server mode\n\n### Start OpenAI-compatible server\n\n```bash\n# Start server\n.\u002Fllama-server -m model-q4_k_m.gguf \\\n    --host 0.0.0.0 \\\n    --port 8080 \\\n    -ngl 35 \\\n    -c 4096\n\n# Or with Python bindings\npython -m llama_cpp.server \\\n    --model model-q4_k_m.gguf \\\n    --n_gpu_layers 35 \\\n    --host 0.0.0.0 \\\n    --port 8080\n```\n\n### Use with OpenAI client\n\n```python\nfrom openai import OpenAI\n\nclient = OpenAI(\n    base_url=\"http:\u002F\u002Flocalhost:8080\u002Fv1\",\n    api_key=\"not-needed\"\n)\n\nresponse = client.chat.completions.create(\n    model=\"local-model\",\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n    max_tokens=256\n)\nprint(response.choices[0].message.content)\n```\n\n## Hardware optimization\n\n### Apple Silicon (Metal)\n\n```bash\n# Build with Metal\nmake clean && make GGML_METAL=1\n\n# Run with Metal acceleration\n.\u002Fllama-cli -m model.gguf -ngl 99 -p \"Hello\"\n\n# Python with Metal\nllm = Llama(\n    model_path=\"model.gguf\",\n    n_gpu_layers=99,     # Offload all layers\n    n_threads=1          # Metal handles parallelism\n)\n```\n\n### NVIDIA CUDA\n\n```bash\n# Build with CUDA\nmake clean && make GGML_CUDA=1\n\n# Run with CUDA\n.\u002Fllama-cli -m model.gguf -ngl 35 -p \"Hello\"\n\n# Specify GPU\nCUDA_VISIBLE_DEVICES=0 .\u002Fllama-cli -m model.gguf -ngl 35\n```\n\n### CPU optimization\n\n```bash\n# Build with AVX2\u002FAVX512\nmake clean && make\n\n# Run with optimal threads\n.\u002Fllama-cli -m model.gguf -t 8 -p \"Hello\"\n\n# Python CPU config\nllm = Llama(\n    model_path=\"model.gguf\",\n    n_gpu_layers=0,      # CPU only\n    n_threads=8,         # Match physical cores\n    n_batch=512          # Batch size for prompt processing\n)\n```\n\n## Integration with tools\n\n### Ollama\n\n```bash\n# Create Modelfile\ncat > Modelfile \u003C\u003C 'EOF'\nFROM .\u002Fmodel-q4_k_m.gguf\nTEMPLATE \"\"\"{{ .System }}\n{{ .Prompt }}\"\"\"\nPARAMETER temperature 0.7\nPARAMETER num_ctx 4096\nEOF\n\n# Create Ollama model\nollama create mymodel -f Modelfile\n\n# Run\nollama run mymodel \"Hello!\"\n```\n\n### LM Studio\n\n1. Place GGUF file in `~\u002F.cache\u002Flm-studio\u002Fmodels\u002F`\n2. Open LM Studio and select the model\n3. Configure context length and GPU offload\n4. Start inference\n\n### text-generation-webui\n\n```bash\n# Place in models folder\ncp model-q4_k_m.gguf text-generation-webui\u002Fmodels\u002F\n\n# Start with llama.cpp loader\npython server.py --model model-q4_k_m.gguf --loader llama.cpp --n-gpu-layers 35\n```\n\n## Best practices\n\n1. **Use K-quants**: Q4_K_M offers best quality\u002Fsize balance\n2. **Use imatrix**: Always use importance matrix for Q4 and below\n3. **GPU offload**: Offload as many layers as VRAM allows\n4. **Context length**: Start with 4096, increase if needed\n5. **Thread count**: Match physical CPU cores, not logical\n6. **Batch size**: Increase n_batch for faster prompt processing\n\n## Common issues\n\n**Model loads slowly:**\n```bash\n# Use mmap for faster loading\n.\u002Fllama-cli -m model.gguf --mmap\n```\n\n**Out of memory:**\n```bash\n# Reduce GPU layers\n.\u002Fllama-cli -m model.gguf -ngl 20  # Reduce from 35\n\n# Or use smaller quantization\n.\u002Fllama-quantize model-f16.gguf model-q3_k_m.gguf Q3_K_M\n```\n\n**Poor quality at low bits:**\n```bash\n# Always use imatrix for Q4 and below\n.\u002Fllama-imatrix -m model-f16.gguf -f calibration.txt -o model.imatrix\n.\u002Fllama-quantize --imatrix model.imatrix model-f16.gguf model-q4_k_m.gguf Q4_K_M\n```\n\n## References\n\n- **[Advanced Usage](references\u002Fadvanced-usage.md)** - Batching, speculative decoding, custom builds\n- **[Troubleshooting](references\u002Ftroubleshooting.md)** - Common issues, debugging, benchmarks\n\n## Resources\n\n- **Repository**: https:\u002F\u002Fgithub.com\u002Fggml-org\u002Fllama.cpp\n- **Python Bindings**: https:\u002F\u002Fgithub.com\u002Fabetlen\u002Fllama-cpp-python\n- **Pre-quantized Models**: https:\u002F\u002Fhuggingface.co\u002FTheBloke\n- **GGUF Converter**: https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fggml-org\u002Fgguf-my-repo\n- **License**: MIT\n",{"name":5,"author":43,"license":14,"version":44,"metadata":45,"description":7,"dependencies":49},"Orchestra Research","1.0.0",{"hermes":46},{"tags":47},[20,18,30,29,48,28,25],"Apple Silicon",[50],"llama-cpp-python>=0.2.0","main","6746276ba18cb774853eb61b3b9399658bc9bc5c","core\u002Fhermes_sovereign_data\u002Fskills\u002Fmlops\u002Finference\u002Fgguf","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch","2026-04-28 17:01:03",{"source":8,"skillName":5,"commands":58,"prompt":68,"zipAvailable":69},[59,62,65],{"tool":60,"command":61},"npx","npx skills add gjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN --skill gguf-quantization",{"tool":63,"command":64},"bunx","bunx skills add gjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN --skill gguf-quantization",{"tool":66,"command":67},"pnpm","pnpm dlx skills add gjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN --skill gguf-quantization","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fhermes_sovereign_data\u002Fskills\u002Fmlops\u002Finference\u002Fgguf\u002FSKILL.md",true,[71,77],{"path":72,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fadvanced-usage.md","REFERENCE","参考文档",10887,"https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fhermes_sovereign_data\u002Fskills\u002Fmlops\u002Finference\u002Fgguf\u002Freferences\u002Fadvanced-usage.md",{"path":78,"resourceType":73,"resourceTypeDesc":74,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Ftroubleshooting.md",8904,"https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fhermes_sovereign_data\u002Fskills\u002Fmlops\u002Finference\u002Fgguf\u002Freferences\u002Ftroubleshooting.md",[82,125,150,167,186,205],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":104,"publishedAt":38},"01M71QG27G1R2H2ZWEG4S0WTZT","writing-plans","Write implementation plans: bite-sized tasks, paths, code.","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Fwriting-plans\u002FSKILL.md",[88,93,96,101],{"categoryNo":89,"categoryName":90,"taxonomyType":91,"taxonomyTypeDesc":92},"01JBSEEDCAT000000000000015","视觉设计","SCENARIO","使用场景",{"categoryNo":94,"categoryName":95,"taxonomyType":91,"taxonomyTypeDesc":92},"01JBSEEDCAT000000000000018","写作与文案",{"categoryNo":97,"categoryName":98,"taxonomyType":99,"taxonomyTypeDesc":100},"01JBSEEDCAT000000000000030","开发工程师","PROFESSION","适用职业",{"categoryNo":102,"categoryName":103,"taxonomyType":99,"taxonomyTypeDesc":100},"01JBSEEDCAT000000000000036","内容创作者",[105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124],"writing","writing plans","plans","test-driven","test-driven-development","superpowers","design","workflow","code","tasks","subagent","code-review","review","documentation","write","paths","planning","development","test","implementation",{"skillNo":126,"name":109,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":136,"publishedAt":38},"01M71QFZYRTJXMAE551MRAKZ14","TDD: enforce RED-GREEN-REFACTOR, tests before code.","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Ftest-driven-development\u002FSKILL.md",[130,133],{"categoryNo":131,"categoryName":132,"taxonomyType":91,"taxonomyTypeDesc":92},"01JBSEEDCAT000000000000007","代码审查",{"categoryNo":134,"categoryName":135,"taxonomyType":91,"taxonomyTypeDesc":92},"01JBSEEDCAT000000000000008","测试与质量",[137,122,123,138,139,140,141,110,105,142,113,115,143,144,145,146,147,107,148,149],"test driven development","driven","green","red-green-refactor","testing","debugging","systematic","refactor","systematic-debugging","enforce","tests","tdd","quality",{"skillNo":151,"name":145,"nameZh":6,"description":152,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":153,"categories":154,"keywords":156,"publishedAt":38},"01M71QFWR5Q8EYEQ6MCS3SM6MC","4-phase root cause debugging: understand bugs before fixing.","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Fsystematic-debugging\u002FSKILL.md",[155],{"categoryNo":134,"categoryName":135,"taxonomyType":91,"taxonomyTypeDesc":92},[157,142,143,108,158,159,109,110,105,115,160,161,122,162,107,163,123,164,165,166],"systematic debugging","problem","problem-solving","phase","bugs","root cause","root-cause","investigation","understand","hermes",{"skillNo":168,"name":169,"nameZh":6,"description":170,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":171,"categories":172,"keywords":178,"publishedAt":38},"01M71QFS9S04MD8JP747W5WM0N","subagent-driven-development","Execute plans via delegate_task subagents (2-stage review).","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Fsubagent-driven-development\u002FSKILL.md",[173,174,177],{"categoryNo":94,"categoryName":95,"taxonomyType":91,"taxonomyTypeDesc":92},{"categoryNo":175,"categoryName":176,"taxonomyType":91,"taxonomyTypeDesc":92},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":102,"categoryName":103,"taxonomyType":99,"taxonomyTypeDesc":100},[179,115,122,138,108,109,180,181,110,105,112,113,116,117,182,183,107,184,185,123],"subagent driven development","delegate","delegation","subagents","parallel","stage","task",{"skillNo":187,"name":188,"nameZh":6,"description":189,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":190,"categories":191,"keywords":194,"publishedAt":38},"01M71QFQ1DBCVAZ511MXFE6T2V","requesting-code-review","Pre-commit review: security scan, quality gates, auto-fix.","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Frequesting-code-review\u002FSKILL.md",[192,193],{"categoryNo":131,"categoryName":132,"taxonomyType":91,"taxonomyTypeDesc":92},{"categoryNo":97,"categoryName":98,"taxonomyType":99,"taxonomyTypeDesc":100},[195,196,113,117,108,109,197,198,110,199,105,200,201,115,116,202,203,122,204,107],"code review","requesting code review","fix","auto-fix","auto","security scan","commit","verification","security","scan",{"skillNo":206,"name":207,"nameZh":6,"description":208,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":209,"categories":210,"keywords":212,"publishedAt":38},"01M71QFM7KWM540YR67FRN807Q","python-debugpy","Debug Python: pdb REPL + debugpy remote (DAP).","https:\u002F\u002Fgithub.com\u002Fgjbvsjjvgm-sketch\u002FWORM_V2_SOVEREIGN\u002Fblob\u002Fmain\u002Fcore\u002Fskills\u002Fsoftware-development\u002Fpython-debugpy\u002FSKILL.md",[211],{"categoryNo":97,"categoryName":98,"taxonomyType":99,"taxonomyTypeDesc":100},[213,214,24,215,216,217,218,219,142,143,220,221,222,145,223,224,225,226,166,227],"debugpy","python debugpy","dap","inspect","post-mortem","pdb","remote","debugger","node","commands","debug","post","breakpoints","node-inspect","tui"]