I used the code below to train on the full MNIST dataset. The code runs quite slowly, and when I monitor my GPU usage using “nvidia-smi -l 1”, although I can see “GPU Memory Usage” ~5xxMiB, “GPU-Util” fluctuates between 0% and 1%.
Is my code using GPU? Or is it simply bottlenecked on data I/O? If the latter, is there a way to make ImageDataLoaders read ahead more?
You code does use GPU (device="cuda"). So it may be indeed due to ImageDataLoaders.from_folder you may try adding the argument num_workers= a number greater than 0 Increasing num_workers allows for parallel data loading, which can help mitigate I/O bottlenecks.
num_workers = 32
(I’m on an 8 core CPU and GTX1080)
The first two didn’t make a difference in training speed (in fact, it’s surprisingly consistent - all epochs took 36 seconds). The last one was slower - all epochs took 40 seconds (probably expected since I only have 8 cores).
Ah well, I guess I’ll learn more ways to optimize later in the course. Thanks again for your help!
Maybe another possibility is that the batch size (bs=1024) might be too large for your GPU, which could limit the GPU utilization. You could try reducing the batch size to a smaller value, such as 128 or 256, to see if it leads to better GPU utilization and faster training times.
You can also enable the pin_memory option in the ImageDataLoaders.from_folder function. Setting pin_memory=True allows the data to be directly transferred from the CPU to the GPU memory, potentially reducing the transfer time.
full_dls = ImageDataLoaders.from_folder(full_path,
train='training',
valid='testing',
img_cls=PILImageBW,
batch_tfms=TransformImageToTensor,
bs=256, # reducing batch size
num_workers=4, # Increase the number of workers
pin_memory=True, # Enable pin_memory
device="cuda")
I don’t have much experience running things locally but once when I tried training a model on my friend’s pc, instead of using the nvidia gpu it was using gpu built in the processor, I never solved the problem. Perhaps you should check if you got the same problem and find ways to utilise the main gpu.