sedpack 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. sedpack-0.2.1/LICENSE +202 -0
  2. {sedpack-0.2.0 → sedpack-0.2.1}/PKG-INFO +1 -1
  3. {sedpack-0.2.0 → sedpack-0.2.1}/rust/Cargo.lock +11 -11
  4. {sedpack-0.2.0 → sedpack-0.2.1}/rust/Cargo.toml +1 -1
  5. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset_iteration.py +27 -14
  6. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/iteration/rust_generator.py +15 -1
  7. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/itertools/itertools.py +5 -3
  8. {sedpack-0.2.0 → sedpack-0.2.1}/README.md +0 -0
  9. {sedpack-0.2.0 → sedpack-0.2.1}/pyproject.toml +0 -0
  10. {sedpack-0.2.0 → sedpack-0.2.1}/rust/benches/my_benchmark.rs +0 -0
  11. {sedpack-0.2.0 → sedpack-0.2.1}/rust/benches/setup.sh +0 -0
  12. {sedpack-0.2.0 → sedpack-0.2.1}/rust/rustfmt.toml +0 -0
  13. {sedpack-0.2.0 → sedpack-0.2.1}/rust/src/batch_iteration.rs +0 -0
  14. {sedpack-0.2.0 → sedpack-0.2.1}/rust/src/example_iteration.rs +0 -0
  15. {sedpack-0.2.0 → sedpack-0.2.1}/rust/src/lib.rs +0 -0
  16. {sedpack-0.2.0 → sedpack-0.2.1}/rust/src/parallel_map.rs +0 -0
  17. {sedpack-0.2.0 → sedpack-0.2.1}/rust/src/shard_generated.rs +0 -0
  18. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/__init__.py +0 -0
  19. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/__init__.py +0 -0
  20. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/compress.py +0 -0
  21. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset.py +0 -0
  22. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset_base.py +0 -0
  23. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset_filler.py +0 -0
  24. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset_iteration_tf.py +0 -0
  25. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/dataset_writing.py +0 -0
  26. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/errors.py +0 -0
  27. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/file_info.py +0 -0
  28. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/__init__.py +0 -0
  29. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/iterate.py +0 -0
  30. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/shard.fbs +0 -0
  31. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/shardfile/Attribute.py +0 -0
  32. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/shardfile/Example.py +0 -0
  33. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/shardfile/Shard.py +0 -0
  34. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/shardfile/__init__.py +0 -0
  35. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/unit_tests/shard_writer_flatbuffer_test_schema/NumPyVectorTest.py +0 -0
  36. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/unit_tests/shard_writer_flatbuffer_test_schema/__init__.py +0 -0
  37. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/flatbuffer/unit_tests/shard_writer_flatbuffer_test_schema.fbs +0 -0
  38. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/iteration/__init__.py +0 -0
  39. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/iteration/rust_batched_generator.py +0 -0
  40. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/itertools/__init__.py +0 -0
  41. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/itertools/lazy_pool.py +0 -0
  42. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/merge_shard_infos.py +0 -0
  43. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/metadata.py +0 -0
  44. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/npz/__init__.py +0 -0
  45. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/npz/iterate_npz.py +0 -0
  46. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/__init__.py +0 -0
  47. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/get_shard_writer.py +0 -0
  48. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/iterate_shard_base.py +0 -0
  49. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/shard.py +0 -0
  50. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/shard_writer_base.py +0 -0
  51. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/shard_writer_flatbuffer.py +0 -0
  52. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/shard_writer_np.py +0 -0
  53. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard/shard_writer_tfrec.py +0 -0
  54. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard_file_metadata.py +0 -0
  55. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard_info_iterator/__init__.py +0 -0
  56. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard_info_iterator/balanced_iterator.py +0 -0
  57. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard_info_iterator/cached_shard_info_iterator.py +0 -0
  58. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/shard_info_iterator/shard_info_iterator.py +0 -0
  59. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/tfrec/__init__.py +0 -0
  60. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/tfrec/read.py +0 -0
  61. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/tfrec/tfdata.py +0 -0
  62. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/types.py +0 -0
  63. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/io/utils.py +0 -0
  64. {sedpack-0.2.0 → sedpack-0.2.1}/src/sedpack/py.typed +0 -0
sedpack-0.2.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sedpack
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Environment :: Console
6
6
  Classifier: Framework :: Jupyter
