Fix uneven batches in distributed dataloading - #237
Merged
Conversation
…htning-AI/litdata into fix_uneven_number_of_batches
for more information, see https://pre-commit.ci
awaelchli
force-pushed
the
fix_uneven_number_of_batches2
branch
from
July 16, 2024 14:55
a7e425c to
265c4e9
Compare
awaelchli
force-pushed
the
fix_uneven_number_of_batches2
branch
from
July 16, 2024 16:27
ebc7e3b to
b0096c5
Compare
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
tchaton
reviewed
Jul 17, 2024
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
awaelchli
marked this pull request as ready for review
July 19, 2024 15:49
awaelchli
commented
Jul 19, 2024
awaelchli
commented
Jul 19, 2024
| output_dir=data_dir, | ||
| chunk_size=190, | ||
| num_workers=4, | ||
| num_workers=1, # TODO: Want 4 here, but optimize() has deletion race condition |
Contributor
Author
There was a problem hiding this comment.
Looks like everywhere in the tests we use num_workers=1, and here I wanted 4 but there seems to be race conditions (?) on the copying/deletion of chunks, causing this test to fail because of missing chunks.
Contributor
Author
There was a problem hiding this comment.
__________________ test_dataset_resume_on_future_chunks[True] __________________
shuffle = True
tmpdir = local('/tmp/pytest-of-runner/pytest-0/test_dataset_resume_on_future_0')
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f6a4124f460>
@pytest.mark.skipif(sys.platform == "win32", reason="Not tested on windows and MacOs")
@mock.patch.dict(os.environ, {}, clear=True)
@pytest.mark.timeout(60)
@pytest.mark.parametrize("shuffle", [True, False])
def test_dataset_resume_on_future_chunks(shuffle, tmpdir, monkeypatch):
"""This test is constructed to test resuming from a chunk past the first chunk, when subsequent chunks don't have
the same size."""
s3_cache_dir = str(tmpdir / "s3cache")
optimize_data_cache_dir = str(tmpdir / "optimize_data_cache")
optimize_cache_dir = str(tmpdir / "optimize_cache")
data_dir = str(tmpdir / "optimized")
monkeypatch.setenv("DATA_OPTIMIZER_DATA_CACHE_FOLDER", optimize_data_cache_dir)
monkeypatch.setenv("DATA_OPTIMIZER_CACHE_FOLDER", optimize_cache_dir)
> optimize(
fn=_simple_preprocess,
inputs=list(range(8)),
output_dir=data_dir,
chunk_size=190,
num_workers=4,
num_uploaders=1,
copying /tmp/pytest-of-runner/pytest-0/test_dataset_resume_on_future_0/optimize_cache/chunk-3-1.bin to /tmp/pytest-of-runner/pytest-0/test_dataset_resume_on_future_0/optimized/chunk-3-1.bin
putting /tmp/pytest-of-runner/pytest-0/test_dataset_resume_on_future_0/optimize_cache/chunk-3-1.bin on the remove queue
Worker 1 is done.
Worker 2 is done.
Worker 3 is done.
Worker 0 is done.
Workers are finished.
----------------------------- Captured stderr call -----------------------------
Progress: 0%| | 0/8 [00:00<?, ?it/s]Process Process-85:1:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/runner/work/litdata/litdata/src/litdata/processing/data_processor.py", line 259, in _upload_fn
shutil.copy(local_filepath, output_filepath)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/shutil.py", line 427, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/opt/hostedtoolcache/Python/3.9.19/x64/lib/python3.9/shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pytest-of-runner/pytest-0/test_dataset_resume_on_future_0/optimize_cache/chunk-0-0.bin'
Progress: 100%|██████████| 8/8 [00:00<00:00, 122.77it/s]
=========================== short test summary info ============================
FAILED tests/streaming/test_dataset.py::test_dataset_resume_on_future_chunks[True] - RuntimeError: All the chunks should have been deleted. Found ['chunk-0-1.bin']
====== 1 failed, 191 passed, 8 skipped, 11 warnings in [247](https://github.com/Lightning-AI/litdata/actions/runs/10010459328/job/27671682379?pr=237#step:10:248).94s (0:04:07) =======
tchaton
approved these changes
Jul 19, 2024
awaelchli
force-pushed
the
fix_uneven_number_of_batches2
branch
from
July 19, 2024 16:28
8350fc2 to
bc64b77
Compare
Co-authored-by: thomas chaton <thomas.chaton.ai@gmail.com>
awaelchli
force-pushed
the
fix_uneven_number_of_batches2
branch
from
July 19, 2024 17:36
6fc442e to
66017e8
Compare
Collaborator
|
Awesome work @awaelchli ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #233
This PR changes/fixes the implementation of how items are assigned to workers.
Before: Chunks are first assigned to ranks, then samples from ranks assigned to workers
Now: Assign samples directly across combined world size of all workers/ranks.
This allows us to correctly apply
drop_lastand ensure that each rank returns the same amount of data. However, this means this PR is a breaking change.IMPORTANT:
This changes the order in which samples are batched and returned. A consequence of this also is resuming from checkpoints made prior to this PR are not going to be restored correctly.
TODOS