LearnQuestion bank

GPU utilisation sits at 30% and loss is not decreasing. How do you investigate?

ML engineeringTechnicalMedium

Answer it yourself first, out loud or on paper, then compare.

Answer

Model answer, written in a candidate's voice

In short

  • Lead with correctness: overfit one batch first; if the model cannot drive that loss down, do not tune throughput yet.
  • Check the training loop: zero_grad every step, loss/target shapes and dtypes, no softmax before CrossEntropyLoss, train() vs eval(), LR, shuffling and label correctness.
  • Then profile throughput: dataloader workers, pinned memory, CPU-side decoding, host-device syncs such as .item(), small batches, and missing AMP.
  • Use the profiler and per-layer gradient norms to separate a data/sync bottleneck from a model/optimisation problem.

In full

My first move is to assume the loss is not decreasing because the optimisation is wrong, not because the GPU is underused: I overfit a single batch and confirm the model can drive that loss down before touching throughput. Then I check the basics: zero_grad every step, loss and target shapes and dtypes, that the final layer is not applying softmax before CrossEntropyLoss (which already includes log-softmax), train() during training and eval() during validation, a sane learning rate, shuffling, and that labels are aligned with inputs. If the one-batch overfit still fails, I inspect per-layer gradient norms and the loss/activation pairing rather than increasing batch size or workers. Once correctness is plausible, I profile the dataloader and loop: worker count, pinned memory, CPU-side decoding, .item() or other host-device syncs, small batches, and whether AMP is enabled. The profiler tells me whether time is spent in data loading, kernels, or synchronisation, and the gradient norms tell me whether the model is actually learning or stuck in a bad regime.

Corrected by an independent AI reviewer.

What a strong answer covers

  • Throughput: profile the dataloader (workers, pinned memory, decoding on CPU), host–device syncs (.item() in the loop), small batches, missing AMP.
  • Correctness: overfit one batch first; check zero_grad, the loss/target shapes and dtype, the final activation vs loss pairing (softmax + CrossEntropyLoss double-softmax), train/eval mode, LR, data shuffling and labels.
  • Uses the profiler and per-layer gradient norms.

Common mistakes

  • tuning hyperparameters before the overfit-one-batch test
  • applying softmax before nn.CrossEntropyLoss.