PyTorch Custom Dataset and DataLoader: getitem , len , collate_fn, and num_workers
Original Publication Notice: This article was originally published on the Botmartz Engineering Blog . Canonical URL: https://blog.botmartz.com/posts/pytorch-custom-dataset-and-dataloader-getitem-len-collate-fn-and-num-workers
GPU utilization dropping to 30% during training is almost always a data loading bottleneck. The model is done processing a batch and waiting for the next one — the CPU isn't keeping up. PyTorch's DataLoader with num_workers > 0 is the fix, but only if your Dataset is correctly implemented.…