Capítulo 3: Servicio a Escala
vLLM
Servicio de alto rendimiento con 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 producción de Hugging Face:
docker run --gpus all -p 8080:80 \
ghcr.io/huggingface/text-generation-inference:latest \
--model-id meta-llama/Llama-2-7b-hf
Comparación
| Framework | Mejor Para | Característica Clave |
|---|---|---|
| vLLM | Rendimiento | PagedAttention |
| TGI | Producción | Integración con HF |
| Triton | Multi-modelo | Optimizado por NVIDIA |
Balanceo de Carga
# Ejemplo: Despliegue en Kubernetes
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3 # Múltiples réplicas para balanceo de carga
template:
spec:
containers:
- name: llm-server
resources:
limits:
nvidia.com/gpu: 1