datashoal 0.1.0__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 (34) hide show
  1. datashoal-0.1.0/PKG-INFO +189 -0
  2. datashoal-0.1.0/README.md +181 -0
  3. datashoal-0.1.0/build_backend.py +77 -0
  4. datashoal-0.1.0/datashoal/__init__.py +9 -0
  5. datashoal-0.1.0/datashoal/_blake3.py +53 -0
  6. datashoal-0.1.0/datashoal/_compact.py +123 -0
  7. datashoal-0.1.0/datashoal/_compat_datasets.py +7 -0
  8. datashoal-0.1.0/datashoal/_compat_hub.py +7 -0
  9. datashoal-0.1.0/datashoal/_compat_safetensors.py +78 -0
  10. datashoal-0.1.0/datashoal/_gear.py +73 -0
  11. datashoal-0.1.0/datashoal/_jit.py +176 -0
  12. datashoal-0.1.0/datashoal/_mapped.py +151 -0
  13. datashoal-0.1.0/datashoal/_parquet_codec.py +137 -0
  14. datashoal-0.1.0/datashoal/_torch_tensors.py +127 -0
  15. datashoal-0.1.0/datashoal/_xet_upload.py +140 -0
  16. datashoal-0.1.0/datashoal/api.py +301 -0
  17. datashoal-0.1.0/datashoal/arrow.py +206 -0
  18. datashoal-0.1.0/datashoal/dataset.py +233 -0
  19. datashoal-0.1.0/datashoal/hf_compat.py +284 -0
  20. datashoal-0.1.0/datashoal/hub.py +312 -0
  21. datashoal-0.1.0/datashoal/modelscope.py +173 -0
  22. datashoal-0.1.0/datashoal/modelscope_compat.py +30 -0
  23. datashoal-0.1.0/datashoal/native/codec.c +434 -0
  24. datashoal-0.1.0/datashoal/native/compact.h +178 -0
  25. datashoal-0.1.0/datashoal/native/parquet.h +898 -0
  26. datashoal-0.1.0/datashoal/native/safetensors.h +215 -0
  27. datashoal-0.1.0/datashoal/native/unicode.h +135 -0
  28. datashoal-0.1.0/datashoal/parquet.py +814 -0
  29. datashoal-0.1.0/datashoal/safetensors.py +599 -0
  30. datashoal-0.1.0/datashoal/tensor_layout.py +85 -0
  31. datashoal-0.1.0/datashoal/torch_ranges.py +426 -0
  32. datashoal-0.1.0/datashoal/wire.py +8 -0
  33. datashoal-0.1.0/datashoal/xet.py +196 -0
  34. datashoal-0.1.0/pyproject.toml +14 -0
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.1
2
+ Name: datashoal
3
+ Version: 0.1.0
4
+ Summary: Cache-first datasets and model artifacts with native Xet transfers
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: logbar>=0.4.16
7
+ Description-Content-Type: text/markdown
8
+
9
+ <!-- SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors -->
10
+
11
+ <h1 align="center"><img src="https://raw.githubusercontent.com/ModelCloud/DataShoal/main/assets/datashoal.png" width="520" alt="DataShoal"></h1>
12
+
13
+ DataShoal is a small Python library for loading datasets and reading, writing and streaming SafeTensors checkpoints. Use it to sample calibration rows for GPT-QModel or read individual weights from a local file or your Hugging Face or ModelScope cache. PyTorch is optional. **By default, `load()` makes zero network requests.**
14
+
15
+ [Documentation wiki](https://github.com/ModelCloud/DataShoal/wiki) · [Python API](https://github.com/ModelCloud/DataShoal/wiki/API-Reference) · [Native ABI](https://github.com/ModelCloud/DataShoal/wiki/Native-Extension-ABI) · [Quickstart](https://github.com/ModelCloud/DataShoal/wiki/Installation-and-Quickstart)
16
+
17
+ ## Features
18
+
19
+ - **Stream and sample.** Read JSON, JSONL, CSV, text, Parquet and supported Arrow streams. Filter, transform, batch or sample rows while keeping nested chat messages and token IDs intact.
20
+ - **Stay offline by default.** Reuse completed files from your existing cache. Pass `download=True` to allow a fetch. DataShoal verifies new artifact downloads before publishing them to the cache.
21
+ - **Keep the install small.** LogBar is the only required package. DataShoal handles calibration and artifact transfers without installing NumPy, pandas, PyArrow, HF Datasets or the Hub SDK.
22
+ - **Read and write Parquet directly.** Select just the columns you need. Frequently used codecs compile locally on first use; a Python fallback runs when a compiler is unavailable.
23
+ - **Read and write SafeTensors.** Inspect shards, stream weights, or copy selected rows into a new checkpoint. With PyTorch installed, index several shards and load just the weights or rows your model needs. [SafeTensors guide](https://github.com/ModelCloud/DataShoal/wiki/SafeTensors)
24
+ - **Use threads with the GIL disabled.** Independent readers can run concurrently on free-threaded CPython. Threads sharing one iterator divide its rows between them.
25
+ - **Work with model hubs.** Download files or snapshots from Hugging Face and ModelScope, upload to Hugging Face using native Xet support, or opt into HF-compatible imports for supported downstream consumers.
26
+
27
+ ## Usage
28
+
29
+ Install from GitHub with Python 3.11 or newer:
30
+
31
+ ```sh
32
+ python -m pip install git+https://github.com/ModelCloud/DataShoal.git
33
+ ```
34
+
35
+ ### 1. Preview a local dataset
36
+
37
+ Given a local JSONL file with one record per line, read its first three rows:
38
+
39
+ ```python
40
+ from datashoal import load
41
+
42
+ rows = load("train.jsonl", type="dataset")
43
+ print(rows.take(3))
44
+ ```
45
+
46
+ ### 2. Write and read a SafeTensors checkpoint
47
+
48
+ Save two weights from a Python buffer, then read them back. PyTorch is optional.
49
+
50
+ ```python
51
+ from struct import pack, unpack
52
+ from datashoal import SafeTensors as st
53
+
54
+ scale = st.wire.TensorData("F32", (2,), pack("<2f", 1.25, 2.5))
55
+ st.save("example.safetensors", {"scale": scale})
56
+
57
+ with st.load("example.safetensors") as archive:
58
+ assert archive.wire.tensors["scale"].shape == (2,)
59
+ assert unpack("<2f", archive.read("scale")) == (1.25, 2.5)
60
+ ```
61
+
62
+ For large weights, iterate over `archive.chunks("scale")`. With PyTorch installed, `archive.torch("scale")` returns a writable tensor. [SafeTensors guide](https://github.com/ModelCloud/DataShoal/wiki/SafeTensors)
63
+
64
+ ### 3. Sample across several shards
65
+
66
+ Read your training files in a stable order. Filter out blank text, then select up to 128 examples with a repeatable seed. Sampling scans every shard and keeps only the selected rows in memory.
67
+
68
+ ```python
69
+ from pathlib import Path
70
+ from datashoal import load
71
+
72
+ shards = sorted(Path("calibration").glob("train-*.jsonl.gz"))
73
+ train = load(shards, type="dataset").filter(lambda row: row["text"].strip())
74
+ calibration_rows = train.sample(128, seed=42)
75
+ ```
76
+
77
+ ### 4. Fetch once and calibrate offline
78
+
79
+ Pin a public calibration dataset to a specific revision. Run the first call on a connected machine to populate its cache. Later runs using that cache can omit download permission entirely.
80
+
81
+ ```python
82
+ from datashoal import load
83
+
84
+ repo = "neuralmagic/calibration"
85
+ shard = dict(type="dataset", file="llm.parquet",
86
+ revision="fb6bc2f8c66543876fb31613f5872b9030220e15")
87
+ load(repo, **shard, download=True)
88
+
89
+ calibration_rows = load(repo, **shard).sample(128, seed=42)
90
+ ```
91
+
92
+ With a loaded GPT-QModel `model`, pass those rows directly to quantization:
93
+
94
+ ```python
95
+ from gptqmodel.quantization import CalibrationConfig
96
+
97
+ model.quantize(CalibrationConfig(dataset=calibration_rows, batch_size=1))
98
+ ```
99
+
100
+ For checkpoints, `load("org/model", type="model")` returns a cached snapshot directory. Add `file="config.json"` to get one file, or `provider="modelscope"` to select ModelScope. See the wiki for [loading options](https://github.com/ModelCloud/DataShoal/wiki/Loading-Reference), [Hub uploads](https://github.com/ModelCloud/DataShoal/wiki/Xet-and-Uploads) and [HF compatibility](https://github.com/ModelCloud/DataShoal/wiki/Hugging-Face-Compatibility).
101
+
102
+ ## Parquet benchmarks
103
+
104
+ Each cell shows **elapsed time / peak process memory** for the same Python chat records. Lower is better for both. Streaming consumed 1,024 rows at a time.
105
+
106
+ | Rows | Mode | DataShoal | PyArrow | HF Datasets |
107
+ | ---: | --- | ---: | ---: | ---: |
108
+ | 10,000 | Collect | **7.55 ms / 92 MiB** | 9.24 ms / 257 MiB | 9.29 ms / 187 MiB |
109
+ | 10,000 | Stream | **7.66 ms / 75 MiB** | 11.72 ms / 119 MiB | 9.83 ms / 203 MiB |
110
+ | 100,000 | Collect | 90.97 ms / **433 MiB** | 92.91 ms / 1,065 MiB | **88.98 ms** / 723 MiB |
111
+ | 100,000 | Stream | **70.81 ms / 95 MiB** | 117.81 ms / 240 MiB | 72.44 ms / 343 MiB |
112
+
113
+ DataShoal used the least memory in all four cases. HF Datasets reopened a prepared local cache for collection. The 100,000-row fixture repeats the smaller chat corpus ten times. Each library ran in separate processes on an Apple M5 Ultra. [Benchmark methods and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#reproduce-the-comparison)
114
+
115
+ ### Parquet projection, numeric reads and writes
116
+
117
+ Median elapsed time across 51 warm runs on an Apple M5 Ultra. Lower is faster. Each reader returns the full output named in the row, including HF Datasets when reading from a stream.
118
+
119
+ | Operation | DataShoal | PyArrow | HF Datasets (streaming) | HF Datasets (cached) |
120
+ | --- | ---: | ---: | ---: | ---: |
121
+ | Read 10,000 chat records as Python rows | **6.88 ms** | 7.92 ms | 13.59 ms | 7.21 ms |
122
+ | Read only the text column of 10,000 chat records | **2.94 ms** | 3.26 ms | 9.15 ms | 3.45 ms |
123
+ | Read 250,000 integer IDs as Python rows | **9.00 ms** | 10.68 ms | 12.44 ms | 12.07 ms |
124
+ | Read 250,000 integer IDs into a NumPy array | 3.89 ms | **0.86 ms** | 1.99 ms | 2.03 ms |
125
+ | Write 10,000 chat records to uncompressed Parquet | **6.99 ms** | 7.50 ms | Not measured | Not measured |
126
+
127
+ [Benchmark details and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#parquet-projection-numeric-reads-and-writes)
128
+
129
+ ## SafeTensors benchmarks
130
+
131
+ Median elapsed time for one 64 MiB integer tensor on an Apple M5 Ultra. Lower is faster.
132
+
133
+ | Operation | DataShoal | SafeTensors 0.8.0 (Rust, NumPy interface) |
134
+ | --- | ---: | ---: |
135
+ | Read the full tensor into owned bytes | **2.89 ms** | 5.16 ms |
136
+ | Stream the tensor in owned 1 MiB chunks | **2.34 ms** | 7.67 ms |
137
+ | Write the tensor to a local file | 5.29 ms | **4.83 ms** |
138
+
139
+ DataShoal publishes writes atomically. [Benchmark details and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#safetensors-file-io)
140
+
141
+ ## Native accelerator benchmarks
142
+
143
+ Speedup of the current JIT accelerator over the previous release on identical inputs. Each cell is the median ratio of 15 alternating rounds with both builds loaded in one process.
144
+
145
+ | Entry point | Used by | Small | Medium | Large |
146
+ | --- | --- | ---: | ---: | ---: |
147
+ | LZ4 frame decode | Xet downloads | **2.00x** | **3.49x** | **4.12x** |
148
+ | Keyed BLAKE3 (64 B / 4 KiB / 64 KiB) | Xet hashing | 1.26x | **1.94x** | **3.23x** |
149
+ | Content-defined chunking | Xet uploads | **1.48x** | **1.98x** | **2.10x** |
150
+ | Positional tensor read (1 / 64 / 256 MiB) | SafeTensors | 1.00x | **1.51x** | **2.56x** |
151
+ | Level encoding | Parquet writes | **1.59x** | **1.79x** | **1.71x** |
152
+ | Repetition levels | Parquet reads | **1.54x** | **1.66x** | **1.41x** |
153
+ | Snappy page decode | Parquet reads | **1.32x** | 1.18x | 1.17x |
154
+ | Page and footer metadata | Parquet reads | 1.18x | 1.18x | 1.19x |
155
+
156
+ String, dictionary and record assembly spend their time creating Python objects and stay within 5% of the previous release. Text packing no longer attaches a cached UTF-8 copy to every non-ASCII input string. That copy previously kept 15.3 MiB alive after writing a 15.7 MiB file. Measured on x86-64 with CPython 3.14.4. [Reproduce with `benchmarks/native.py`](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#native-accelerator)
157
+
158
+ ## Attributions and citations 📚
159
+
160
+ DataShoal implements the Xet protocol for uploads to and downloads from the
161
+ Hugging Face Hub. Please credit Hugging Face’s Xet team when citing the protocol.
162
+
163
+ | Work | Authors / project | Reference |
164
+ | --- | --- | --- |
165
+ | DataShoal | ModelCloud.ai, [@qubitiium](https://x.com/qubitium), and DataShoal contributors | [Project](https://github.com/ModelCloud/DataShoal) |
166
+ | Xet | Hugging Face’s Xet team and contributors | [Protocol specification](https://huggingface.co/docs/xet/en/index) · [Reference implementation](https://github.com/huggingface/xet-core) |
167
+ | SafeTensors | SafeTensors contributors | [File format](https://github.com/safetensors/safetensors#format) · [Reference implementation](https://github.com/safetensors/safetensors) |
168
+
169
+ ### Cite DataShoal, Xet and SafeTensors (BibTeX)
170
+
171
+ ```bibtex
172
+ @misc{modelcloud_datashoal,
173
+ author = {{ModelCloud.ai} and {@qubitiium} and {DataShoal contributors}},
174
+ title = {{DataShoal}},
175
+ url = {https://github.com/ModelCloud/DataShoal}
176
+ }
177
+
178
+ @misc{huggingface_xet_protocol,
179
+ author = {{Hugging Face}},
180
+ title = {{Xet Protocol Specification}},
181
+ url = {https://huggingface.co/docs/xet/en/index}
182
+ }
183
+
184
+ @misc{safetensors_format,
185
+ author = {{SafeTensors contributors}},
186
+ title = {{SafeTensors}},
187
+ url = {https://github.com/safetensors/safetensors}
188
+ }
189
+ ```
@@ -0,0 +1,181 @@
1
+ <!-- SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors -->
2
+
3
+ <h1 align="center"><img src="https://raw.githubusercontent.com/ModelCloud/DataShoal/main/assets/datashoal.png" width="520" alt="DataShoal"></h1>
4
+
5
+ DataShoal is a small Python library for loading datasets and reading, writing and streaming SafeTensors checkpoints. Use it to sample calibration rows for GPT-QModel or read individual weights from a local file or your Hugging Face or ModelScope cache. PyTorch is optional. **By default, `load()` makes zero network requests.**
6
+
7
+ [Documentation wiki](https://github.com/ModelCloud/DataShoal/wiki) · [Python API](https://github.com/ModelCloud/DataShoal/wiki/API-Reference) · [Native ABI](https://github.com/ModelCloud/DataShoal/wiki/Native-Extension-ABI) · [Quickstart](https://github.com/ModelCloud/DataShoal/wiki/Installation-and-Quickstart)
8
+
9
+ ## Features
10
+
11
+ - **Stream and sample.** Read JSON, JSONL, CSV, text, Parquet and supported Arrow streams. Filter, transform, batch or sample rows while keeping nested chat messages and token IDs intact.
12
+ - **Stay offline by default.** Reuse completed files from your existing cache. Pass `download=True` to allow a fetch. DataShoal verifies new artifact downloads before publishing them to the cache.
13
+ - **Keep the install small.** LogBar is the only required package. DataShoal handles calibration and artifact transfers without installing NumPy, pandas, PyArrow, HF Datasets or the Hub SDK.
14
+ - **Read and write Parquet directly.** Select just the columns you need. Frequently used codecs compile locally on first use; a Python fallback runs when a compiler is unavailable.
15
+ - **Read and write SafeTensors.** Inspect shards, stream weights, or copy selected rows into a new checkpoint. With PyTorch installed, index several shards and load just the weights or rows your model needs. [SafeTensors guide](https://github.com/ModelCloud/DataShoal/wiki/SafeTensors)
16
+ - **Use threads with the GIL disabled.** Independent readers can run concurrently on free-threaded CPython. Threads sharing one iterator divide its rows between them.
17
+ - **Work with model hubs.** Download files or snapshots from Hugging Face and ModelScope, upload to Hugging Face using native Xet support, or opt into HF-compatible imports for supported downstream consumers.
18
+
19
+ ## Usage
20
+
21
+ Install from GitHub with Python 3.11 or newer:
22
+
23
+ ```sh
24
+ python -m pip install git+https://github.com/ModelCloud/DataShoal.git
25
+ ```
26
+
27
+ ### 1. Preview a local dataset
28
+
29
+ Given a local JSONL file with one record per line, read its first three rows:
30
+
31
+ ```python
32
+ from datashoal import load
33
+
34
+ rows = load("train.jsonl", type="dataset")
35
+ print(rows.take(3))
36
+ ```
37
+
38
+ ### 2. Write and read a SafeTensors checkpoint
39
+
40
+ Save two weights from a Python buffer, then read them back. PyTorch is optional.
41
+
42
+ ```python
43
+ from struct import pack, unpack
44
+ from datashoal import SafeTensors as st
45
+
46
+ scale = st.wire.TensorData("F32", (2,), pack("<2f", 1.25, 2.5))
47
+ st.save("example.safetensors", {"scale": scale})
48
+
49
+ with st.load("example.safetensors") as archive:
50
+ assert archive.wire.tensors["scale"].shape == (2,)
51
+ assert unpack("<2f", archive.read("scale")) == (1.25, 2.5)
52
+ ```
53
+
54
+ For large weights, iterate over `archive.chunks("scale")`. With PyTorch installed, `archive.torch("scale")` returns a writable tensor. [SafeTensors guide](https://github.com/ModelCloud/DataShoal/wiki/SafeTensors)
55
+
56
+ ### 3. Sample across several shards
57
+
58
+ Read your training files in a stable order. Filter out blank text, then select up to 128 examples with a repeatable seed. Sampling scans every shard and keeps only the selected rows in memory.
59
+
60
+ ```python
61
+ from pathlib import Path
62
+ from datashoal import load
63
+
64
+ shards = sorted(Path("calibration").glob("train-*.jsonl.gz"))
65
+ train = load(shards, type="dataset").filter(lambda row: row["text"].strip())
66
+ calibration_rows = train.sample(128, seed=42)
67
+ ```
68
+
69
+ ### 4. Fetch once and calibrate offline
70
+
71
+ Pin a public calibration dataset to a specific revision. Run the first call on a connected machine to populate its cache. Later runs using that cache can omit download permission entirely.
72
+
73
+ ```python
74
+ from datashoal import load
75
+
76
+ repo = "neuralmagic/calibration"
77
+ shard = dict(type="dataset", file="llm.parquet",
78
+ revision="fb6bc2f8c66543876fb31613f5872b9030220e15")
79
+ load(repo, **shard, download=True)
80
+
81
+ calibration_rows = load(repo, **shard).sample(128, seed=42)
82
+ ```
83
+
84
+ With a loaded GPT-QModel `model`, pass those rows directly to quantization:
85
+
86
+ ```python
87
+ from gptqmodel.quantization import CalibrationConfig
88
+
89
+ model.quantize(CalibrationConfig(dataset=calibration_rows, batch_size=1))
90
+ ```
91
+
92
+ For checkpoints, `load("org/model", type="model")` returns a cached snapshot directory. Add `file="config.json"` to get one file, or `provider="modelscope"` to select ModelScope. See the wiki for [loading options](https://github.com/ModelCloud/DataShoal/wiki/Loading-Reference), [Hub uploads](https://github.com/ModelCloud/DataShoal/wiki/Xet-and-Uploads) and [HF compatibility](https://github.com/ModelCloud/DataShoal/wiki/Hugging-Face-Compatibility).
93
+
94
+ ## Parquet benchmarks
95
+
96
+ Each cell shows **elapsed time / peak process memory** for the same Python chat records. Lower is better for both. Streaming consumed 1,024 rows at a time.
97
+
98
+ | Rows | Mode | DataShoal | PyArrow | HF Datasets |
99
+ | ---: | --- | ---: | ---: | ---: |
100
+ | 10,000 | Collect | **7.55 ms / 92 MiB** | 9.24 ms / 257 MiB | 9.29 ms / 187 MiB |
101
+ | 10,000 | Stream | **7.66 ms / 75 MiB** | 11.72 ms / 119 MiB | 9.83 ms / 203 MiB |
102
+ | 100,000 | Collect | 90.97 ms / **433 MiB** | 92.91 ms / 1,065 MiB | **88.98 ms** / 723 MiB |
103
+ | 100,000 | Stream | **70.81 ms / 95 MiB** | 117.81 ms / 240 MiB | 72.44 ms / 343 MiB |
104
+
105
+ DataShoal used the least memory in all four cases. HF Datasets reopened a prepared local cache for collection. The 100,000-row fixture repeats the smaller chat corpus ten times. Each library ran in separate processes on an Apple M5 Ultra. [Benchmark methods and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#reproduce-the-comparison)
106
+
107
+ ### Parquet projection, numeric reads and writes
108
+
109
+ Median elapsed time across 51 warm runs on an Apple M5 Ultra. Lower is faster. Each reader returns the full output named in the row, including HF Datasets when reading from a stream.
110
+
111
+ | Operation | DataShoal | PyArrow | HF Datasets (streaming) | HF Datasets (cached) |
112
+ | --- | ---: | ---: | ---: | ---: |
113
+ | Read 10,000 chat records as Python rows | **6.88 ms** | 7.92 ms | 13.59 ms | 7.21 ms |
114
+ | Read only the text column of 10,000 chat records | **2.94 ms** | 3.26 ms | 9.15 ms | 3.45 ms |
115
+ | Read 250,000 integer IDs as Python rows | **9.00 ms** | 10.68 ms | 12.44 ms | 12.07 ms |
116
+ | Read 250,000 integer IDs into a NumPy array | 3.89 ms | **0.86 ms** | 1.99 ms | 2.03 ms |
117
+ | Write 10,000 chat records to uncompressed Parquet | **6.99 ms** | 7.50 ms | Not measured | Not measured |
118
+
119
+ [Benchmark details and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#parquet-projection-numeric-reads-and-writes)
120
+
121
+ ## SafeTensors benchmarks
122
+
123
+ Median elapsed time for one 64 MiB integer tensor on an Apple M5 Ultra. Lower is faster.
124
+
125
+ | Operation | DataShoal | SafeTensors 0.8.0 (Rust, NumPy interface) |
126
+ | --- | ---: | ---: |
127
+ | Read the full tensor into owned bytes | **2.89 ms** | 5.16 ms |
128
+ | Stream the tensor in owned 1 MiB chunks | **2.34 ms** | 7.67 ms |
129
+ | Write the tensor to a local file | 5.29 ms | **4.83 ms** |
130
+
131
+ DataShoal publishes writes atomically. [Benchmark details and reproduction](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#safetensors-file-io)
132
+
133
+ ## Native accelerator benchmarks
134
+
135
+ Speedup of the current JIT accelerator over the previous release on identical inputs. Each cell is the median ratio of 15 alternating rounds with both builds loaded in one process.
136
+
137
+ | Entry point | Used by | Small | Medium | Large |
138
+ | --- | --- | ---: | ---: | ---: |
139
+ | LZ4 frame decode | Xet downloads | **2.00x** | **3.49x** | **4.12x** |
140
+ | Keyed BLAKE3 (64 B / 4 KiB / 64 KiB) | Xet hashing | 1.26x | **1.94x** | **3.23x** |
141
+ | Content-defined chunking | Xet uploads | **1.48x** | **1.98x** | **2.10x** |
142
+ | Positional tensor read (1 / 64 / 256 MiB) | SafeTensors | 1.00x | **1.51x** | **2.56x** |
143
+ | Level encoding | Parquet writes | **1.59x** | **1.79x** | **1.71x** |
144
+ | Repetition levels | Parquet reads | **1.54x** | **1.66x** | **1.41x** |
145
+ | Snappy page decode | Parquet reads | **1.32x** | 1.18x | 1.17x |
146
+ | Page and footer metadata | Parquet reads | 1.18x | 1.18x | 1.19x |
147
+
148
+ String, dictionary and record assembly spend their time creating Python objects and stay within 5% of the previous release. Text packing no longer attaches a cached UTF-8 copy to every non-ASCII input string. That copy previously kept 15.3 MiB alive after writing a 15.7 MiB file. Measured on x86-64 with CPython 3.14.4. [Reproduce with `benchmarks/native.py`](https://github.com/ModelCloud/DataShoal/wiki/Runtime-and-Performance#native-accelerator)
149
+
150
+ ## Attributions and citations 📚
151
+
152
+ DataShoal implements the Xet protocol for uploads to and downloads from the
153
+ Hugging Face Hub. Please credit Hugging Face’s Xet team when citing the protocol.
154
+
155
+ | Work | Authors / project | Reference |
156
+ | --- | --- | --- |
157
+ | DataShoal | ModelCloud.ai, [@qubitiium](https://x.com/qubitium), and DataShoal contributors | [Project](https://github.com/ModelCloud/DataShoal) |
158
+ | Xet | Hugging Face’s Xet team and contributors | [Protocol specification](https://huggingface.co/docs/xet/en/index) · [Reference implementation](https://github.com/huggingface/xet-core) |
159
+ | SafeTensors | SafeTensors contributors | [File format](https://github.com/safetensors/safetensors#format) · [Reference implementation](https://github.com/safetensors/safetensors) |
160
+
161
+ ### Cite DataShoal, Xet and SafeTensors (BibTeX)
162
+
163
+ ```bibtex
164
+ @misc{modelcloud_datashoal,
165
+ author = {{ModelCloud.ai} and {@qubitiium} and {DataShoal contributors}},
166
+ title = {{DataShoal}},
167
+ url = {https://github.com/ModelCloud/DataShoal}
168
+ }
169
+
170
+ @misc{huggingface_xet_protocol,
171
+ author = {{Hugging Face}},
172
+ title = {{Xet Protocol Specification}},
173
+ url = {https://huggingface.co/docs/xet/en/index}
174
+ }
175
+
176
+ @misc{safetensors_format,
177
+ author = {{SafeTensors contributors}},
178
+ title = {{SafeTensors}},
179
+ url = {https://github.com/safetensors/safetensors}
180
+ }
181
+ ```
@@ -0,0 +1,77 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """Standard-library PEP 517 backend for source-only distributions."""
4
+
5
+ import base64
6
+ import csv
7
+ import hashlib
8
+ import io
9
+ import tarfile
10
+ import tomllib
11
+ import zipfile
12
+ from pathlib import Path
13
+
14
+ ROOT = Path(__file__).resolve().parent
15
+ PROJECT = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))["project"]
16
+ DIST = f"{PROJECT['name']}-{PROJECT['version']}"
17
+
18
+
19
+ def _metadata():
20
+ return (
21
+ "Metadata-Version: 2.1\n"
22
+ f"Name: {PROJECT['name']}\nVersion: {PROJECT['version']}\n"
23
+ f"Summary: {PROJECT['description']}\nRequires-Python: {PROJECT['requires-python']}\n"
24
+ + "".join(f"Requires-Dist: {dep}\n" for dep in PROJECT["dependencies"])
25
+ + "Description-Content-Type: text/markdown\n\n"
26
+ + (ROOT / PROJECT["readme"]).read_text(encoding="utf-8")
27
+ ).encode("utf-8")
28
+
29
+
30
+ PACKAGE = ROOT / "datashoal"
31
+
32
+
33
+ def _sources():
34
+ """Package sources shipped in both distributions: Python modules and native C sources."""
35
+ return sorted(
36
+ path
37
+ for pattern in ("*.py", "*.c", "*.h")
38
+ for path in PACKAGE.rglob(pattern)
39
+ if "__pycache__" not in path.parts
40
+ )
41
+
42
+
43
+ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
44
+ tag = "py3-none-any"
45
+ filename = f"{DIST}-{tag}.whl"
46
+ info = f"{DIST}.dist-info"
47
+ files = {
48
+ path.relative_to(ROOT).as_posix(): path.read_bytes()
49
+ for path in _sources()
50
+ }
51
+ files[f"{info}/METADATA"] = _metadata()
52
+ files[f"{info}/WHEEL"] = f"Wheel-Version: 1.0\nGenerator: datashoal\nRoot-Is-Purelib: true\nTag: {tag}\n".encode()
53
+ record = io.StringIO(newline="")
54
+ writer = csv.writer(record)
55
+ for name, data in files.items():
56
+ digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode("ascii")
57
+ writer.writerow((name, f"sha256={digest}", len(data)))
58
+ writer.writerow((f"{info}/RECORD", "", ""))
59
+ files[f"{info}/RECORD"] = record.getvalue().encode("utf-8")
60
+ with zipfile.ZipFile(Path(wheel_directory) / filename, "w", zipfile.ZIP_DEFLATED) as wheel:
61
+ for name, data in files.items():
62
+ wheel.writestr(name, data)
63
+ return filename
64
+
65
+
66
+ def build_sdist(sdist_directory, config_settings=None):
67
+ filename = f"{DIST}.tar.gz"
68
+ paths = [ROOT / name for name in ("pyproject.toml", "README.md", "build_backend.py")]
69
+ paths.extend(_sources())
70
+ with tarfile.open(Path(sdist_directory) / filename, "w:gz") as archive:
71
+ for path in paths:
72
+ archive.add(path, arcname=f"{DIST}/{path.relative_to(ROOT).as_posix()}")
73
+ metadata = _metadata()
74
+ entry = tarfile.TarInfo(f"{DIST}/PKG-INFO")
75
+ entry.size = len(metadata)
76
+ archive.addfile(entry, io.BytesIO(metadata))
77
+ return filename
@@ -0,0 +1,9 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """Cache-first calibration datasets and model artifacts."""
4
+
5
+ from . import hf_compat
6
+ from .api import ArrowIPC, DownloadConfig, Parquet, SafeTensors, load, upload
7
+ from .dataset import Dataset
8
+
9
+ __all__ = ["ArrowIPC", "Dataset", "DownloadConfig", "Parquet", "SafeTensors", "hf_compat", "load", "upload"]
@@ -0,0 +1,53 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """One-shot, 32-byte keyed BLAKE3 for Xet's bounded chunks and Merkle nodes."""
4
+
5
+ import struct
6
+
7
+ _IV = (0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A)
8
+ _PERMUTE = (2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8)
9
+ _MASK = 0xffffffff
10
+
11
+
12
+ def _rotate(value, distance):
13
+ return ((value >> distance) | (value << (32 - distance))) & _MASK
14
+
15
+
16
+ def _mix(v, a, b, c, d, x, y):
17
+ v[a] = (v[a] + v[b] + x) & _MASK
18
+ v[d] = _rotate(v[d] ^ v[a], 16)
19
+ v[c] = (v[c] + v[d]) & _MASK
20
+ v[b] = _rotate(v[b] ^ v[c], 12)
21
+ v[a] = (v[a] + v[b] + y) & _MASK
22
+ v[d] = _rotate(v[d] ^ v[a], 8)
23
+ v[c] = (v[c] + v[d]) & _MASK
24
+ v[b] = _rotate(v[b] ^ v[c], 7)
25
+
26
+
27
+ def _compress(cv, words, counter, length, flags):
28
+ v = [*cv, *_IV, counter & _MASK, counter >> 32, length, flags]
29
+ for _ in range(7):
30
+ for i in range(4):
31
+ _mix(v, i, i+4, i+8, i+12, words[2*i], words[2*i+1])
32
+ for i in range(4):
33
+ _mix(v, i, 4+(i+1)%4, 8+(i+2)%4, 12+(i+3)%4, words[8+2*i], words[9+2*i])
34
+ words = [words[i] for i in _PERMUTE]
35
+ return tuple(v[i] ^ v[i+8] for i in range(8))
36
+
37
+
38
+ def keyed(data, key):
39
+ key_words = struct.unpack("<8I", key)
40
+ def subtree(start, end, root):
41
+ if end - start > 1024:
42
+ chunks = (end - start + 1023) // 1024
43
+ middle = start + 1024 * (1 << ((chunks - 1).bit_length() - 1))
44
+ words = subtree(start, middle, False) + subtree(middle, end, False)
45
+ return _compress(key_words, words, 0, 64, 16 | 4 | (8 if root else 0))
46
+ cv = key_words
47
+ for offset in range(start, max(start + 1, end), 64):
48
+ block = data[offset:min(end, offset+64)]
49
+ final = offset+64 >= end
50
+ flags = 16 | int(offset == start) | (2 if final else 0) | (8 if final and root else 0)
51
+ cv = _compress(cv, struct.unpack("<16I", block.ljust(64, b"\0")), start//1024, len(block), flags)
52
+ return cv
53
+ return struct.pack("<8I", *subtree(0, len(data), True))
@@ -0,0 +1,123 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """Thrift compact protocol used by Parquet footers and page headers."""
4
+
5
+ import struct
6
+
7
+ BOOL, BYTE, I16, I32, I64, DOUBLE, BINARY, LIST, SET, MAP, STRUCT = 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
8
+
9
+
10
+ def exact(stream, n):
11
+ if n < 0:
12
+ raise ValueError("Negative Parquet length")
13
+ data = stream.read(n)
14
+ if len(data) != n:
15
+ raise ValueError("Truncated Parquet data")
16
+ return data
17
+
18
+
19
+ def uint(stream):
20
+ value = 0
21
+ for shift in range(0, 70, 7):
22
+ b = exact(stream, 1)[0]
23
+ if shift == 63 and b > 1:
24
+ raise ValueError("Invalid compact integer")
25
+ value |= (b & 127) << shift
26
+ if b < 128:
27
+ return value
28
+ raise ValueError("Invalid compact integer")
29
+
30
+
31
+ def varint(value):
32
+ out = bytearray()
33
+ while value >= 128:
34
+ out.append(128 | (value & 127))
35
+ value >>= 7
36
+ out.append(value)
37
+ return bytes(out)
38
+
39
+
40
+ def _value(stream, kind, depth, budget):
41
+ if depth > 64:
42
+ raise ValueError("Parquet metadata nested too deeply")
43
+ if kind in (1, 2):
44
+ return kind == 1
45
+ if kind == BYTE:
46
+ return int.from_bytes(exact(stream, 1), "little", signed=True)
47
+ if kind in (I16, I32, I64):
48
+ n = uint(stream)
49
+ return (n >> 1) ^ -(n & 1)
50
+ if kind == DOUBLE:
51
+ return struct.unpack("<d", exact(stream, 8))[0]
52
+ if kind == BINARY:
53
+ size = uint(stream)
54
+ if size > 64 << 20:
55
+ raise ValueError("Oversized Parquet metadata string")
56
+ return exact(stream, size)
57
+ if kind in (LIST, SET):
58
+ head = exact(stream, 1)[0]
59
+ count = head >> 4
60
+ if count == 15:
61
+ count = uint(stream)
62
+ budget[0] -= count
63
+ if budget[0] < 0 or count > 1000000:
64
+ raise ValueError("Oversized Parquet metadata list")
65
+ if head & 15 in (1, 2):
66
+ values = exact(stream, count)
67
+ if any(v not in (1, 2) for v in values):
68
+ raise ValueError("Invalid compact boolean")
69
+ return [v == 1 for v in values]
70
+ return [_value(stream, head & 15, depth + 1, budget) for _ in range(count)]
71
+ if kind == STRUCT:
72
+ return fields(stream, depth + 1, budget)
73
+ raise ValueError(f"Unsupported Parquet compact type {kind}")
74
+
75
+
76
+ def fields(stream, depth=0, budget=None):
77
+ if budget is None:
78
+ budget = [1 << 20]
79
+ out = {}
80
+ last = 0
81
+ while head := exact(stream, 1)[0]:
82
+ budget[0] -= 1
83
+ if budget[0] < 0:
84
+ raise ValueError("Oversized compact metadata")
85
+ delta, kind = divmod(head, 16)
86
+ last = last + delta if delta else _value(stream, I16, depth, budget)
87
+ if not -32768 <= last <= 32767:
88
+ raise ValueError("Invalid compact field id")
89
+ if last in out:
90
+ raise ValueError("Duplicate compact field")
91
+ out[last] = _value(stream, kind, depth, budget)
92
+ return out
93
+
94
+
95
+ def _encode(kind, value):
96
+ if kind in (I16, I32, I64):
97
+ return varint(value * 2 if value >= 0 else -value * 2 - 1)
98
+ if kind == BINARY:
99
+ return varint(len(value)) + value
100
+ if kind == STRUCT:
101
+ return encode(value)
102
+ if kind == LIST:
103
+ item, values = value
104
+ n = len(values)
105
+ head = bytes([min(n, 15) * 16 + item])
106
+ return head + (varint(n) if n >= 15 else b"") + b"".join(_encode(item, v) for v in values)
107
+ raise ValueError(f"Unsupported compact type {kind}")
108
+
109
+
110
+ def encode(entries):
111
+ out = bytearray()
112
+ previous = 0
113
+ for number, kind, value in entries:
114
+ delta = number - previous
115
+ if 0 < delta < 16:
116
+ out.append(delta * 16 + kind)
117
+ else:
118
+ out.append(kind)
119
+ out.extend(_encode(I16, number))
120
+ out.extend(_encode(kind, value))
121
+ previous = number
122
+ out.append(0)
123
+ return bytes(out)
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """Opt-in datasets import surface."""
4
+
5
+ from .hf_compat import Dataset, DatasetDict, IterableDataset, IterableDatasetDict, load_dataset
6
+
7
+ __all__ = ["Dataset", "DatasetDict", "IterableDataset", "IterableDatasetDict", "load_dataset"]
@@ -0,0 +1,7 @@
1
+ # SPDX-FileCopyrightText: 2026 ModelCloud.ai, @qubitiium (https://x.com/qubitium), and DataShoal contributors
2
+
3
+ """Opt-in huggingface_hub import surface."""
4
+
5
+ from .hf_compat import hf_hub_download, snapshot_download, upload_file
6
+
7
+ __all__ = ["hf_hub_download", "snapshot_download", "upload_file"]