Capítulo 3: Treinamento em Nuvem (AWS, GCP, Azure)
Comparação de Plataformas
| Recurso | AWS SageMaker | GCP Vertex AI | Azure ML |
|---|---|---|---|
| Notebooks | ✅ | ✅ | ✅ |
| AutoML | ✅ | ✅ | ✅ |
| Pipelines | ✅ | ✅ | ✅ |
| Spot/Preemptible | ✅ | ✅ | ✅ |
| Integração com MLflow | ✅ | ✅ | ✅ |
Exemplo AWS SageMaker
import sagemaker
from sagemaker.pytorch import PyTorch
estimator = PyTorch(
entry_point='train.py',
source_dir='src/',
role=sagemaker.get_execution_role(),
instance_count=2,
instance_type='ml.p3.2xlarge',
framework_version='2.0',
py_version='py310',
hyperparameters={
'epochs': 10,
'batch-size': 32,
'learning-rate': 0.001
},
use_spot_instances=True,
max_wait=3600, # Max wait time for spot
checkpoint_s3_uri='s3://bucket/checkpoints/'
)
estimator.fit({'training': 's3://bucket/data/train/'})
Dicas de Otimização de Custos
- Use instâncias spot/preemptible – economia de 60-90%
- Dimensione corretamente as instâncias – Não superprovisione
- Desligue notebooks automaticamente – Evite cobranças por ociosidade
- Utilize checkpointing – Retome treinamentos interrompidos
Próximo: Quiz do Módulo 5