Capítulo 3: Servindo em Escala
vLLM
Serviço de alta vazão com PagedAttention:
from vllm import LLM, SamplingParams
llm = LLM(model="meta-llama/Llama-2-7b-hf")
sampling_params = SamplingParams(temperature=0.7, max_tokens=256)
outputs = llm.generate(["Hello, my name is"], sampling_params)
Text Generation Inference (TGI)
Servidor de produção da Hugging Face:
docker run --gpus all -p 8080:80 \
ghcr.io/huggingface/text-generation-inference:latest \
--model-id meta-llama/Llama-2-7b-hf
Comparação
| Framework | Melhor Para | Principal Característica |
|---|---|---|
| vLLM | Vazão | PagedAttention |
| TGI | Produção | Integração com HF |
| Triton | Multi-modelo | Otimizado pela NVIDIA |
Balanceamento de Carga
# Exemplo: deployment no Kubernetes
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3 # Múltiplas réplicas para balanceamento de carga
template:
spec:
containers:
- name: llm-server
resources:
limits:
nvidia.com/gpu: 1