Repository navigation
Optimize PyArrow block shuffling with dynamic rebatched chunk interleaving - #8407
Conversation
|
The PR changes the shuffle results for a given seed, seems to cause test_iterable_dataset_shuffle_buffer_uses_multiple_input_shards to fail. |
Updated the test. |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
lhoestq
left a comment
There was a problem hiding this comment.
Nice improvement ! I think it would make sense to also update the __iter__ method as well so both __iter__ and _iter_arrow return examples in the same order - otherwise it can be confusing for users IMO
… randomization Update the randomization logic of BufferShuffledExamplesIterable.__iter__ to match the rolling amortized block-shuffling algorithm used in _iter_arrow.
5552280 to
c9dc3f4
Compare
@lhoestq sure, I have updated the |
lhoestq
left a comment
There was a problem hiding this comment.
lgtm ! I could even get a x150 speed boost with a local dataset !
|
This is really, really useful btw ! Would it be ok if I share this improvement online and mention you and the GCS team ? edit: I couldn't wait lol: https://x.com/lhoestq/status/2096966828547277195?s=20 |
@lhoestq Yes, thanks for the recognition! |
When streaming PyArrow datasets with shuffling enabled (
buffer_size > 0), theBufferShuffledExamplesIterable._iter_arrow()method historically relied on a Python-levellistto maintain the shuffle buffer, replacing elements one-by-one. In a multi-workerDataLoaderenvironment, this per-row generator approach caused severe GIL contention, high generator state-transition overhead, and inefficient memory interleaving.This PR introduces Amortized Native C++ Block Shuffling for PyArrow streaming. It completely replaces the Python 1-row exchange loop with vectorized block shuffling:
2 * self.buffer_size.pyarrow.concat_tables(tables).pyarrow.compute.take(buffer_table, indices).current_len - self.buffer_sizerows are yielded immediately, while the remainingself.buffer_sizerows are retained as the seed buffer for the next shuffle block.By eliminating the 1-row
yieldloop, we drastically drop CPU overhead and unlock the full IO throughput potential of PyArrow when combined withsplit_dataset_by_nodeand multiple dataloader workers.Impact
We benchmarked streaming shuffled reads over 3 epochs on a 5.24 GB Parquet dataset (1.63M rows across 20 shards, 9 row groups/file) stored in a Google Cloud Storage Rapid bucket (
c4-highmem-96, 96 vCPUs):After #8387 and this PR: