Skip to content

artubss/SKILLS-CLAUDE-CODE / skills/skills/ai-research/inference-serving-llama-cpp

llama-cpp

Unverified

Executa inferência de LLM em CPU, Apple Silicon e GPUs consumer sem hardware NVIDIA. Use para edge deployment, Macs M1/M2/M3, GPUs AMD/Intel ou quando CUDA não está disponível. Suporta quantização GGUF (1,5-8 bits) para redução de memória e aceleração de 4-10× vs PyTorch em CPU.

llama.cpp

Inferência de LLM pura em C/C++ com dependências mínimas, otimizada para CPUs e hardware não-NVIDIA.

Quando usar llama.cpp

Use llama.cpp quando:

  • Executar em máquinas apenas com CPU
  • Fazer deploy em Apple Silicon (M1/M2/M3/M4)
  • Usar GPUs AMD ou Intel (sem CUDA)
  • Edge deployment (Raspberry Pi, sistemas embarcados)
  • Precisar de deploy simples sem Docker/Python

Use TensorRT-LLM quando:

  • Tiver GPUs NVIDIA (A100/H100)
  • Precisar de throughput máximo (100K+ tok/s)
  • Rodando em datacenter com CUDA

Use vLLM quando:

  • Tiver GPUs NVIDIA
  • Precisar de API Python-first
  • Quiser PagedAttention

Guia rápido

Instalação

# macOS/Linux
brew install llama.cpp

# Ou compilar do source
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make

# Com Metal (Apple Silicon)
make LLAMA_METAL=1

# Com CUDA (NVIDIA)
make LLAMA_CUDA=1

# Com ROCm (AMD)
make LLAMA_HIP=1

Baixar modelo

# Baixar do HuggingFace (formato GGUF)
huggingface-cli download \
    TheBloke/Llama-2-7B-Chat-GGUF \
    llama-2-7b-chat.Q4_K_M.gguf \
    --local-dir models/

# Ou converter do HuggingFace
python convert_hf_to_gguf.py models/llama-2-7b-chat/

Executar inferência

# Chat simples
./llama-cli \
    -m models/llama-2-7b-chat.Q4_K_M.gguf \
    -p "Explain quantum computing" \
    -n 256  # Max tokens

# Chat interativo
./llama-cli \
    -m models/llama-2-7b-chat.Q4_K_M.gguf \
    --interactive

Modo server

# Iniciar servidor compatível com OpenAI
./llama-server \
    -m models/llama-2-7b-chat.Q4_K_M.gguf \
    --host 0.0.0.0 \
    --port 8080 \
    -ngl 32  # Offload 32 layers to GPU

# Requisição do cliente
curl http://localhost:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama-2-7b-chat",
    "messages": [{"role": "user", "content": "Hello!"}],
    "temperature": 0.7,
    "max_tokens": 100
  }'

Formatos de quantização

Visão geral do formato GGUF

FormatoBitsTamanho (7B)VelocidadeQualidadeCaso de Uso
Q4_K_M4,54,1 GBRápidoBomPadrão recomendado
Q4_K_S4,33,9 GBMais rápidoMenorCrítico em velocidade
Q5_K_M5,54,8 GBMédioMelhorCrítico em qualidade
Q6_K6,55,5 GBMais lentoMelhorQualidade máxima
Q8_08,07,0 GBLentoExcelenteDegradação mínima
Q2_K2,52,7 GBMais rápidoPobreApenas testes

Escolhendo quantização

# Uso geral (equilibrado)
Q4_K_M  # 4-bit, qualidade média

# Velocidade máxima (mais degradação)
Q2_K or Q3_K_M

# Qualidade máxima (mais lento)
Q6_K or Q8_0

# Modelos muito grandes (70B, 405B)
Q3_K_M or Q4_K_S  # Bits menores para caber na memória

Aceleração de hardware

Apple Silicon (Metal)

# Compilar com Metal
make LLAMA_METAL=1

# Executar com aceleração GPU (automático)
./llama-cli -m model.gguf -ngl 999  # Offload all layers

# Performance: M3 Max 40-60 tokens/sec (Llama 2-7B Q4_K_M)

GPUs NVIDIA (CUDA)

# Compilar com CUDA
make LLAMA_CUDA=1

# Offload layers para GPU
./llama-cli -m model.gguf -ngl 35  # Offload 35/40 layers

# Híbrido CPU+GPU para modelos grandes
./llama-cli -m llama-70b.Q4_K_M.gguf -ngl 20  # GPU: 20 layers, CPU: rest

GPUs AMD (ROCm)

# Compilar com ROCm
make LLAMA_HIP=1

# Executar com GPU AMD
./llama-cli -m model.gguf -ngl 999

Padrões comuns

Processamento em lote

# Processar múltiplos prompts de arquivo
cat prompts.txt | ./llama-cli \
    -m model.gguf \
    --batch-size 512 \
    -n 100

Geração restrita

# Saída JSON com grammar
./llama-cli \
    -m model.gguf \
    -p "Generate a person: " \
    --grammar-file grammars/json.gbnf

# Outputs valid JSON only

Tamanho de contexto

# Aumentar contexto (padrão 512)
./llama-cli \
    -m model.gguf \
    -c 4096  # 4K context window

# Contexto muito longo (se modelo suportar)
./llama-cli -m model.gguf -c 32768  # 32K context

Benchmarks de performance

Performance em CPU (Llama 2-7B Q4_K_M)

CPUThreadsVelocidadeCusto
Apple M3 Max1650 tok/sR$ 0 (local)
AMD Ryzen 9 7950X3235 tok/sR$ 0,50/hora
Intel i9-13900K3230 tok/sR$ 0,40/hora
AWS c7i.16xlarge6440 tok/sR$ 2,88/hora

Aceleração por GPU (Llama 2-7B Q4_K_M)

GPUVelocidadevs CPUCusto
NVIDIA RTX 4090120 tok/s3-4×R$ 0 (local)
NVIDIA A1080 tok/s2-3×R$ 1,00/hora
AMD MI25070 tok/s2×R$ 2,00/hora
Apple M3 Max (Metal)50 tok/s~MesmoR$ 0 (local)

Modelos suportados

Família LLaMA:

  • Llama 2 (7B, 13B, 70B)
  • Llama 3 (8B, 70B, 405B)
  • Code Llama

Família Mistral:

  • Mistral 7B
  • Mixtral 8x7B, 8x22B

Outros:

  • Falcon, BLOOM, GPT-J
  • Phi-3, Gemma, Qwen
  • LLaVA (vision), Whisper (audio)

Encontrar modelos: https://huggingface.co/models?library=gguf

Referências

Recursos

writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deploymentStars: 318kUpdated Claude CodeCodexUnverifiedInstall
xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release.Stars: 117kUpdated Claude CodeCodexUnverifiedInstall