Troubleshooting intermittent input/output errors in DDP

martinlindstrom: <p>I’m experiencing an intermittent input/output error trying to train a ResNet-50 classifier on ImageNet. I run DDP and distribute the workload over 4 GPU:s. Some runs I start work fine, others fail, often in the first epoch, and I’m struggling to figure out why. In the last few months, I haven’t seen any problems, but in the last few weeks almost half the runs fail. In general, how does one approach troubleshooting these types of issues?</p>
<p>The only thing I could think of that could cause this sudden jump in problems is that I recently increased the batch size quite a bit. I also sometimes start multiple runs in parallel, which obviously work on the same dataset. Could this cause some form of “file lock” where different runs are trying to read the same image at the same time? That would explain why these issues are intermittent, sometimes the runs work fine, and it’s gotten worse lately. If not, I’d greatly appreciate any pointers.</p>
<h3><a name="p-466228-some-things-i-have-tried-unsuccessfully-1" class="anchor" href="#p-466228-some-things-i-have-tried-unsuccessfully-1"></a>Some things I have tried (unsuccessfully):</h3>
<ul>
<li>Reducing the number of workers in the DataLoader (though not to 0 due to performance)</li>
<li>Iterating through all images in my local copy of ImageNet and seeing that they are not corrupted by using <code>img.verify()</code> from the <code>pillow</code> library</li>
<li>Reducing the <code>OMP_NUM_THREADS</code> environment variable (though not to 0 due to performance)</li>
</ul>
<h3><a name="p-466228-error-print-2" class="anchor" href="#p-466228-error-print-2"></a>Error print</h3>
<p>(The rank and DataLoader worker process number changes from failed run to failed run.)</p>
<blockquote>
<p>…<br>
[rank1]: OSError: Caught OSError in DataLoader worker process 0.<br>
[rank1]: Original Traceback (most recent call last):<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/worker.py”, line 308, in _worker_loop<br>
[rank1]:     data = fetcher.fetch(index)  # type: ignore[possibly-undefined]<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py”, line 51, in fetch<br>
[rank1]:     data = [self.dataset[idx] for idx in possibly_batched_index]<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py”, line 51, in <br>
[rank1]:     data = [self.dataset[idx] for idx in possibly_batched_index]<br>
[rank1]:   File “/path/to/dataloader.py”, line 85, in __getitem__<br>
[rank1]:     x, y = self.subset[index]<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataset.py”, line 411, in __getitem__<br>
[rank1]:     return self.dataset[self.indices[idx]]<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torchvision/datasets/folder.py”, line 245, in __getitem__<br>
[rank1]:     sample = self.loader(path)<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torchvision/datasets/folder.py”, line 284, in default_loader<br>
[rank1]:     return pil_loader(path)<br>
[rank1]:   File “/usr/local/lib/python3.10/dist-packages/torchvision/datasets/folder.py”, line 262, in pil_loader<br>
[rank1]:     with open(path, “rb”) as f:<br>
[rank1]: OSError: [Errno 5] Input/output error: ‘/path/to/file.jpeg’</p>
</blockquote>