@@ -678,9 +678,9 @@ dependencies = [
678
678
 
679
679
  [[package]]
680
680
  name = "pyo3"
681
- version = "0.29.2"
681
+ version = "0.29.3"
682
682
  source = "registry+https://github.com/rust-lang/crates.io-index"
683
- checksum = "4688ddedf473e32662b9b067670129a8afb8c18e351482c70d62ba4a88171e8b"
683
+ checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655"
684
684
  dependencies = [
685
685
  "libc",
686
686
  "once_cell",
@@ -692,18 +692,18 @@ dependencies = [
692
692
 
693
693
  [[package]]
694
694
  name = "pyo3-build-config"
695
- version = "0.29.2"
695
+ version = "0.29.3"
696
696
  source = "registry+https://github.com/rust-lang/crates.io-index"
697
- checksum = "f41027e41b4bd03f6e60f9f417fe24a6341a6bb744edd62b6f709f2a52ea30e9"
697
+ checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb"
698
698
  dependencies = [
699
699
  "target-lexicon",
700
700
  ]
701
701
 
702
702
  [[package]]
703
703
  name = "pyo3-ffi"
704
- version = "0.29.2"
704
+ version = "0.29.3"
705
705
  source = "registry+https://github.com/rust-lang/crates.io-index"
706
- checksum = "e591a95526fead067432c3b3a33fc74770b87b1e04e73671090d9c2055a2b327"
706
+ checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330"
707
707
  dependencies = [
708
708
  "libc",
709
709
  "pyo3-build-config",
@@ -711,9 +711,9 @@ dependencies = [
711
711
 
712
712
  [[package]]
713
713
  name = "pyo3-macros"
714
- version = "0.29.2"
714
+ version = "0.29.3"
715
715
  source = "registry+https://github.com/rust-lang/crates.io-index"
716
- checksum = "73225868fc1cd84eef2c3c230ddb91273bf1de46aeb8a4248da76d32a0924a1c"
716
+ checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6"
717
717
  dependencies = [
718
718
  "proc-macro2",
719
719
  "pyo3-macros-backend",
@@ -723,9 +723,9 @@ dependencies = [
723
723
 
724
724
  [[package]]
725
725
  name = "pyo3-macros-backend"
726
- version = "0.29.2"
726
+ version = "0.29.3"
727
727
  source = "registry+https://github.com/rust-lang/crates.io-index"
728
- checksum = "571575aa3749fa6216757dd47d2a3e7ef360f329a40f0666a9fbd14889024952"
728
+ checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3"
729
729
  dependencies = [
730
730
  "heck",
731
731
  "proc-macro2",
@@ -882,7 +882,7 @@ dependencies = [
882
882
 
883
883
  [[package]]
884
884
  name = "sedpack_rs"
885
- version = "0.2.0"
885
+ version = "0.2.1"
886
886
  dependencies = [
887
887
  "criterion",
888
888
  "flatbuffers",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "sedpack_rs"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  edition = "2024"
5
5
  description = "Rust bindings for sedpack a general ML dataset package"
6
6
  authors = [
@@ -28,7 +28,12 @@ import asyncstdlib
28
28
  from sedpack.io.dataset_base import DatasetBase
29
29
  from sedpack.io.flatbuffer import IterateShardFlatBuffer
30
30
  from sedpack.io.itertools import LazyPool
31
- from sedpack.io.itertools import round_robin, round_robin_async, shuffle_buffer
31
+ from sedpack.io.itertools import (
32
+ round_robin,
33
+ round_robin_async,
34
+ shuffle_buffer,
35
+ shuffle_buffer_async,
36
+ )
32
37
  from sedpack.io.npz import IterateShardNP
33
38
  from sedpack.io.shard import IterateShardBase
34
39
  from sedpack.io.shard.iterate_shard_base import T
@@ -176,13 +181,16 @@ class DatasetIteration(DatasetBase):
176
181
  # TODO(issue #85) Async iterator typing.
177
182
  example_iterator: AsyncIterator[ExampleT]
178
183
  if shuffle:
179
- example_iterator = round_robin_async(
180
- asyncstdlib.map(
181
- shard_iterator.
182
- iterate_shard_async, # type: ignore[arg-type]
183
- shard_paths_iterator,
184
+ example_iterator = shuffle_buffer_async(
185
+ round_robin_async(
186
+ asyncstdlib.map(
187
+ shard_iterator.
188
+ iterate_shard_async, # type: ignore[arg-type]
189
+ shard_paths_iterator,
190
+ ),
191
+ buffer_size=file_parallelism,
184
192
  ),
185
- buffer_size=file_parallelism,
193
+ buffer_size=shuffle,
186
194
  ) # type: ignore[assignment]
187
195
  else:
188
196
  example_iterator = asyncstdlib.chain.from_iterable(
@@ -356,14 +364,17 @@ class DatasetIteration(DatasetBase):
356
364
  with context:
357
365
  if shuffle:
358
366
  with LazyPool(file_parallelism) as pool:
359
- yield from round_robin(
360
- pool.imap_unordered(
361
- shard_iterator.
362
- process_and_list, # type: ignore[arg-type]
363
- shard_paths_iterator,
367
+ yield from shuffle_buffer(
368
+ round_robin(
369
+ pool.imap_unordered(
370
+ shard_iterator.
371
+ process_and_list, # type: ignore[arg-type]
372
+ shard_paths_iterator,
373
+ ),
374
+ # round_robin keeps the whole shard files in memory.
375
+ buffer_size=file_parallelism,
364
376
  ),
365
- # round_robin keeps the whole shard files in memory.
366
- buffer_size=file_parallelism,
377
+ buffer_size=shuffle,
367
378
  )
368
379
  else:
369
380
  # Iterate in order but avoid out of memory caused by eagerly
@@ -579,6 +590,7 @@ class DatasetIteration(DatasetBase):
579
590
  batch_size=batch_size,
580
591
  process_batch=process_batch,
581
592
  file_parallelism=file_parallelism,
593
+ shuffle_buffer_size=shuffle,
582
594
  ) as rust_generator:
583
595
  yield from rust_generator()
584
596
 
@@ -640,5 +652,6 @@ class DatasetIteration(DatasetBase):
640
652
  shard_iterator=shard_iterator,
641
653
  process_record=process_record,
642
654
  file_parallelism=file_parallelism,
655
+ shuffle_buffer_size=shuffle,
643
656
  ) as rust_generator:
644
657
  yield from rust_generator()
@@ -28,6 +28,7 @@ from typing_extensions import Self
28
28
  import numpy as np
29
29
 
30
30
  from sedpack.io.flatbuffer import IterateShardFlatBuffer
31
+ from sedpack.io.itertools import shuffle_buffer
31
32
  from sedpack.io.metadata import DatasetStructure
32
33
  from sedpack.io.shard.iterate_shard_base import T
33
34
  from sedpack.io.shard_file_metadata import ShardInfo
@@ -94,6 +95,7 @@ class RustGenerator:
94
95
  shard_iterator: Iterable[ShardInfo],
95
96
  process_record: Callable[[ExampleT], T] | None = None,
96
97
  file_parallelism: int = os.cpu_count() or 1,
98
+ shuffle_buffer_size: int = 0,
97
99
  ) -> None:
98
100
  """A reentrant generator.
99
101
 
@@ -110,6 +112,9 @@ class RustGenerator:
110
112
  transformation of each example.
111
113
 
112
114
  file_parallelism (int): How many files to read in parallel.
115
+
116
+ shuffle_buffer_size (int): How large should the shuffle buffer be.
117
+ Defaults to 0 for deterministic iteration.
113
118
  """
114
119
  self._rust_iter: RustIter | None # type: ignore[no-any-unimported]
115
120
  self._rust_iter = None
@@ -131,6 +136,7 @@ class RustGenerator:
131
136
  self._shard_iterator: Iterator[ShardInfo] = iter(shard_iterator)
132
137
  self._process_record: Callable[[ExampleT], T] | None = process_record
133
138
  self._file_parallelism: int = file_parallelism
139
+ self._shuffle_buffer_size: int = shuffle_buffer_size
134
140
 
135
141
  # Only FlatBuffers are supported.
136
142
  if dataset_structure.shard_file_type != "fb":
@@ -207,7 +213,15 @@ class RustGenerator:
207
213
  elif not self._rust_iter.can_iterate:
208
214
  self._rust_iter.__enter__() # pylint: disable=unnecessary-dunder-call
209
215
 
210
- example_iterator = map(self._to_dict, iter(self._rust_iter))
216
+ example_iterator: Iterable[ExampleT] = map(
217
+ self._to_dict,
218
+ iter(self._rust_iter),
219
+ )
220
+ if self._shuffle_buffer_size > 0:
221
+ example_iterator = shuffle_buffer(
222
+ example_iterator,
223
+ buffer_size=self._shuffle_buffer_size,
224
+ )
211
225
  if self._process_record:
212
226
  yield from map(self._process_record, example_iterator)
213
227
  else:
@@ -17,7 +17,6 @@
17
17
  import random
18
18
  from typing import AsyncIterable, Iterable, TypeVar
19
19
 
20
- import asyncstdlib
21
20
  import numpy as np
22
21
 
23
22
 
@@ -73,8 +72,11 @@ async def shuffle_buffer_async(iterable: AsyncIterable[T],
73
72
 
74
73
  # Fill the buffer.
75
74
  buffer: list[T] = []
76
- async for _, item in asyncstdlib.zip(range(buffer_size), iterable):
77
- buffer.append(item)
75
+ for _ in range(buffer_size):
76
+ try:
77
+ buffer.append(await anext(iterable))
78
+ except StopAsyncIteration:
79
+ break
78
80
 
79
81
  # Iterate and keep filling the buffer.
80
82
  r = initial_random_state()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes