LLM training optimization: identify the bottleneck before adding GPUs
· Nodeox
An LLM run is slow, and there are more GPUs available. Should you use them—or would that spread the same bottleneck across a larger allocation?
Start LLM training optimization by identifying what limits the current workload. Memory capacity, device computation, input delivery and communication lead to different changes. Measure useful work over a defined interval, preserve the result criterion, then test a change that addresses the observed constraint.
This guide concerns training and fine-tuning open language models in an existing GPU budget. It is not an inference-serving guide or a blueprint for a frontier-pretraining facility.
Decide what must stay comparable
Pretraining, full fine-tuning and parameter-efficient fine-tuning do not train the same set of parameters or require the same state. Changing the method changes the experiment. Name that change explicitly rather than attributing all differences to a faster implementation.
Write a compact run specification: model and revision, dataset and preprocessing, training method, sequence-length policy, precision, effective batch, optimizer and evaluation criterion. Add the relevant hardware and software versions.
For language models, keep token accounting clear. Report how training tokens are counted, including treatment of padding, packing and truncation. A number called “tokens per second” is difficult to compare if one setup counts padded positions and another counts useful input tokens.
Do not shorten sequences or drop difficult examples silently to improve a throughput figure. Those choices may be sensible workload changes, but the resulting run needs to be judged as that changed workload.
Separate memory capacity from memory traffic
An out-of-memory failure and slow movement of data through memory are different problems. The first asks whether the required state fits. The second asks how efficiently the workload uses the available hardware.
Inspect when memory peaks: model loading, forward computation, backward computation, optimizer update or evaluation. A model's weight size alone does not describe the peak training allocation. With Adam in a common mixed-precision layout, weights, gradients and optimizer state take about 16 bytes per parameter before any activations—over 100 GB for a 7-billion-parameter model. Changing batch size or sequence length can change activation and temporary-storage requirements.
Start with a short representative run rather than the easiest possible input. Include the optimizer update and evaluation path when checking the configuration. Otherwise a successful forward pass can provide false reassurance about the full job.
PyTorch's CUDA memory tools distinguish allocated and reserved memory. Interpret those readings with a trace and the allocator's behavior; a large reserved value is not, by itself, proof of a leak.
Match the intervention to the constraint
The following options are candidates for an experiment, not a universal sequence of switches to enable.
Observed constraint | Candidate change | Trade-off | Check before keeping it |
|---|---|---|---|
Activation memory prevents the intended batch or sequence length | Activation checkpointing | Recomputation adds work | Peak memory and elapsed time at the same workload |
Replicated training state does not fit comfortably | Sharded training | Additional exchanges and configuration complexity | Peak memory, communication and completed-run quality |
Suitable operations spend too much time or memory in the chosen precision | Supported mixed precision | Different numerical behavior and compatibility requirements | Stability, evaluation result and actual throughput |
Input preparation leaves the device waiting | Tune loading, preprocessing and transfers | CPU, memory and I/O usage can rise | End-to-end useful throughput, not loader speed alone |
An effective batch does not fit as one local batch | Smaller microbatches with gradient accumulation | Smaller microbatches can use the GPU less efficiently, so each update takes longer; synchronization needs care | Effective batch, loss normalization across microbatches and update equivalence |
Communication dominates distributed execution | Revisit layout, placement and synchronization | Another layout may need more memory or change the method | Exposed exchange time and total completion time |
Do one useful experiment at a time. If several settings change together, it becomes hard to explain what produced the improvement—or what caused a regression.

Understand what each memory-saving change buys
Activation checkpointing retains less intermediate state and recomputes selected forward work during backward. Its value depends on whether the memory it releases enables a more useful configuration. A lower memory peak is an achievement; it does not automatically mean a shorter training run.
Sharding addresses a different part of the budget. FSDP distributes training state and gathers what active computation needs. Network traffic and transient memory remain part of the design. Evaluate the complete layout rather than treating device memory as an unrestricted shared pool.
Gradient accumulation lets several microbatches contribute before an optimizer step. In a conventional equal-sized data-parallel arrangement, effective batch equals the per-process microbatch times the number of processes times accumulation steps. For language models, make every training token count equally: sum the per-token losses and divide by the number of loss tokens in the whole effective batch, across accumulation steps and processes. If each microbatch averages over its own tokens, tokens in shorter microbatches get more weight, and the result differs from training on the full batch at once.

With DDP, intermediate accumulation steps can avoid repeated gradient synchronization through no_sync; the forward pass must be within the intended context too. Recheck the resulting gradient scaling and final synchronized update. More accumulation is not a free increase in useful throughput. In a communication-bound run, skipping intermediate synchronizations can help. If you increase accumulation without adjusting the microbatch, the larger effective batch also changes training.
Precision is an experiment, not a quality guarantee
Automatic mixed precision chooses appropriate precision for supported operations. Hardware, operators and the training setup determine whether it is useful. fp16 usually needs gradient scaling; bf16 usually does not; numerical stability and the evaluation result still need checking.
Keep the precision policy explicit in both the baseline and candidate. If you change it while also adding devices or changing the batch, separate those effects in your interpretation.
Report the useful result directly: the configuration fits, the defined interval is shorter, or the evaluation criterion is met. Include the conditions that make that statement meaningful.
Profile the input path before expanding the allocation
A language-model input pipeline can include parsing, tokenization, length handling, batching and host-to-device transfer. If those steps cannot supply one device, more devices may increase demand on the same CPU or storage bottleneck.
The PyTorch tuning guide discusses data-loader workers and pinned memory. Tune worker counts for the actual host; multiplying a reasonable per-process setting across many ranks can create CPU contention.
Use PyTorch Profiler for a short diagnostic window, then measure the representative configuration without heavy tracing. Check that the change improved the interval the user waits for, rather than just one component's timer.
Distribute after deciding what must move
If a training replica fits, data parallelism can distribute examples across replicas. If the model or state needs partitioning, consider a layout that addresses that memory boundary.
Tensor parallelism partitions operations and introduces exchanges inside computation. Pipeline parallelism partitions layers across stages, with stage balance and scheduling becoming important. Those different exchange patterns make the interconnect part of the optimization decision. Our multi-GPU training guide compares these approaches and the local and network paths they rely on.
For a mixed fleet, check each device's memory and software support alongside its expected contribution. Our mixed-GPU training article explains that eligibility question. Nodeox's published ViT studies illustrate measurement and engineering methods; they are not LLM-throughput benchmarks.
Keep a result that someone can use again
For each candidate, retain the run specification, changes, timing boundary, useful-token count, memory peak and evaluation outcome. If you report cost, define its boundary separately: device rental alone may not capture the resources used to complete the job.
A useful fixed-work comparison holds training work steady. A time-to-quality comparison holds the target steady and measures how long reaching it takes. Neither can be replaced by one especially fast step.
Our benchmarking guide develops these comparisons. Our GPU-selection guide connects the configuration to a representative workload.
Common questions
Is lower peak memory always better?
It can enable a useful configuration. Whether it improves the overall run depends on the extra work, exchanges and operating costs it introduces.
Can I compare runs with different effective batches?
Yes, as different training configurations. Report that change and compare the quality outcome; do not present it as an isolated implementation speed-up.
What is the first optimization to try?
The one that addresses the measured limit. Establish a baseline, change the relevant setting, check quality and repeat the comparison. The best result is a configuration that finishes the intended work more effectively—not a longer list of enabled optimizations.