Model Training Infrastructure and Distributed Training Questions
Scaling model training across hardware and time. Covers GPU/accelerator considerations, data and model parallelism, distributed and large-scale training, experiment tracking and training infrastructure, and the training-versus-inference compute tradeoff. Focuses on the systems and resource decisions that make large-model training feasible.
Compare AllReduce-based collective communication and a parameter server architecture for distributed gradient aggregation. Explain their basic mechanics, typical frameworks that implement them, and one scenario where one approach outperforms the other.
Sample Answer
Direct answer
AllReduce-based training has every worker communicate directly with every other worker (typically via a ring or tree topology) to jointly compute a fully-reduced result, with no single coordinating node. A parameter server (PS) architecture instead has dedicated server nodes that receive gradients from workers, apply the update, and push back the new parameters, so workers never talk to each other directly.
Structured elaboration
- Communication pattern: AllReduce is peer-to-peer and symmetric: every worker's outbound and inbound traffic is roughly equal. PS is a star/hub pattern: server nodes see traffic proportional to the number of workers, so they can become a bandwidth bottleneck as worker count grows unless sharded across many servers.
- Framework fit: AllReduce is the default in most modern deep learning frameworks (PyTorch DDP, Horovod using NCCL) because it needs no extra server infrastructure and scales bandwidth per-worker rather than concentrating it. PS architectures (originally popularized for very large sparse models) are still common when parameters are enormous and sparsely accessed, since each worker only needs to pull the parameter shards relevant to its mini-batch. Classic named implementations include the original Parameter Server design (Li et al., 2014, used inside systems like Google's DistBelief-era infrastructure) and, in more recent open-source form, TensorFlow's
tf.distribute.experimental.ParameterServerStrategyor a hand-rolled PS built ontorch.distributed.rpc; these give PS a concrete framework grounding the same way PyTorch DDP/Horovod do for AllReduce. - Fault tolerance: PS can tolerate a slow or failed worker more gracefully in asynchronous mode (workers push/pull independently), while synchronous AllReduce requires every worker to reach the collective call, so one straggler blocks everyone.
- Staleness: AllReduce is naturally synchronous (fully consistent gradients each step); PS supports asynchronous updates, trading gradient staleness for higher worker utilization.
Worked example
A 500M-parameter dense model trained on 32 GPUs: AllReduce moves each worker's full gradient (~2GB in fp32) through the ring at ~2x that size in total link traffic per worker, independent of the number of parameter servers you would otherwise need to provision. A PS setup for the same model would need server-side bandwidth sufficient for 32 workers pushing and pulling ~2GB each per step; without sharding the parameters across multiple servers, a single PS node's NIC becomes the bottleneck well before the GPUs do.
Trade-offs & pitfalls
For dense models where every worker touches every parameter, AllReduce is almost always the better default today. PS earns its complexity back mainly for extremely large, sparsely-accessed parameter sets like recommendation-system embedding tables, where each worker only needs a small slice of the total parameters per step.
Describe how GPU memory capacity and memory bandwidth constrain choices of batch size, model size, and training throughput. Explain the trade-offs between increasing batch size, using gradient accumulation, reducing precision, and applying activation checkpointing to fit larger models or larger effective batches into GPU memory while balancing convergence and throughput.
Sample Answer
Direct answer
GPU memory capacity limits how large a batch and model you can fit at all, while memory bandwidth (how fast data moves between GPU memory and compute units) limits how fast you can actually process that data once it fits, so a training configuration can be capacity-bound, bandwidth-bound, or compute-bound depending on which resource is the tightest constraint for a given model and batch size.
Structured elaboration
- Capacity constraint: parameters, gradients, optimizer state, and activations must all fit within the GPU's total memory (e.g. 80GB on an H100); exceeding this causes an out-of-memory error regardless of how fast the GPU could otherwise compute, forcing a smaller batch size, model, or the memory-saving techniques (mixed precision, checkpointing, sharding) discussed elsewhere in this topic.
- Bandwidth constraint: even when everything fits, operations that move a lot of data relative to the compute they perform (elementwise operations, some normalization layers, small matrix multiplies) can be bottlenecked by how fast data streams between HBM and the GPU's compute units rather than by the compute units' raw throughput; this shows up as low GPU utilization percentage even though the workload is running continuously.
- Batch size trade-off: larger batch sizes generally improve compute efficiency (better utilization of the GPU's parallel compute, amortizing fixed per-kernel-launch overhead) up to the point where capacity is exhausted; very small batch sizes tend to be more bandwidth-bound (relatively more data movement per unit of useful compute) since fixed overheads and memory-bound elementwise operations don't scale down favorably.
- Model size trade-off: a larger model directly increases capacity pressure (more parameters, more activation memory per sample) which forces either a smaller batch size or additional memory-saving techniques, in turn affecting how compute-efficient a given step actually is.
Worked example
Training a model where activation memory dominates: at batch size 8, activations plus weights plus optimizer state fit within an 80GB GPU with headroom, and the GPU runs near its compute-bound peak throughput; increasing batch size to 32 might exceed the 80GB budget entirely (capacity-bound failure), while decreasing to batch size 1 for debugging purposes leaves so much of each kernel launch as fixed overhead relative to the tiny amount of actual compute that the GPU spends much of its time bandwidth- or launch-overhead-bound rather than compute-bound.
Trade-offs & pitfalls
A common mistake is assuming more GPU memory alone fixes a slow training run; if the workload is bandwidth-bound rather than capacity-bound, adding memory (a bigger GPU) doesn't address the actual bottleneck, only profiling (checking whether the GPU is near its compute-throughput ceiling or spending time waiting on memory transfers) reveals which constraint is actually binding.
Explain gradient accumulation and why it is used. Provide a brief algorithmic description of how to implement gradient accumulation to emulate a larger batch size on limited-memory GPUs, and mention how it interacts with learning rate schedules and batch-norm statistics.
Sample Answer
Direct answer
Gradient accumulation simulates training with a larger batch size than fits in memory by running several forward/backward passes on smaller micro-batches, summing (or averaging) their gradients without updating the weights, and only applying the optimizer update once after the desired number of micro-batches has accumulated.
Structured elaboration
- Why it's needed: GPU memory limits the largest batch that fits for a given model; gradient accumulation decouples the "effective batch size" the optimizer sees from the "micro-batch size" that actually fits in memory, letting you train with a large effective batch on hardware that can't hold that batch's activations all at once.
- Algorithm: for each of K micro-batches, run forward and backward (accumulating
.gradon each parameter, since PyTorch's default is to add to existing gradients rather than overwrite), without callingoptimizer.step()orzero_grad()in between; after the Kth micro-batch, calloptimizer.step()once, thenzero_grad()to reset for the next cycle. - Loss scaling convention: divide each micro-batch's loss by K before calling
.backward(), so the summed gradient across K micro-batches equals the average gradient a true large-batch step would have produced, keeping the effective learning rate consistent with what was tuned for that effective batch size.
Worked example
To simulate an effective batch size of 128 on hardware that only fits 32 samples at a time: run 4 micro-batches of 32 samples each, dividing each micro-batch's loss by 4 before backward, accumulating gradients across all 4, then calling optimizer.step() once; the resulting parameter update is (approximately, modulo any batch-size-sensitive layers like BatchNorm) equivalent to what a single true batch-128 step would have produced.
Interaction with learning-rate schedules
A learning-rate scheduler's .step() must be called once per completed accumulation cycle (once per true optimizer step), not once per micro-batch; calling it every micro-batch effectively runs the schedule K times faster than intended relative to the actual number of samples/effective-batches seen, so a warmup or decay schedule tuned for, say, 1000 optimizer steps would finish in 1000 micro-batches instead of 1000*K micro-batches, a large, easy-to-miss bug. The scheduler's total step count (and any warmup-step count) should be computed as total_micro_batches / accumulation_steps, matching the optimizer_step counter, not the raw micro-batch or sample index.
Trade-offs & pitfalls
Gradient accumulation increases wall-clock time per effective step (K sequential forward/backward passes instead of one) since it doesn't add compute parallelism, only memory savings; it also doesn't fix batch-size-sensitive layers like BatchNorm, whose statistics are still computed per micro-batch rather than over the full effective batch, unless specifically handled (e.g. via sync-BN-style aggregation or accepting the approximation).
Explain the key differences between data parallelism, model parallelism, and pipeline parallelism for distributed deep learning training. For each approach, describe typical use cases, how parameters and activations are partitioned, communication patterns, and the hardware/network characteristics that would push you to pick one strategy over the others.
Sample Answer
Direct answer
Data parallelism replicates the entire model on every device and splits the training data across devices; model parallelism splits the model itself (different parameters on different devices) while typically keeping the same data on each; pipeline parallelism is a specific form of model parallelism that splits the model into sequential stages placed on different devices, with different devices processing different micro-batches at different pipeline stages simultaneously to keep all devices busy.
Structured elaboration
- Data parallelism: every device holds an identical, full copy of the model; each device processes a different slice of the mini-batch, computing its own local gradients; gradients are then synchronized (typically via all-reduce) across devices before the (identical, since it started from identical weights and applies an identical aggregated gradient) parameter update. Chosen when the model fits comfortably in a single device's memory but training would benefit from more parallel compute across more data.
- Model parallelism: the model's parameters themselves are split across devices (e.g. different layers, or different slices of very large layers via tensor parallelism), with each device holding only a portion of the full model; necessary specifically when the model is too large to fit on a single device, regardless of batch size or data volume. Its communication pattern is denser than data parallelism's: because a split weight matrix's output activations need to be reassembled (or its input activations need to be replicated) across the devices holding the split, tensor parallelism requires an all-gather or reduce-scatter/all-reduce at essentially every split-and-rejoin point in both the forward and backward pass, on every layer that's split, which is why tensor parallelism is generally kept within a single node over fast NVLink rather than spread across a slower network.
- Pipeline parallelism: a specific model-parallelism strategy that splits the model into sequential stages (contiguous groups of layers), each stage on a different device; to avoid devices sitting idle waiting for the previous stage to finish an entire batch, the batch is further divided into smaller micro-batches, which flow through the pipeline stages in an overlapped fashion (while stage 2 processes micro-batch 1's forward pass, stage 1 can already be processing micro-batch 2's forward pass), analogous to an assembly line. Its communication pattern is much sparser than tensor parallelism's: since each device holds a distinct, non-overlapping group of layers, communication between adjacent stages is limited to point-to-point send/recv of activations (forward direction) and gradients (backward direction) at each stage boundary, once per micro-batch, rather than the dense collective communication tensor parallelism requires on every split layer; this is why pipeline parallelism tolerates being spread across nodes with slower cross-node networking far better than tensor parallelism does.
- Combining all three (3D parallelism): for very large models on large clusters, these three axes are commonly combined: tensor/model parallelism within a node (exploiting fast NVLink), pipeline parallelism across a few node groups (tolerating the necessarily-less-frequent cross-node communication), and data parallelism to scale out replicas of that combined unit across many such groups, as discussed in the earlier large-model-training-design survivors.
Worked example
Training a model that fits comfortably on one GPU but would benefit from more compute: use pure data parallelism, replicating the model across, say, 8 GPUs, each processing 1/8 of the mini-batch. Training a model too large for even one GPU's memory: use model parallelism (splitting the model's parameters across devices) as a prerequisite before data parallelism can even be applied at all, since data parallelism assumes the whole model fits on each device to begin with. Training a very large model across many GPUs with a deep layer stack: pipeline parallelism specifically addresses the idle-time problem that would otherwise occur if you naively split layers across devices without micro-batching, since without micro-batches, each device would sit completely idle while waiting for the previous device to finish the ENTIRE batch's forward pass before it could start.
Trade-offs & pitfalls
A common conceptual confusion is treating "model parallelism" and "pipeline parallelism" as synonyms; pipeline parallelism is specifically ONE WAY to do model parallelism (splitting by sequential layer groups, with micro-batching to keep devices busy), while tensor parallelism (splitting individual weight matrices) is a different way to do model parallelism, and the choice between them (or combining both) depends on the specific memory/communication trade-offs of the model and cluster in question.
Compare GPUs and TPUs for model training. Explain workload characteristics where GPUs are a better fit and where TPUs offer advantages. Discuss programming model differences (TensorFlow vs XLA), precision support (FP16, BF16), and practical considerations when selecting instance types for cloud training.
Sample Answer
Direct answer
GPUs are the default choice for most training workloads today because of their broad software ecosystem and flexibility across model architectures, while TPUs offer an edge specifically for very large, highly-regular workloads (especially transformers at scale) where their systolic-array matrix-multiply design and purpose-built high-bandwidth interconnect (ICI) pay off most.
Structured elaboration
- Workload characteristics favoring GPUs: irregular or research-stage architectures (custom ops, dynamic control flow, frequent architecture changes), smaller-scale training, and any workload needing the widest possible library/framework support (most cutting-edge research code targets GPU first).
- Workload characteristics favoring TPUs: very large, well-established architectures (transformers) trained at massive scale, where TPU pods' purpose-built interconnect and systolic-array matrix units are specifically tuned for the dense matrix multiplies dominating transformer compute, often at a favorable cost-per-FLOP for sustained large training runs.
- Programming model differences: GPU programming (CUDA, and the PyTorch/TensorFlow ecosystems built on it) is eager-execution-friendly and broadly flexible; TPUs traditionally require (or strongly favor) XLA-compiled, graph-based execution, which handles static, regular computation graphs excellently but is less forgiving of dynamic shapes or data-dependent control flow, and has historically meant a narrower (though growing) software ecosystem outside Google's own frameworks (JAX, TensorFlow).
- Availability and lock-in: GPUs are available across essentially every cloud provider and on-prem; TPUs are Google Cloud-specific, which is a real practical constraint for teams not already committed to that ecosystem.
Worked example
A research team iterating rapidly on novel architectures with custom CUDA kernels and dynamic control flow would find GPUs' flexibility essential; the same team, once they've settled on a stable, well-established transformer architecture and are scaling a single well-defined training run to thousands of accelerators, might specifically evaluate TPU pods for that production-scale run given TPUs' interconnect and systolic-array advantages at that specific workload shape, while continuing GPU-based experimentation for anything still in flux.
Precision support and instance-type selection
- Precision support: both platforms support bf16, but their history differs. GPUs (from the Volta generation onward for fp16, Ampere onward for native bf16 Tensor Core support) support fp16 well but fp16's narrow dynamic range typically requires loss scaling; TPUs were designed around bf16 from early generations specifically to avoid the loss-scaling machinery fp16 needs, so bf16-native training is the more idiomatic default on TPU, while GPU training commonly still supports both fp16 (with loss scaling) and bf16 depending on the GPU generation and framework defaults.
- Practical considerations for instance-type selection: cloud GPU instances (e.g. A100/H100-based VM families) are available in flexible single-GPU-to-multi-GPU configurations across essentially every major cloud provider, so a team can start small and scale incrementally; TPU pods are typically procured in fixed pod-slice sizes (e.g. v4/v5 slices of a given chip count) on Google Cloud specifically, which means committing to a minimum scale upfront and to a single cloud provider, a real practical constraint when a team wants provider flexibility or needs to start at very small scale before committing to a large training run.
Trade-offs & pitfalls
The GPU-versus-TPU choice is as much about ecosystem and organizational fit (existing tooling, cloud provider commitments, team CUDA expertise) as it is about a workload's raw performance characteristics; a team defaulting to GPUs purely out of ecosystem familiarity, even for a workload that would benefit from TPU's advantages, is a common and often reasonable trade-off, not a mistake, given the switching cost.
Unlock Full Question Bank
Get access to all 12 Model Training Infrastructure and Distributed Training interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.