Hi!
The docs (torch.utils.data — PyTorch 1.13 documentation) define prefetch_factor as the “Number of batches loaded in advance by each worker,” implying that if I have W
workers and P
prefetch factor, the total batches loaded would be WxP
, although are all of these batches that have to be loaded in advance? Or are these the max batches that could be loaded in advance?
For example, consider the following code snippet:
for batch in range(data_loader):
# forward & backward passes on the model
For the above code snippet, does the data_loader
function in the following way:
- Before the first iteration,
WxP
batches are loaded - After
WxP
iterations, another set ofWxP
batches is loaded
Or does the data_loader
function in this way:
- Before the first iteration,
WxP
batches are loaded - After the first iteration, now in the host memory
WxP - 1
batches reside, so any worker from the worker pool fetches a new batch to make it toWxP
.
If in case the latter is correct, does the 2nd step happen synchronously or asynchronously? i.e. do I need to wait to fetch a new batch to make total batches to WxP
and then proceed to the iteration, or given I already have WxP - 1
batches to feed, I can process the remaining batch asynchronously?
Thanks in advance for answering!