Capítulo 1: Gestión de GPU/TPU
Guía de selección de GPU
| Tipo de GPU | VRAM | Caso de uso | Costo ($/hr) |
|---|---|---|---|
| NVIDIA T4 | 16GB | Inferencia, entrenamiento pequeño | $0.35 |
| NVIDIA V100 | 32GB | Entrenamiento mediano | $2.50 |
| NVIDIA A100 | 80GB | Entrenamiento de modelos grandes | $4.00 |
| NVIDIA H100 | 80GB | Entrenamiento de LLM | $8.00+ |
Optimización de memoria de GPU
import torch
# Enable gradient checkpointing
model.gradient_checkpointing_enable()
# Mixed precision training
from torch.cuda.amp import autocast, GradScaler
scaler = GradScaler()
with autocast():
outputs = model(inputs)
loss = criterion(outputs, targets)
scaler.scale(loss).backward()
scaler.step(optimizer)
scaler.update()
# Memory-efficient attention
from torch.nn.functional import scaled_dot_product_attention
# Uses Flash Attention when available
Puntos clave
Summary
- Asocie la GPU con la carga de trabajo: no sobreprovisione
- Utilice precisión mixta para duplicar la velocidad y ahorrar memoria
- Monitoree la utilización de la GPU para identificar cuellos de botella
- Considere instancias spot para ahorrar entre 60-90% en costos
Siguiente: Capítulo 2: Entrenamiento distribuido