loaderx 2.3.3__tar.gz → 2.3.8__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.
- {loaderx-2.3.3/loaderx.egg-info → loaderx-2.3.8}/PKG-INFO +212 -252
- {loaderx-2.3.3 → loaderx-2.3.8}/README.md +209 -251
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/__init__.py +4 -2
- loaderx-2.3.8/loaderx/converter.py +204 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/utils.py +13 -21
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/zrecord.py +3 -22
- {loaderx-2.3.3 → loaderx-2.3.8/loaderx.egg-info}/PKG-INFO +212 -252
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx.egg-info/SOURCES.txt +2 -0
- loaderx-2.3.8/loaderx.egg-info/requires.txt +6 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/pyproject.toml +3 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/_bench_common.py +55 -158
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/bench.py +5 -5
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/bench_dense.py +8 -5
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/bench_ragged.py +23 -111
- loaderx-2.3.8/scripts/prepare_vision.py +167 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/requirements-bench.txt +3 -1
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/test_loaderx.py +213 -40
- {loaderx-2.3.3 → loaderx-2.3.8}/src/record/engine.zig +6 -7
- {loaderx-2.3.3 → loaderx-2.3.8}/src/record/executor.zig +1 -1
- loaderx-2.3.3/loaderx.egg-info/requires.txt +0 -3
- {loaderx-2.3.3 → loaderx-2.3.8}/LICENSE +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/MANIFEST.in +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/build.zig +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/build.zig.zon +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/_lib.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/_store.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/dataloader.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx/zsampler.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx.egg-info/dependency_links.txt +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/loaderx.egg-info/top_level.txt +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/build_wheels.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/scripts/prepare_tokens.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/setup.cfg +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/setup.py +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/src/record/storage.zig +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/src/store.zig +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/src/zsampler.zig +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/src/zstd/c.zig +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/COPYING +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/LICENSE +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/allocations.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/bits.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/bitstream.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/compiler.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/cpu.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/debug.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/debug.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/entropy_common.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/error_private.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/error_private.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/fse.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/fse_decompress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/huf.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/mem.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/pool.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/pool.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/portability_macros.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/threading.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/threading.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/xxhash.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/xxhash.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/zstd_common.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/zstd_deps.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/zstd_internal.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/common/zstd_trace.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/clevels.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/fse_compress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/hist.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/hist.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/huf_compress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_internal.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_literals.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_literals.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_sequences.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_sequences.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_superblock.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_compress_superblock.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_cwksp.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_double_fast.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_double_fast.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_fast.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_fast.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_lazy.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_lazy.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_ldm.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_ldm.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_ldm_geartab.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_opt.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_opt.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_preSplit.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstd_preSplit.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstdmt_compress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/compress/zstdmt_compress.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/huf_decompress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/huf_decompress_amd64.S +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_ddict.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_ddict.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_decompress.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_decompress_block.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_decompress_block.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/decompress/zstd_decompress_internal.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/cover.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/cover.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/divsufsort.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/fastcover.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/dictBuilder/zdict.c +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/zdict.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/zstd.h +0 -0
- {loaderx-2.3.3 → loaderx-2.3.8}/vendor/zstd/lib/zstd_errors.h +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: loaderx
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.8
|
|
4
4
|
Summary: Rebuildable high-performance ordered record containers
|
|
5
5
|
Author-email: Ben0i0d <ben0i0d@foxmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -21,6 +21,8 @@ License-File: LICENSE
|
|
|
21
21
|
Requires-Dist: numpy
|
|
22
22
|
Requires-Dist: cffi
|
|
23
23
|
Requires-Dist: msgpack
|
|
24
|
+
Provides-Extra: converter
|
|
25
|
+
Requires-Dist: datasets[vision]>=2.19; extra == "converter"
|
|
24
26
|
Dynamic: license-file
|
|
25
27
|
|
|
26
28
|
# Loaderx
|
|
@@ -73,9 +75,9 @@ from loaderx.dataloader import DataLoader
|
|
|
73
75
|
|
|
74
76
|
data = np.load('data.npy', mmap_mode='r')
|
|
75
77
|
label = np.load('label.npy', mmap_mode='r')
|
|
76
|
-
with Dense.create('train_data', data.dtype, data.shape[1:]) as ds:
|
|
78
|
+
with Dense.create('train_data', data.dtype, data.shape[1:], codec='zstd') as ds:
|
|
77
79
|
ds.append(data)
|
|
78
|
-
with Dense.create('train_label', label.dtype, label.shape[1:]) as ds:
|
|
80
|
+
with Dense.create('train_label', label.dtype, label.shape[1:], codec='zstd') as ds:
|
|
79
81
|
ds.append(label)
|
|
80
82
|
|
|
81
83
|
data_store = Dense.open('train_data')
|
|
@@ -100,13 +102,70 @@ at the same indices, so record ``i`` lines up across them. The ``transform``
|
|
|
100
102
|
callback is the collate step — reshape, cast, stack — where ``values`` is the
|
|
101
103
|
plain dense batch ready for the model.
|
|
102
104
|
|
|
105
|
+
### Offline Hugging Face conversion
|
|
106
|
+
|
|
107
|
+
The optional converter uses Hugging Face Datasets for remote discovery,
|
|
108
|
+
download, caching, revision handling and source-format decoding. It then writes
|
|
109
|
+
explicit typed Zrecord streams, so training needs neither `datasets` nor Arrow:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pip install 'loaderx[converter]'
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from loaderx.converter import convert, huggingface
|
|
117
|
+
|
|
118
|
+
dataset = huggingface("ylecun/mnist", revision="main", token=None)
|
|
119
|
+
convert(
|
|
120
|
+
dataset,
|
|
121
|
+
"mnist",
|
|
122
|
+
codec="zstd",
|
|
123
|
+
batch_size=256,
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`huggingface` resolves the requested branch, tag or commit to an immutable
|
|
128
|
+
snapshot, then downloads and returns the repository's DatasetDict. Repositories
|
|
129
|
+
without one default config require `config=...`. `convert` is the independent
|
|
130
|
+
persistence stage: it accepts that DatasetDict or one already normalized
|
|
131
|
+
Dataset. `batch_size` bounds records per Python batch; actual bytes also depend
|
|
132
|
+
on record sizes and Ragged packing.
|
|
133
|
+
For private or gated repositories, pass `token="hf_..."`; `None` uses the
|
|
134
|
+
standard HF environment, local login, or anonymous access.
|
|
135
|
+
Static or regularly batched numeric arrays become Dense stores, while dynamic
|
|
136
|
+
arrays become Ragged stores; source dtype and record shape are preserved.
|
|
137
|
+
|
|
138
|
+
Zrecord persists numeric tensors rather than Python objects. A standard HF
|
|
139
|
+
feature that cannot be represented losslessly fails with its column name;
|
|
140
|
+
conversion does not filter, pad, tokenize, reshape, or run a transform stage.
|
|
141
|
+
Arrow dtypes, including float64 and uint64, are preserved. Only the current
|
|
142
|
+
batch is formatted; `with_format` never materializes the complete dataset.
|
|
143
|
+
|
|
144
|
+
The result groups aligned streams under one published root:
|
|
145
|
+
|
|
146
|
+
```text
|
|
147
|
+
mnist/
|
|
148
|
+
train/
|
|
149
|
+
image/
|
|
150
|
+
label/
|
|
151
|
+
test/
|
|
152
|
+
image/
|
|
153
|
+
label/
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Conversion happens under a temporary sibling directory. The root is renamed
|
|
157
|
+
into place only after all stores close and their record counts agree; a failed
|
|
158
|
+
build that raises a Python exception is discarded. A process kill may leave the
|
|
159
|
+
hidden temporary sibling for manual cleanup. No collection manifest is added;
|
|
160
|
+
the output is only split directories containing ordinary column Zrecord stores.
|
|
161
|
+
|
|
103
162
|
### Creating a dense store
|
|
104
163
|
```python
|
|
105
164
|
import numpy as np
|
|
106
165
|
from loaderx.zrecord import Dense
|
|
107
166
|
|
|
108
167
|
data = np.load('data.npy', mmap_mode='r')
|
|
109
|
-
with Dense.create('train_data', data.dtype, data.shape[1:]) as ds:
|
|
168
|
+
with Dense.create('train_data', data.dtype, data.shape[1:], codec='zstd') as ds:
|
|
110
169
|
ds.append(data)
|
|
111
170
|
```
|
|
112
171
|
One record per slice along axis 0; a 1-D array (the usual shape of a label set)
|
|
@@ -132,7 +191,7 @@ engine consumes the trusted Dense stride or Ragged offsets. Append inputs are
|
|
|
132
191
|
strictly NumPy arrays: Dense takes one batched ndarray and Ragged takes an
|
|
133
192
|
iterable of ndarrays. Raw bytes and pre-encoded images are made explicit with
|
|
134
193
|
``np.frombuffer(raw, dtype=np.uint8)`` and stored in a
|
|
135
|
-
``Ragged.create(path, dtype=np.uint8, ndim=1)`` rather than creating a second
|
|
194
|
+
``Ragged.create(path, dtype=np.uint8, ndim=1, codec="zstd")`` rather than creating a second
|
|
136
195
|
public storage API.
|
|
137
196
|
|
|
138
197
|
### Records
|
|
@@ -147,7 +206,7 @@ import numpy as np
|
|
|
147
206
|
from loaderx.zrecord import Dense
|
|
148
207
|
|
|
149
208
|
data = np.arange(64, dtype=np.float32).reshape(8, 2, 4)
|
|
150
|
-
with Dense.create('data', data.dtype, data.shape[1:]) as ds:
|
|
209
|
+
with Dense.create('data', data.dtype, data.shape[1:], codec='zstd') as ds:
|
|
151
210
|
ds.append(data)
|
|
152
211
|
ds = Dense.open('data')
|
|
153
212
|
ds[0, 5, 2] # (3, 2, 4) — shape from the persisted schema
|
|
@@ -173,7 +232,7 @@ batch is the model's call — a plain numpy loop, wherever you need it:
|
|
|
173
232
|
from loaderx.zrecord import Ragged
|
|
174
233
|
|
|
175
234
|
seqs = [np.arange(L, dtype=np.int32) for L in (3, 1, 4, 1, 5)]
|
|
176
|
-
with Ragged.create('tokens', np.int32, ndim=1) as rs:
|
|
235
|
+
with Ragged.create('tokens', np.int32, ndim=1, codec='zstd') as rs:
|
|
177
236
|
rs.append(seqs) # dtype/rank fixed; lengths remain per-record
|
|
178
237
|
rs = Ragged.open('tokens')
|
|
179
238
|
|
|
@@ -260,8 +319,10 @@ warmup belongs outside build or loader benchmark timing.
|
|
|
260
319
|
### Creating containers
|
|
261
320
|
|
|
262
321
|
``Dense.create`` and ``Ragged.create`` return append-only ordered-sequence
|
|
263
|
-
builders. ``
|
|
264
|
-
|
|
322
|
+
builders. The ``codec`` keyword is required: callers must explicitly select
|
|
323
|
+
``"raw"``, ``"zstd"``, or ``"zstd_dict"``. ``append`` is explicit — one input
|
|
324
|
+
batch extends the logical sequence without exposing native physical completion
|
|
325
|
+
order.
|
|
265
326
|
Dense append is synchronous and borrows an already-contiguous ndarray without a
|
|
266
327
|
snapshot copy. Ragged append consumes its iterable once into one owned packed
|
|
267
328
|
buffer, then completes the native append before returning. Nothing is inferred.
|
|
@@ -269,12 +330,13 @@ buffer, then completes the native append before returning. Nothing is inferred.
|
|
|
269
330
|
```python
|
|
270
331
|
from loaderx.zrecord import Dense, Ragged
|
|
271
332
|
|
|
272
|
-
ds = Dense.create('mnist/x', dtype=np.uint8, item_shape=(28, 28),
|
|
333
|
+
ds = Dense.create('mnist/x', dtype=np.uint8, item_shape=(28, 28),
|
|
334
|
+
codec='zstd', data_shards=4)
|
|
273
335
|
ds.append(images[i:i + 1024]) # synchronous native batch; returns None
|
|
274
336
|
ds.append(single_image[None]) # one sample is batch_size 1 — add the axis yourself
|
|
275
337
|
ds.close() # publish before opening
|
|
276
338
|
|
|
277
|
-
tok = Ragged.create('tokens', dtype=np.int32, ndim=1)
|
|
339
|
+
tok = Ragged.create('tokens', dtype=np.int32, ndim=1, codec='zstd')
|
|
278
340
|
tok.append([seq_a, seq_b, seq_c])
|
|
279
341
|
tok.close()
|
|
280
342
|
|
|
@@ -315,32 +377,19 @@ published without one.
|
|
|
315
377
|
### Codec notes
|
|
316
378
|
|
|
317
379
|
`"zstd"` compresses each record independently with plain zstd (level 3). Use it
|
|
318
|
-
for general-purpose compression
|
|
380
|
+
for general-purpose compression; it is fast and must be selected explicitly.
|
|
319
381
|
|
|
320
382
|
`"zstd_dict"` trains a shared dictionary on a sample of the data before writing
|
|
321
|
-
any record, then compresses every record against it at level
|
|
383
|
+
any record, then compresses every record against it at level 3. The dictionary
|
|
322
384
|
captures structure shared across records that per-record compression cannot see —
|
|
323
|
-
a
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
| tier | dict | sample | tradeoff |
|
|
332
|
-
|------|------|--------|----------|
|
|
333
|
-
| `"fast"` | 32 KiB | 4 MiB | fastest gather and training; ratio barely above `zstd` |
|
|
334
|
-
| `"balanced"` | 128 KiB | 16 MiB | **default** — most of the ratio at a fraction of the gather cost |
|
|
335
|
-
| `"max"` | 1 MiB | 64 MiB | best ratio; slowest gather and training |
|
|
336
|
-
|
|
337
|
-
The sample is the byte budget the dictionary trains on (a strided subset of the
|
|
338
|
-
records), so each tier costs the same training time whatever the record size.
|
|
339
|
-
At realistic image scale (768 KiB records) the tiers converge — on the earlier
|
|
340
|
-
measurement box's structured data `"balanced"` and `"max"` both gather
|
|
341
|
-
~1.6 GiB/s at a 1.74x ratio — because a dictionary is a small fraction of a
|
|
342
|
-
large frame. The tiers still matter at small record sizes, where the dict is
|
|
343
|
-
most of a record and `"max"` trades gather throughput for ratio.
|
|
385
|
+
a useful fit for large corpora of small, similar records such as token sequences
|
|
386
|
+
and image tiles. Plain `"zstd"` or `"raw"` remains the better default for large
|
|
387
|
+
records and small corpora.
|
|
388
|
+
|
|
389
|
+
Dictionary geometry is fixed: `train_dict` trains a dictionary of at most 32 KiB
|
|
390
|
+
from a strided sample bounded at 4 MiB. Real WikiText and MNIST profiling found
|
|
391
|
+
that larger 128 KiB and 1 MiB dictionaries added training and cache cost without
|
|
392
|
+
a stable ratio or gather advantage. There is no dictionary tuning API.
|
|
344
393
|
|
|
345
394
|
`"zstd_dict"` records can only be read from a store that has the dictionary
|
|
346
395
|
(`dict.zr`). The dictionary is loaded on open and shared, lock-free, across all
|
|
@@ -348,7 +397,7 @@ reader threads.
|
|
|
348
397
|
|
|
349
398
|
A dictionary must train on the settled, complete data. :func:`train_dict` is the
|
|
350
399
|
standalone, **manual** training step — a numpy array, an iterable of records, or
|
|
351
|
-
a typed container all train the same
|
|
400
|
+
a typed container all train the same fixed contract — and its bytes are handed to
|
|
352
401
|
a container-writing path via ``dict_bytes``. ``zstd_dict`` never trains by itself: a
|
|
353
402
|
write without a dictionary is an error. A stream cannot train its own
|
|
354
403
|
dictionary, but it can write with one trained on the settled data:
|
|
@@ -358,7 +407,7 @@ from loaderx.utils import train_dict
|
|
|
358
407
|
from loaderx.zrecord import Dense, Ragged
|
|
359
408
|
|
|
360
409
|
# train once on the settled data — a standalone, reusable artifact
|
|
361
|
-
d = train_dict(settled_array
|
|
410
|
+
d = train_dict(settled_array)
|
|
362
411
|
|
|
363
412
|
# then any new store can install it and append explicitly
|
|
364
413
|
with Ragged.create('tokens', np.int32, ndim=1,
|
|
@@ -409,11 +458,11 @@ from loaderx.zrecord import Dense, Ragged
|
|
|
409
458
|
from loaderx.dataloader import DataLoader
|
|
410
459
|
|
|
411
460
|
root = "xsub/train"
|
|
412
|
-
with Dense.create(root + "/joint", joint.dtype, joint.shape[1:]) as s:
|
|
461
|
+
with Dense.create(root + "/joint", joint.dtype, joint.shape[1:], codec="zstd") as s:
|
|
413
462
|
s.append(joint)
|
|
414
|
-
with Dense.create(root + "/label", label.dtype, label.shape[1:]) as s:
|
|
463
|
+
with Dense.create(root + "/label", label.dtype, label.shape[1:], codec="zstd") as s:
|
|
415
464
|
s.append(label)
|
|
416
|
-
with Ragged.create(root + "/token", np.int32, ndim=1) as s:
|
|
465
|
+
with Ragged.create(root + "/token", np.int32, ndim=1, codec="zstd") as s:
|
|
417
466
|
s.append(seqs)
|
|
418
467
|
|
|
419
468
|
streams = {
|
|
@@ -493,7 +542,8 @@ caller's to own and reuse. This is the entire H2D answer — there is no `pin=`
|
|
|
493
542
|
hook or device backend, because the only unified thing a multi-framework loader
|
|
494
543
|
can own is the CPU batch.
|
|
495
544
|
|
|
496
|
-
For practical integration
|
|
545
|
+
For a practical JAX/Flax integration, see the
|
|
546
|
+
**[MNIST layer-representation example](examples/mnist_latent/)**.
|
|
497
547
|
|
|
498
548
|
## Benchmarks
|
|
499
549
|
|
|
@@ -506,12 +556,12 @@ so CFFI, NumPy allocation, and Ragged list/shape reconstruction are timed.
|
|
|
506
556
|
|
|
507
557
|
### Methodology
|
|
508
558
|
|
|
509
|
-
The comparison matrix began as one complete run on a warm page cache.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
559
|
+
The comparison matrix began as one complete run on a warm page cache. Most Store
|
|
560
|
+
matrices and the loader rows were refreshed on 2.3.6 with the default
|
|
561
|
+
`data_shards=4`; the Dense token matrix was refreshed on 2.3.8 after the append
|
|
562
|
+
window increased to 32,768 records. Every workload uses a prepared real source.
|
|
563
|
+
These are not three-run medians: an unexpected result is traced separately
|
|
564
|
+
instead of being hidden by repeated aggregation. Within each store workload every
|
|
515
565
|
backend receives identical source records. Correctness and timing use independent
|
|
516
566
|
deterministic `zsampler` IID streams. Loader backends receive
|
|
517
567
|
the same source and seed but use their own shipped samplers, so their exact
|
|
@@ -530,7 +580,7 @@ operation. Reusable source preparation is outside that timer; in particular,
|
|
|
530
580
|
The measured Store paths are explicit:
|
|
531
581
|
|
|
532
582
|
```text
|
|
533
|
-
write:
|
|
583
|
+
write: source is ready -> writer setup [untimed]
|
|
534
584
|
-> start -> encode/pack -> append/write -> logical finalize -> return -> stop
|
|
535
585
|
-> resource-only cleanup [untimed]
|
|
536
586
|
|
|
@@ -555,8 +605,10 @@ reconstruction are included, while open, close and destruction after return are
|
|
|
555
605
|
not.
|
|
556
606
|
Every backend name states its actual codec; the full default set is required
|
|
557
607
|
rather than silently skipped when a package is missing.
|
|
558
|
-
|
|
559
|
-
|
|
608
|
+
The vision source is the Oxford-IIIT Pet train split prepared by
|
|
609
|
+
`scripts/prepare_vision.py`. Dense uses RGB photographs resized on the short side
|
|
610
|
+
to 256 and center-cropped to `(3, 224, 224)`; Ragged uses the same ordered source
|
|
611
|
+
at native RGB resolution. Both are mmap-loaded uint8 CHW records.
|
|
560
612
|
|
|
561
613
|
**Machine** — one local workstation (AMD Ryzen AI 9 HX PRO 370, 12 cores / 24
|
|
562
614
|
threads):
|
|
@@ -580,75 +632,67 @@ pipeline. Store reads run on the ordinary page cache.
|
|
|
580
632
|
|
|
581
633
|
#### Fixed-Shape Dense
|
|
582
634
|
|
|
583
|
-
Zrecord against array-store alternatives: random batch gather
|
|
584
|
-
|
|
585
|
-
|
|
635
|
+
Zrecord against array-store alternatives: random batch gather over the first
|
|
636
|
+
2,500 Oxford-IIIT Pet train images, batch 256. Every prepared image is
|
|
637
|
+
`uint8[3,224,224]`; `metadata.json` records the source revision, transform,
|
|
638
|
+
decoder versions and logical SHA-256.
|
|
586
639
|
|
|
587
640
|
Fixed-resolution vision records — 147 KiB per record, 36.8 MiB per batch:
|
|
588
641
|
|
|
589
642
|
| backend | logical write | logical gather | krecords/s | p95 | disk | ratio |
|
|
590
643
|
|---|---:|---:|---:|---:|---:|---:|
|
|
591
|
-
| zrecord-zstd |
|
|
592
|
-
| zrecord-zstdict |
|
|
593
|
-
| zrecord-raw |
|
|
594
|
-
| npy-mmap-raw |
|
|
595
|
-
| hdf5-raw |
|
|
596
|
-
| hdf5-gzip |
|
|
597
|
-
| lmdb-raw |
|
|
598
|
-
| arrow-ipc-raw |
|
|
599
|
-
| arrow-ipc-zstd |
|
|
600
|
-
| parquet-raw |
|
|
601
|
-
| parquet-zstd |
|
|
602
|
-
| arrayrecord-raw |
|
|
603
|
-
| arrayrecord-zstd |
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
644
|
+
| zrecord-zstd | 1375 MiB/s | 6020 MiB/s | 41.9 | 6.97 ms | 311.1 MiB | 1.15x |
|
|
645
|
+
| zrecord-zstdict | 1145 MiB/s | 7318 MiB/s | 51.0 | 6.06 ms | 320.1 MiB | 1.12x |
|
|
646
|
+
| zrecord-raw | 5111 MiB/s | 14808 MiB/s | 103.2 | 2.81 ms | 358.9 MiB | 1.00x |
|
|
647
|
+
| npy-mmap-raw | 2023 MiB/s | 4751 MiB/s | 33.1 | 10.46 ms | 358.9 MiB | 1.00x |
|
|
648
|
+
| hdf5-raw | 2310 MiB/s | 1903 MiB/s | 13.3 | 22.33 ms | 359.0 MiB | 1.00x |
|
|
649
|
+
| hdf5-gzip | 41 MiB/s | 213 MiB/s | 1.5 | 193.93 ms | 301.8 MiB | 1.19x |
|
|
650
|
+
| lmdb-raw | 1359 MiB/s | 4120 MiB/s | 28.7 | 10.10 ms | 361.4 MiB | 0.99x |
|
|
651
|
+
| arrow-ipc-raw | 1117 MiB/s | 3439 MiB/s | 24.0 | 12.89 ms | 358.9 MiB | 1.00x |
|
|
652
|
+
| arrow-ipc-zstd | 223 MiB/s | 97 MiB/s | 0.7 | 399.21 ms | 305.9 MiB | 1.17x |
|
|
653
|
+
| parquet-raw | 1237 MiB/s | 454 MiB/s | 3.2 | 85.72 ms | 358.9 MiB | 1.00x |
|
|
654
|
+
| parquet-zstd | 215 MiB/s | 80 MiB/s | 0.6 | 480.45 ms | 305.9 MiB | 1.17x |
|
|
655
|
+
| arrayrecord-raw | 1852 MiB/s | 2092 MiB/s | 14.6 | 20.84 ms | 359.2 MiB | 1.00x |
|
|
656
|
+
| arrayrecord-zstd | 219 MiB/s | 1779 MiB/s | 12.4 | 23.15 ms | 320.1 MiB | 1.12x |
|
|
657
|
+
|
|
658
|
+
At 147 KiB per record, Zrecord-raw reaches 14.5 GiB/s and is 3.1x npy-mmap-raw.
|
|
659
|
+
Decoded photographs have little remaining redundancy: plain zstd reduces them
|
|
660
|
+
only 1.15x, while dictionary mode falls to 1.12x. This is
|
|
661
|
+
why large real images should use plain zstd or raw. LMDB and Arrow
|
|
609
662
|
IPC are competitive raw record
|
|
610
663
|
stores, while codecs tied to whole IPC batches or Parquet row groups pay read
|
|
611
664
|
amplification on random gathers. Dense demonstrates that
|
|
612
665
|
typed record ownership and per-record compression do not turn fixed tensors
|
|
613
666
|
into an object-store slow path.
|
|
614
667
|
|
|
615
|
-
####
|
|
668
|
+
#### Native-Resolution Ragged
|
|
616
669
|
|
|
617
|
-
This workload contains 2,500
|
|
618
|
-
|
|
619
|
-
|
|
670
|
+
This workload contains the first 2,500 native-resolution Oxford-IIIT Pet CHW RGB
|
|
671
|
+
images. Height is 108..2606 (median 375) and width is 117..3264 (median 500),
|
|
672
|
+
totaling 1252.3 MiB of logical uint8 payload. Each of 50 random
|
|
620
673
|
batches contains 256 records. Every backend persists payload plus exact shape
|
|
621
674
|
and must return an ordered `list[np.ndarray]` of `(3, H, W)` arrays; a flat byte
|
|
622
675
|
list or a one-dimensional variable-length abstraction is not enough.
|
|
623
676
|
|
|
624
677
|
| backend | logical write | logical gather | krecords/s | p95 | disk | ratio |
|
|
625
678
|
|---|---:|---:|---:|---:|---:|---:|
|
|
626
|
-
| zrecord-zstd |
|
|
627
|
-
| zrecord-zstdict |
|
|
628
|
-
| zrecord-raw |
|
|
629
|
-
| hdf5-raw |
|
|
630
|
-
|
|
|
631
|
-
|
|
|
632
|
-
|
|
|
633
|
-
|
|
|
634
|
-
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
logical payload while reducing the corpus to 26.9 MiB. HDF5, Arrow IPC, Parquet,
|
|
644
|
-
ArrayRecord and TileDB
|
|
645
|
-
show the same framework/codec tradeoffs in both tables; compressed batch, chunk
|
|
646
|
-
and row-group formats pay read amplification on random records.
|
|
647
|
-
|
|
648
|
-
The shared generator makes compression ratios directly comparable across
|
|
649
|
-
contracts: Zrecord zstd is 14.69x Dense versus 15.48x Ragged, and zstdict is
|
|
650
|
-
22.10x versus 22.97x. The remaining difference comes from the H/W distribution
|
|
651
|
-
and Ragged shape metadata, not a different image entropy model.
|
|
679
|
+
| zrecord-zstd | 852 MiB/s | 4546 MiB/s | 9.1 | 49.35 ms | 1032.2 MiB | 1.21x |
|
|
680
|
+
| zrecord-zstdict | 705 MiB/s | 4493 MiB/s | 8.9 | 49.94 ms | 1032.9 MiB | 1.21x |
|
|
681
|
+
| zrecord-raw | 2080 MiB/s | 13367 MiB/s | 26.7 | 13.74 ms | 1252.4 MiB | 1.00x |
|
|
682
|
+
| hdf5-raw | 1909 MiB/s | 2302 MiB/s | 4.6 | 69.05 ms | 1253.1 MiB | 1.00x |
|
|
683
|
+
| lmdb-raw | 1818 MiB/s | 8758 MiB/s | 17.5 | 23.61 ms | 1257.0 MiB | 1.00x |
|
|
684
|
+
| arrow-ipc-raw | 1346 MiB/s | 4567 MiB/s | 9.1 | 41.32 ms | 1252.4 MiB | 1.00x |
|
|
685
|
+
| parquet-raw | 722 MiB/s | 513 MiB/s | 1.0 | 283.13 ms | 1252.4 MiB | 1.00x |
|
|
686
|
+
| arrayrecord-raw | 1644 MiB/s | 2753 MiB/s | 5.5 | 64.37 ms | 1253.0 MiB | 1.00x |
|
|
687
|
+
| arrayrecord-zstd | 188 MiB/s | 2008 MiB/s | 4.0 | 95.29 ms | 1054.6 MiB | 1.19x |
|
|
688
|
+
|
|
689
|
+
Zrecord-raw is 1.5x LMDB and 2.9x Arrow IPC in logical gather. Plain and
|
|
690
|
+
dictionary zstd both reach 1.21x, confirming that dictionary mode is not useful
|
|
691
|
+
for these large photographs. The Ragged matrix is intentionally asymmetric:
|
|
692
|
+
HDF5 gzip, Arrow IPC zstd and Parquet zstd adapters are not implemented because
|
|
693
|
+
the real 256-record batch took 1.1–1.7 seconds; TileDB variable queries took
|
|
694
|
+
8.6–9.6 seconds and the backend was removed entirely. ArrayRecord zstd remains
|
|
695
|
+
because its batch p95 is 95 ms.
|
|
652
696
|
|
|
653
697
|
### Small Token Records
|
|
654
698
|
|
|
@@ -667,19 +711,20 @@ accumulate at least two seconds.
|
|
|
667
711
|
|
|
668
712
|
| backend | logical write | logical gather | krecords/s | p95 | disk | ratio |
|
|
669
713
|
|---|---:|---:|---:|---:|---:|---:|
|
|
670
|
-
| zrecord-zstd |
|
|
671
|
-
| zrecord-zstdict |
|
|
672
|
-
| zrecord-raw |
|
|
673
|
-
| npy-mmap-raw |
|
|
674
|
-
| lmdb-raw |
|
|
675
|
-
| arrow-ipc-raw |
|
|
676
|
-
| arrayrecord-raw |
|
|
677
|
-
| arrayrecord-zstd |
|
|
678
|
-
|
|
679
|
-
The contiguous NumPy baseline is strongest when the whole corpus is
|
|
680
|
-
typed matrix. Zrecord-raw reaches 3.
|
|
681
|
-
record semantics
|
|
682
|
-
|
|
714
|
+
| zrecord-zstd | 1060 MiB/s | 2149 MiB/s | 1100.2 | 0.33 ms | 193.2 MiB | 2.02x |
|
|
715
|
+
| zrecord-zstdict | 1435 MiB/s | 2478 MiB/s | 1268.7 | 0.28 ms | 168.5 MiB | 2.32x |
|
|
716
|
+
| zrecord-raw | 5535 MiB/s | 7056 MiB/s | 3612.5 | 0.10 ms | 393.7 MiB | 0.99x |
|
|
717
|
+
| npy-mmap-raw | 1771 MiB/s | 10306 MiB/s | 5276.6 | 0.07 ms | 390.6 MiB | 1.00x |
|
|
718
|
+
| lmdb-raw | 692 MiB/s | 1133 MiB/s | 580.3 | 0.61 ms | 786.3 MiB | 0.50x |
|
|
719
|
+
| arrow-ipc-raw | 1330 MiB/s | 213 MiB/s | 109.2 | 4.09 ms | 390.8 MiB | 1.00x |
|
|
720
|
+
| arrayrecord-raw | 887 MiB/s | 158 MiB/s | 80.8 | 5.16 ms | 401.4 MiB | 0.97x |
|
|
721
|
+
| arrayrecord-zstd | 123 MiB/s | 134 MiB/s | 68.5 | 4.69 ms | 201.3 MiB | 1.94x |
|
|
722
|
+
|
|
723
|
+
The contiguous NumPy baseline is strongest for gather when the whole corpus is
|
|
724
|
+
one fixed typed matrix. Zrecord-raw reaches 3.61 Mrecords/s while retaining
|
|
725
|
+
independent record semantics and writes 3.1x faster than npy-mmap-raw;
|
|
726
|
+
dictionary zstd writes 35% faster than plain zstd, uses 13% less disk and gathers
|
|
727
|
+
15% faster in this pass. LMDB's B-tree/page overhead is visible in both throughput
|
|
683
728
|
and disk.
|
|
684
729
|
|
|
685
730
|
#### Variable Token Sequences
|
|
@@ -691,18 +736,18 @@ with exact `int32` values and original one-dimensional shapes.
|
|
|
691
736
|
|
|
692
737
|
| backend | logical write | logical gather | krecords/s | p95 | disk | ratio |
|
|
693
738
|
|---|---:|---:|---:|---:|---:|---:|
|
|
694
|
-
| zrecord-zstd |
|
|
695
|
-
| zrecord-zstdict |
|
|
696
|
-
| zrecord-raw |
|
|
697
|
-
| lmdb-raw |
|
|
698
|
-
| arrow-ipc-raw |
|
|
699
|
-
| arrayrecord-raw |
|
|
700
|
-
| arrayrecord-zstd |
|
|
739
|
+
| zrecord-zstd | 268 MiB/s | 337 MiB/s | 637.3 | 0.52 ms | 67.4 MiB | 1.57x |
|
|
740
|
+
| zrecord-zstdict | 368 MiB/s | 367 MiB/s | 692.8 | 0.49 ms | 53.0 MiB | 2.00x |
|
|
741
|
+
| zrecord-raw | 682 MiB/s | 434 MiB/s | 819.1 | 0.41 ms | 110.5 MiB | 0.96x |
|
|
742
|
+
| lmdb-raw | 316 MiB/s | 108 MiB/s | 204.2 | 1.53 ms | 151.8 MiB | 0.70x |
|
|
743
|
+
| arrow-ipc-raw | 317 MiB/s | 42 MiB/s | 80.3 | 4.65 ms | 109.1 MiB | 0.97x |
|
|
744
|
+
| arrayrecord-raw | 291 MiB/s | 28 MiB/s | 52.7 | 7.63 ms | 118.0 MiB | 0.90x |
|
|
745
|
+
| arrayrecord-zstd | 59 MiB/s | 29 MiB/s | 55.2 | 5.71 ms | 76.0 MiB | 1.39x |
|
|
701
746
|
|
|
702
747
|
Here the record contract, not bulk byte bandwidth, is the useful scale.
|
|
703
|
-
Zrecord's three codecs return
|
|
704
|
-
|
|
705
|
-
this pass.
|
|
748
|
+
Zrecord's three codecs return 637–819 krecords/s with 0.41–0.52 ms p95.
|
|
749
|
+
Dictionary zstd writes 37% faster than plain zstd, uses 21% less disk and gathers
|
|
750
|
+
9% faster in this pass.
|
|
706
751
|
|
|
707
752
|
### Sampler
|
|
708
753
|
|
|
@@ -723,7 +768,7 @@ a 1.87–7.96x margin across batch sizes.
|
|
|
723
768
|
|
|
724
769
|
The full input pipeline comparison (sample, fetch, collate, hand over a batch)
|
|
725
770
|
uses exactly the Dense vision source above: 2,500 `(3,224,224)` uint8
|
|
726
|
-
records from
|
|
771
|
+
Oxford-IIIT Pet records from the prepared mmap corpus, 4 high-level workers, and batch 256
|
|
727
772
|
(36.8 MiB). After warmup, throughput and memory are collected during one
|
|
728
773
|
200-batch qualitative pass. `peak PSS` sums proportional
|
|
729
774
|
set size across the process tree, apportioning mapped shared and copy-on-write
|
|
@@ -747,19 +792,19 @@ and Grain reads ArrayRecord.
|
|
|
747
792
|
|
|
748
793
|
| loader | model | storage | batches/s | p95 | steady PSS | peak PSS | peak RSS |
|
|
749
794
|
|---|---|---|---:|---:|---:|---:|---:|
|
|
750
|
-
| **loaderx** | threads | zrecord-zstd |
|
|
751
|
-
| loaderx-raw | threads | zrecord-raw |
|
|
752
|
-
| torch | fork | npy-mmap-raw |
|
|
753
|
-
| torch-spawn | spawn | npy-mmap-raw |
|
|
754
|
-
| grain | processes | arrayrecord-zstd |
|
|
795
|
+
| **loaderx** | threads | zrecord-zstd | 129.2 | 10.68 ms | 641 MiB | 666 MiB | 670 MiB |
|
|
796
|
+
| loaderx-raw | threads | zrecord-raw | 226.7 | 7.97 ms | 668 MiB | 669 MiB | 672 MiB |
|
|
797
|
+
| torch | fork | npy-mmap-raw | 91.7 | 40.30 ms | 1403 MiB | 1597 MiB | 3845 MiB |
|
|
798
|
+
| torch-spawn | spawn | npy-mmap-raw | 115.2 | 30.41 ms | 2632 MiB | 2710 MiB | 4700 MiB |
|
|
799
|
+
| grain | processes | arrayrecord-zstd | 43.0 | 101.51 ms | 1706 MiB | 1770 MiB | 1892 MiB |
|
|
755
800
|
|
|
756
801
|
At 36.8 MiB per batch the per-batch gather dominates the tiny sampler cost, and
|
|
757
802
|
the transform threads overlap Python-side collation with the next gather. The
|
|
758
803
|
memory is the source, Zrecord container and bounded in-flight batches. loaderx prefetches in
|
|
759
804
|
threads inside one process, so workers share one interpreter, one NumPy runtime
|
|
760
805
|
and one set of gather buffers. With source geometry and entropy held constant,
|
|
761
|
-
raw is 1.
|
|
762
|
-
Torch spawn and 3.
|
|
806
|
+
raw is 1.75x compressed loaderx; compressed loaderx is 1.41x Torch fork, 1.12x
|
|
807
|
+
Torch spawn and 3.00x Grain, while raw is 2.47x, 1.97x and 5.27x faster.
|
|
763
808
|
Torch's aggregate RSS is high because
|
|
764
809
|
Linux fork mappings are counted repeatedly; it is not a total-memory ratio
|
|
765
810
|
against Zrecord's unaccounted page cache. The explicit `torch-spawn` row removes
|
|
@@ -768,19 +813,19 @@ not copy the full corpus into every worker; a Windows Dataset holding Python
|
|
|
768
813
|
lists or in-memory arrays would be a different, deliberately harsher workload.
|
|
769
814
|
|
|
770
815
|
The Torch-only worker sweep runs each count once. Worker 0 is an in-process
|
|
771
|
-
baseline (
|
|
816
|
+
baseline (74.8 and 79.8 batches/s with 1413/1415 MiB peak PSS in the two equivalent
|
|
772
817
|
rows), so the process-context comparison starts at one worker:
|
|
773
818
|
|
|
774
819
|
| workers | fork batches/s | fork peak PSS | fork peak RSS | spawn batches/s | spawn peak PSS | spawn peak RSS |
|
|
775
820
|
|---:|---:|---:|---:|---:|---:|---:|
|
|
776
|
-
| 1 |
|
|
777
|
-
| 2 |
|
|
778
|
-
| 4 |
|
|
779
|
-
| 8 |
|
|
780
|
-
|
|
781
|
-
Spawn peak PSS grows from
|
|
782
|
-
while fork grows from
|
|
783
|
-
workers spawn uses 2.
|
|
821
|
+
| 1 | 49.3 | 1428 MiB | 1733 MiB | 46.8 | 1711 MiB | 1950 MiB |
|
|
822
|
+
| 2 | 78.2 | 1512 MiB | 2481 MiB | 79.0 | 2068 MiB | 2893 MiB |
|
|
823
|
+
| 4 | 111.5 | 1614 MiB | 3898 MiB | 113.1 | 2729 MiB | 4710 MiB |
|
|
824
|
+
| 8 | 123.2 | 1802 MiB | 6579 MiB | 124.2 | 4039 MiB | 8189 MiB |
|
|
825
|
+
|
|
826
|
+
Spawn peak PSS grows from 1711 to 4039 MiB as workers rise from one to eight,
|
|
827
|
+
while fork grows from 1428 to 1802 MiB because it retains COW sharing. At eight
|
|
828
|
+
workers spawn uses 2.24x fork's peak PSS and throughput has already flattened.
|
|
784
829
|
This demonstrates no-fork memory pressure; it is not labeled OOM because this
|
|
785
830
|
31 GiB machine completed the run. Fork aggregate RSS grows faster because Linux
|
|
786
831
|
counts shared/COW mappings in every process, so RSS is diagnostic rather than
|
|
@@ -789,20 +834,19 @@ physical memory.
|
|
|
789
834
|
**CPU-heavy transform solutions.** The same Python per-sample transform exposes
|
|
790
835
|
the GIL bottleneck on standard CPython. Numba is an explicit solution, not the
|
|
791
836
|
default: `--transform numba-nogil` compiles the equivalent batch transform with
|
|
792
|
-
`nogil=True`. The other explicit solution runs the Python transform on
|
|
793
|
-
free-threaded CPython. Numba compilation is warmed before timing
|
|
794
|
-
|
|
795
|
-
no separate no-GIL Store implementation; the Store table above applies to both.
|
|
837
|
+
`nogil=True`. The other explicit solution runs the unchanged Python transform on
|
|
838
|
+
free-threaded CPython. Numba compilation is warmed before timing; both
|
|
839
|
+
interpreters use NumPy 2.4.6 and the same prepared real corpus.
|
|
796
840
|
|
|
797
841
|
| loader | GIL Python | GIL + Numba nogil | free-threaded Python | Numba gain | free-threaded gain |
|
|
798
842
|
|---|---:|---:|---:|---:|---:|
|
|
799
|
-
| **loaderx** |
|
|
800
|
-
| loaderx-raw |
|
|
843
|
+
| **loaderx** | 50.2 batches/s | 101.5 batches/s | 86.2 batches/s | **2.02x** | **1.72x** |
|
|
844
|
+
| loaderx-raw | 57.7 batches/s | 130.8 batches/s | 98.4 batches/s | **2.27x** | **1.71x** |
|
|
801
845
|
|
|
802
|
-
Peak PSS for compressed/raw was
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
846
|
+
Peak PSS for compressed/raw was 878/883 MiB with GIL Python, 942/967 MiB with
|
|
847
|
+
Numba, and 872/900 MiB with free-threaded Python. These are two deployment
|
|
848
|
+
solutions to the transform bottleneck, not claims that Store itself was
|
|
849
|
+
optimized for either runtime.
|
|
806
850
|
|
|
807
851
|
**Conclusion** — why the numbers look like this.
|
|
808
852
|
|
|
@@ -827,14 +871,15 @@ specialization for compression and a complete variable-shape persistence model.
|
|
|
827
871
|
"storage plus a codec": the layout, the multi-core decompress and the GIL-free
|
|
828
872
|
copy are one path, so turning compression on costs part of a margin, not an
|
|
829
873
|
order of magnitude. The ratio is the data, not the
|
|
830
|
-
format: in the current Dense
|
|
831
|
-
|
|
874
|
+
format: in the current real-photograph Dense workload, plain zstd reaches only
|
|
875
|
+
1.15x and the fixed dictionary reaches 1.12x. Dictionary mode is for repeated
|
|
876
|
+
small records, not a universal higher-ratio setting.
|
|
832
877
|
|
|
833
878
|
**Loader results combine architecture and storage.** loaderx uses threads and
|
|
834
879
|
never ends an epoch, so a step pays no IPC and never waits on an epoch boundary;
|
|
835
880
|
torch uses finite shuffled epochs, worker processes and shared-memory handoff.
|
|
836
|
-
Here compressed loaderx is 1.
|
|
837
|
-
raw loaderx is
|
|
881
|
+
Here compressed loaderx is 1.41x Torch fork, 1.12x Torch spawn and 3.00x Grain;
|
|
882
|
+
raw loaderx is 2.47x, 1.97x and 5.27x faster, respectively.
|
|
838
883
|
Storage also differs per loader — each reads from what it was
|
|
839
884
|
built for — so the loader table is a different comparison from either store
|
|
840
885
|
table, not a rerun.
|
|
@@ -853,99 +898,18 @@ views into one batch allocation, while most byte-store adapters return
|
|
|
853
898
|
independent copies. This is a single benchmark run, while each Store read path
|
|
854
899
|
accumulates at least two timed seconds —
|
|
855
900
|
the µs-scale sampler timings and the loader `batches/s` fluctuate with box load
|
|
856
|
-
(on these 12 cores the compressed loader trails the raw one
|
|
901
|
+
(on these 12 cores the compressed loader trails the raw one materially), so
|
|
857
902
|
treat the absolute numbers as ballpark and the cross-backend margins as the
|
|
858
903
|
signal.
|
|
859
904
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
```bash
|
|
863
|
-
.venv/bin/python scripts/bench_dense.py
|
|
864
|
-
.venv/bin/python scripts/bench_ragged.py
|
|
865
|
-
|
|
866
|
-
.venv/bin/python scripts/prepare_tokens.py wiki.train.tokens /tmp/wikitext-gpt2
|
|
867
|
-
.venv/bin/python scripts/bench_dense.py --workload tokens \
|
|
868
|
-
--token-corpus /tmp/wikitext-gpt2 --records 200000 --batches 100
|
|
869
|
-
.venv/bin/python scripts/bench_ragged.py --workload tokens \
|
|
870
|
-
--token-corpus /tmp/wikitext-gpt2 --records 200000 --batches 100
|
|
871
|
-
|
|
872
|
-
.venv/bin/python scripts/bench.py sampler
|
|
873
|
-
.venv/bin/python scripts/bench.py loader \
|
|
874
|
-
--only loaderx,loaderx-raw,torch,torch-spawn,grain --workers 4
|
|
875
|
-
.venv/bin/python scripts/bench.py loader --only torch,torch-spawn \
|
|
876
|
-
--workers 0,1,2,4,8
|
|
877
|
-
.venv/bin/python scripts/bench.py loader \
|
|
878
|
-
--only loaderx,loaderx-raw --workers 4 --transform python-loop
|
|
879
|
-
.venv/bin/python scripts/bench.py loader --only loaderx,loaderx-raw \
|
|
880
|
-
--workers 4 --transform numba-nogil
|
|
881
|
-
|
|
882
|
-
.venv-t/bin/python scripts/bench.py loader --only loaderx,loaderx-raw \
|
|
883
|
-
--workers 4 --transform python-loop
|
|
884
|
-
```
|
|
905
|
+
## Real-data verification
|
|
885
906
|
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
The focused token defaults omit formats that are already represented in the
|
|
893
|
-
larger vision matrix; `--only` can select any registered backend explicitly.
|
|
894
|
-
The loader rows used Numba 0.67.0, Torch 2.13.0 and Grain 0.2.18; all benchmark dependencies
|
|
895
|
-
are pinned in `scripts/requirements-bench.txt`. Temporary stores used the ordinary
|
|
896
|
-
disk-backed `/tmp` filesystem, not `/dev/shm`.
|
|
897
|
-
|
|
898
|
-
## Real-data verification: NTU RGB-D skeletons
|
|
899
|
-
|
|
900
|
-
The vision tables above are synthetic; the token tables use real WikiText-103.
|
|
901
|
-
As a separate historical ground-truth check,
|
|
902
|
-
loaderx was run end to end on **NTU RGB-D skeleton data** — 114,480 raw `.skeleton` files,
|
|
903
|
-
120 action classes, 25 joints — processed into the ST-GCN `N C T V M` layout
|
|
904
|
-
(per-sample `(3, 300, 25, 2)` float32) for the `xsub`/`xview` protocols. The
|
|
905
|
-
`.npy` outputs of the standard preprocessing pipeline were treated as ground
|
|
906
|
-
truth. This verification was not rerun with the synthetic benchmarks above;
|
|
907
|
-
its throughput is retained as a separate historical 12-core result.
|
|
908
|
-
|
|
909
|
-
**Correctness — the read path is bit-exact against the ground truth:**
|
|
910
|
-
|
|
911
|
-
* Full scan of all **228,356 records** (joint float32 + label int64, all four
|
|
912
|
-
splits) through `Dense`: byte-for-byte identical to the reference npy.
|
|
913
|
-
* A `DataLoader` over joint + label + an index stream, run under all three
|
|
914
|
-
sampler modes (`sequential`, `iid`, `cyclic`): every received batch is
|
|
915
|
-
bit-exact to the ground truth at its own declared indices, and the streams
|
|
916
|
-
stay index-aligned.
|
|
917
|
-
* Sampler semantics hold on real index spaces: `sequential` walks in order,
|
|
918
|
-
`cyclic` draws a full cycle without replacement, `iid` is deterministic per
|
|
919
|
-
seed.
|
|
920
|
-
|
|
921
|
-
**Storage — zstd on this data:**
|
|
922
|
-
|
|
923
|
-
| store | on disk | ratio |
|
|
924
|
-
|-----------------------|---------|-------|
|
|
925
|
-
| npy (raw float32) | 6.4 GB | 1.00x |
|
|
926
|
-
| zrecord raw | 6.86 GB | 1.00x |
|
|
927
|
-
| zrecord zstd | 0.79 GB | 8.66x |
|
|
928
|
-
| zrecord zstd_dict | 0.75 GB | 9.13x |
|
|
929
|
-
|
|
930
|
-
Sizes above are for one split (`xview/val`, 38,132 records); across all four
|
|
931
|
-
splits the zstd `joint` stores total 4.97 GB against 41 GB of raw npy (~8x).
|
|
932
|
-
|
|
933
|
-
**Throughput** (180 KB per record, warm page cache, 12 physical cores):
|
|
934
|
-
|
|
935
|
-
| path | throughput |
|
|
936
|
-
|-------------------------------------|-----------|
|
|
937
|
-
| random-batch gather, zstd store | 4.1–4.5 GiB/s |
|
|
938
|
-
| same, npy-mmap fancy indexing | 0.6–1.3 GiB/s |
|
|
939
|
-
| DataLoader, 4 prefetch threads | 5.7–6.6 GiB/s (123–144 batches/s) |
|
|
940
|
-
|
|
941
|
-
zstd decompression reads ~8x fewer bytes than raw storage, so the compressed
|
|
942
|
-
store gathers *faster* than the raw one (zstd 4587 MiB/s vs raw 1792 MiB/s on
|
|
943
|
-
the same split).
|
|
944
|
-
|
|
945
|
-
**The npy intermediate is optional.** Parse the skeleton files in parallel and
|
|
946
|
-
feed each fixed-shape ndarray produced by the parser directly to
|
|
947
|
-
`Dense.append`. This writes the store in one pass with no npy staging or
|
|
948
|
-
second read; zrecord bounds its compression working memory independently.
|
|
907
|
+
Production dataset-specific preprocessing and verification remain in the
|
|
908
|
+
**[DataPipe](https://codeberg.org/eoelab/DataPipe)** repository. The built-in
|
|
909
|
+
converter covers standardized Hugging Face datasets; DataPipe handles sources
|
|
910
|
+
without a common remote protocol and implements derived modalities as loader
|
|
911
|
+
transforms without NumPy dump intermediates. Oxford-IIIT Pet is only the shared
|
|
912
|
+
benchmark fixture.
|
|
949
913
|
|
|
950
914
|
## Current Limitations
|
|
951
915
|
* Single-host only; multi-host training is not supported.
|
|
@@ -963,10 +927,6 @@ second read; zrecord bounds its compression working memory independently.
|
|
|
963
927
|
zig build # host shared objects, into loaderx/lib/
|
|
964
928
|
zig build test # native store suite, in both Debug and ReleaseFast
|
|
965
929
|
python3 scripts/test_loaderx.py # Python integration suite against the real build
|
|
966
|
-
uv pip install --python .venv/bin/python -r scripts/requirements-bench.txt
|
|
967
|
-
.venv/bin/python scripts/bench_dense.py # fixed-shape store comparison
|
|
968
|
-
.venv/bin/python scripts/bench_ragged.py # variable-length store comparison
|
|
969
|
-
.venv/bin/python scripts/bench.py # machine, sampler, and dense loader layers
|
|
970
930
|
```
|
|
971
931
|
|
|
972
932
|
The Zig side is tested for behaviour only; throughput is measured from Python,
|
|
@@ -1089,7 +1049,7 @@ defend against bypassing the public Python API do not belong in zrecord.
|
|
|
1089
1049
|
|-------|-----------|----------------------------------------|
|
|
1090
1050
|
| 0 | raw | none |
|
|
1091
1051
|
| 1 | zstd | zstd (plain, level 3) |
|
|
1092
|
-
| 2 | zstdict | zstd with a trained dictionary (level
|
|
1052
|
+
| 2 | zstdict | zstd with a trained dictionary (level 3) |
|
|
1093
1053
|
```
|
|
1094
1054
|
|
|
1095
1055
|
7. Compression is transparent to the client:
|
|
@@ -1108,10 +1068,10 @@ defend against bypassing the public Python API do not belong in zrecord.
|
|
|
1108
1068
|
record is still independent, random access is unchanged — but the
|
|
1109
1069
|
dictionary carries the structure shared across records, which per-record
|
|
1110
1070
|
compression cannot see. On many small, similar records (image tiles, token
|
|
1111
|
-
sequences) this
|
|
1112
|
-
|
|
1113
|
-
open and shared, lock-free, across all reader
|
|
1114
|
-
|
|
1071
|
+
sequences) this can be a large win. Decoded real photographs are a useful
|
|
1072
|
+
counterexample where plain zstd or raw is the better fit. The 32 KiB
|
|
1073
|
+
dictionary is loaded once on open and shared, lock-free, across all reader
|
|
1074
|
+
threads.
|
|
1115
1075
|
* A `zstd_dict` store needs its dictionary to read every record; a `raw` or
|
|
1116
1076
|
`zstd` store rejects an unexpected dictionary as malformed state.
|
|
1117
1077
|
|