11.1 Choosing CPUs, GPUs & TPUs for Training
Key Takeaways
- Google recommends CPUs for quick prototyping, simple models, and models with many custom C++ operations or I/O limits.
- GPUs suit medium-to-large models with larger batch sizes and models with many custom PyTorch or JAX operations that must partly run on CPUs.
- TPUs suit large matrix-heavy models with large batches, weeks-long training, and ultra-large embeddings, but not models with custom operations in the main training loop.
- Code that runs on TPUs is compiled by the XLA compiler, and TPU v6e no longer supports TensorFlow.
- Agent Platform serverless training supports NVIDIA GPUs from T4 and L4 through A100, H100, H200, B200, and GB200, plus TPU VMs.
Section 3.3 of the exam guide begins with evaluating compute and accelerator options (for example, CPU, GPU, and TPU). The right answer depends on model type, framework, custom operations, model and batch size, and how long training runs.
Google's Guidance: CPU vs. GPU vs. TPU
| Hardware | Best for | Not ideal for |
|---|---|---|
| CPU | Quick prototyping. Simple models that train fast. Small models with small batches. Models with many custom C++ operations. Workloads limited by I/O or host networking. Classical ML (scikit-learn, many XGBoost jobs) | Large deep networks |
| GPU | Medium-to-large deep learning models with larger batches. Models with many custom PyTorch or JAX operations that must run at least partly on CPUs. TensorFlow ops not available on TPUs | Tiny models, where host overhead dominates and GPUs sit idle |
| TPU | Models dominated by matrix computations. No custom operations inside the main training loop. Training that runs weeks or months. Large models with large batches. Ultra-large embeddings in ranking and recommendation | Frequent branching, many element-wise operations, high-precision arithmetic, custom ops in the training loop |
Tensor Processing Units (TPUs) are Google-designed ASICs with on-chip high-bandwidth memory. They connect into slices that scale with little code change. TPU code is compiled by XLA (Accelerated Linear Algebra). JAX, PyTorch/XLA, and TensorFlow can target TPUs, and starting with TPU v6e, TensorFlow is no longer supported. On Agent Platform, TPU training runs on TPU VMs (for example, v2, v3, v5e, and v6e generations).
GPU Options on Agent Platform Training
| GPU | Memory | Typical training role |
|---|---|---|
| NVIDIA T4 | 16 GB | Low-cost small models, experimentation |
| NVIDIA L4 | 24 GB | Cost-efficient small-to-medium models and fine-tuning small LLMs with parameter-efficient methods |
| NVIDIA A100 | 40 GB or 80 GB | Mainstream large deep learning training |
| NVIDIA H100 | 80 GB | High-performance large-model training. Mega variants add high-bandwidth GPU networking (GPUDirect-TCPXO) |
| NVIDIA H200 | 141 GB | Very large models needing more memory per GPU. Includes GPUDirect-RDMA |
| NVIDIA B200 / GB200 | Latest generation | Frontier-scale training. Includes GPUDirect-RDMA |
Older GPUs (P4, P100, V100) are also listed for training. Each accelerator is available only in certain regions and machine families, such as a2 for A100, a3 for H100/H200, a4 for B200, and g2 for L4.
Sizing Memory
Training memory holds weights + gradients + optimizer states + activations. With the Adam optimizer in mixed precision, a rough rule is about 16 bytes per parameter before activations:
| Model size | Approximate weight/gradient/optimizer memory | Implication |
|---|---|---|
| 350 M parameters | ~5.6 GB | Fits on one T4 or L4 with room for activations |
| 7 B parameters | ~112 GB | Doesn't fit on one 80 GB GPU for full fine-tuning. Use sharding (FSDP/ZeRO) across GPUs, or parameter-efficient tuning (LoRA or QLoRA) |
| 70 B parameters | ~1.1 TB | Needs multi-node model parallelism and sharding |
Ways to reduce memory before buying bigger hardware:
- Mixed precision (bfloat16 on A100, H100, and TPUs, or float16 with loss scaling)
- Gradient checkpointing (recompute activations to save memory)
- Gradient accumulation (smaller micro-batches with the same effective batch)
- Parameter-efficient fine-tuning (LoRA, QLoRA)
- Sharded optimizer states (Section 11.2)
Matching Hardware to Scenarios
| Scenario | Recommended hardware | Reason |
|---|---|---|
| XGBoost churn model on 5 GB of tabular data | High-memory CPU machine (or GPU if using XGBoost GPU training) | Tree methods are fast on CPU. GPUs help mainly at larger scale |
| Fine-tuning a vision transformer on 2 million images in PyTorch with custom augmentation ops | A100 or H100 GPUs | Large batches plus custom PyTorch ops |
| Training a large recommendation model with huge embedding tables in JAX, for weeks | TPU slice | Matrix-heavy with ultra-large embeddings and long training |
| Prototype of a new loss function on a sample | CPU or a single small GPU | Flexibility and low cost matter most |
| LoRA tuning of a 7B open model on a tight budget | L4 or A100 with QLoRA | Memory-efficient tuning on cheaper GPUs |
Cost and Capacity Strategies
| Strategy | Effect |
|---|---|
| Spot VMs | Large discounts for fault-tolerant jobs with checkpoints. Not supported with TPU Pods |
| Dynamic Workload Scheduler (flex-start) | Waits for GPUs (L4, A100, H100, H200, B200) to become available, then starts all nodes together |
| Reservations / Managed Training Clusters | Guaranteed capacity for critical or very large jobs |
| Right-sizing | Measure GPU utilization. If it's low, fix the input pipeline or use fewer or smaller accelerators |
Faster hardware is often cheaper overall. A job that costs 3× more per hour but finishes 5× faster costs less in total. Compare cost per completed training run, not hourly price.
Checking Utilization Before Scaling Up
Before choosing bigger or more accelerators, look at how the current ones are used:
| Observation | Meaning | Action |
|---|---|---|
| GPU utilization low, CPU high | Input pipeline or preprocessing bottleneck | Optimize data loading (Chapter 9), then reassess |
| GPU memory near full, utilization high | Hardware is the limit | Mixed precision, then more or bigger accelerators |
| GPU utilization spiky in multi-GPU jobs | Communication or synchronization waits | Better interconnect, Reduction Server, larger per-device batch |
| Many short CPU-bound trials | Accelerators unnecessary | CPU machines or BigQuery ML |
Exam Traps
- Choosing TPUs for a PyTorch model full of custom CUDA operations in the training loop. GPUs are the better fit.
- Choosing GPUs for a small scikit-learn model. CPUs are simpler and cheaper.
- Recommending TensorFlow on the newest TPU generation where it isn't supported.
- Adding accelerators when utilization shows the input pipeline is the bottleneck.
A research team trains a JAX ranking model with very large embedding tables, dominated by matrix multiplications with no custom operations, for several weeks. Which accelerator does Google's guidance favor?
A PyTorch model relies on many custom operations that must partly run on the CPU, and the team wants to train with large batches. Which hardware is the best fit?
An engineer plans full fine-tuning of a 7-billion-parameter model with Adam in mixed precision on one 80 GB GPU. Using the rule of thumb of about 16 bytes per parameter for weights, gradients, and optimizer states, what should they expect?