Issue
Is there a difference between the parallelization that takes place between these two options? I’m assuming num_workers
is solely concerned with the parallelizing the data loading. But is setting torch.set_num_threads
for training in general? Trying to understand the difference between these options. Thanks!
Solution
The num_workers
for the DataLoader specifies how many parallel workers to use to load the data and run all the transformations. If you are loading large images or have expensive transformations then you can be in situation where GPU is fast to process your data and your DataLoader is too slow to continuously feed the GPU. In that case setting higher number of workers helps. I typically increase this number until my epoch step is fast enough. Also, a side tip: if you are using docker, usually you want to set shm to 1X to 2X number of workers in GB for large dataset like ImageNet.
The torch.set_num_threads
specifies how many threads to use for parallelizing CPU-bound tensor operations. If you are using GPU for most of your tensor operations then this setting doesn't matter too much. However, if you have tensors that you keep on cpu and you are doing lot of operations on them then you might benefit from setting this. Pytorch docs, unfortunately, don't specify which operations will benefit from this so see your CPU utilization and adjust this number until you can max it out.
Answered By - Shital Shah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.