s3-connector-for-pytorch: PIL UnidentifiedImageError training with higher 'num_workers'
s3torchconnector version
s3torchconnector-1.3.0
s3torchconnectorclient version
s3torchconnectorclient-1.3.0
AWS Region
No response
Describe the running environment
OS: AlmaLinux 8.10 Python: Python 3.11.9
What happened?
I am trying to train a ResNet model on ImageNet-1000 dataset over S3. Training begins fine and usually completes a few epochs. Randomly during any epoch, PyTorch will error out trying to open/read any particular S3 object (image file):
Traceback (most recent call last):
File "/opt/pytorch/test_s3.py", line 134, in <module>
for i, (images, labels) in enumerate(tqdm(train_dataloader, desc=f'Epoch {epoch + 1}')):
File "/opt/pytorch/venv/lib64/python3.11/site-packages/tqdm/std.py", line 1181, in __iter__
for obj in iterable:
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/dataloader.py", line 630, in __next__
data = self._next_data()
^^^^^^^^^^^^^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/dataloader.py", line 1324, in _next_data
return self._process_data(data)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/dataloader.py", line 1370, in _process_data
data.reraise()
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/_utils.py", line 706, in reraise
raise exception
PIL.UnidentifiedImageError: Caught UnidentifiedImageError in DataLoader worker process 1.
Original Traceback (most recent call last):
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 309, in _worker_loop
data = fetcher.fetch(index) # type: ignore[possibly-undefined]
^^^^^^^^^^^^^^^^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 52, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 52, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
~~~~~~~~~~~~^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/s3torchconnector/s3map_dataset.py", line 144, in __getitem__
return self._transform(self._get_object(i))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pytorch/test_s3.py", line 44, in transform_image
img = Image.open(object)
^^^^^^^^^^^^^^^^^^
File "/opt/pytorch/venv/lib64/python3.11/site-packages/PIL/Image.py", line 3298, in open
raise UnidentifiedImageError(msg)
PIL.UnidentifiedImageError: cannot identify image file <s3torchconnector.s3reader.S3Reader object at 0x7f1f4abe9150>
I tried catching the exception to print the state of the object. The _size and _position variables are both 0. This is random and can happen with any object during any epoch.
exception caught!
Object Key: train/n03743016/n03743016_1737.JPEG
{'state_after': {'_bucket': 'imagenet', '_buffer': <_io.BytesIO object at 0x7f1f4abe3290>, '_get_object_info': functools.partial(<function _identity at 0x7f1e9bf8d8a0>,
PyObjectInfo { key: "train/n03743016/n03743016_1737.JPEG", etag: "\"2f6e8e68b8ccef44c7f341149e8$ 43e5\"",
size: 122938, last_modified: 1734842473, storage_class: Some("STANDARD"), restore_status: None }),
'_get_stream': functools.partial(<bound method S3Client._get_object_stream of <s3torchconnector._s3client._s3client.S3Client object at 0x7f1e9c8af0d0>>,
'imagenet', 'train/n$ 3743016/n03743016_1737.JPEG'),
'_key': 'train/n03743016/n03743016_1737.JPEG', '_position': 0, '_size': 0, '_stream': <s3torchconnectorclient._mountpoint_s3_client.GetObjectStream object at 0x7f1ea423b690>}
I have only observed this behavior when I set num_workers for the train data loader to a higher value, greater than 1. If I set the num_workers to 0 or 1, then I don’t notice the issue.
Relevant log output
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 19 (10 by maintainers)
Hi @aqibahmad , I don’t have significant updates yet. I’m still investigating the issue, though troubleshooting is slow because in my environment, the problem only happens after few hours. In about 50% of cases, the system hangs rather than returning a zero stream as you reported. I’ve made some progress by implementing timeouts to resolve the hanging issue. However, the problems you reported persist despite attempting various solutions, including implementing retries. I thought the root cause might be related to version of Pyo3, that we are using for wiring with our transport layer. However, upgrading to the latest Pyo3 version introduced additional complications. I’m currently investigating whether these new issues post-upgrade are related to the original problem.
I’ll continue investigating and update you once I have more concrete findings.
Hi @aqibahmad , Thank you for providing the logs. I was able to reproduce the reported issue using VPC and long term credentials with low-level logging enabled; however, there was still no errors in logs that could help in finding the reason. We will need additional time to troubleshoot the root cause of this problem. Thank you for your patience.