ztensor 1.1.1__py3-none-win32.whl

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.
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: ztensor
3
+ Version: 1.1.1
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: 3
6
+ Classifier: License :: OSI Approved :: MIT License
7
+ Classifier: Operating System :: OS Independent
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Topic :: Scientific/Engineering
10
+ Requires-Dist: numpy
11
+ Requires-Dist: cffi
12
+ Requires-Dist: ml-dtypes
13
+ License-File: LICENSE
14
+ Summary: Python bindings for the zTensor library.
15
+ Author-email: In Gim <in.gim@yale.edu>
16
+ License-Expression: MIT
17
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
+ Project-URL: Homepage, https://github.com/pie-project/ztensor
19
+ Project-URL: Source, https://github.com/pie-project/ztensor
20
+
21
+ # ztensor
22
+ [![Crates.io](https://img.shields.io/crates/v/ztensor.svg)](https://crates.io/crates/ztensor)
23
+ [![Docs.rs](https://docs.rs/ztensor/badge.svg)](https://docs.rs/ztensor)
24
+ [![PyPI](https://img.shields.io/pypi/v/ztensor.svg)](https://pypi.org/project/ztensor/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
26
+
27
+ Simple tensor serialization format
28
+
29
+ ## Key Features
30
+
31
+ - **Simple Spec** — Minimalist [spec](SPEC.md) for easy parsing.
32
+ - **Zero-Copy Access** — Instant memory-mapping (mmap) with no extra RAM copying overhead.
33
+ - **Efficient Writes** — Supports streaming and append-only operations without rewriting files.
34
+ - **Future-Proof** — Decouples physical storage from logical representation for long-term compatibility.
35
+
36
+ ## Tools
37
+
38
+ - **Rust Core** — High-performance, SIMD-aligned implementation.
39
+ - **Python API** — First-class bindings for **NumPy** and **PyTorch**.
40
+ - **Universal Converters** — CLI tools to easily convert **Pickle**, **SafeTensors**, and **GGUF** files.
41
+
42
+ ## Comparison
43
+
44
+ | Feature | **zTensor** | SafeTensors | GGUF | Pickle | HDF5 |
45
+ | :--- | :---: | :---: | :---: | :---: | :---: |
46
+ | **Zero-Copy Read** | ✅ | ✅ | ✅ | ❌ | ⚠️ |
47
+ | **Safe (No Exec)** | ✅ | ✅ | ✅ | ❌ | ✅ |
48
+ | **Streaming / Append** | ✅ | ❌ | ❌ | ❌ | ✅ |
49
+ | **Sparse Tensors** | ✅ | ❌ | ❌ | ✅ | ✅ |
50
+ | **Compression** | ✅ | ❌ | ❌ | ❌ | ✅ |
51
+ | **Quantization** | ✅ | ✅ | ✅ | ✅ | ✅ |
52
+ | **Parser Complexity** | 🟢 Low | 🟢 Low | 🟡 Med | 🔴 High | 🔴 High |
53
+
54
+ ## Benchmark
55
+
56
+ ![benchmark](benchmark/plot.png)
57
+
58
+ See [benchmark](benchmark/bench.py) for more details.
59
+
60
+ ## Installation
61
+
62
+ ### Python
63
+
64
+ ```bash
65
+ pip install ztensor
66
+ ```
67
+
68
+ ### Rust
69
+
70
+ ```toml
71
+ [dependencies]
72
+ ztensor = "0.1"
73
+ ```
74
+
75
+ ### CLI
76
+
77
+ ```bash
78
+ cargo install ztensor-cli
79
+ ```
80
+
81
+ ## Quick Start: Python
82
+
83
+ ### Basic Usage with NumPy
84
+
85
+ ```python
86
+ import numpy as np
87
+ from ztensor import Writer, Reader
88
+
89
+ # Write tensors
90
+ with Writer("model.zt") as w:
91
+ w.add_tensor("weights", np.random.randn(1024, 768).astype(np.float32))
92
+ w.add_tensor("bias", np.zeros(768, dtype=np.float32))
93
+
94
+ # Read tensors (zero-copy where possible)
95
+ with Reader("model.zt") as r:
96
+ # Returns a numpy-like view
97
+ weights = r.read_tensor("weights")
98
+ print(f"Weights shape: {weights.shape}, dtype: {weights.dtype}")
99
+ ```
100
+
101
+ ### PyTorch Integration
102
+
103
+ ```python
104
+ import torch
105
+ from ztensor import Writer, Reader
106
+
107
+ # Write PyTorch tensors directly
108
+ t = torch.randn(10, 10)
109
+ with Writer("torch_model.zt") as w:
110
+ w.add_tensor("embedding", t)
111
+
112
+ # Read back as PyTorch tensors
113
+ with Reader("torch_model.zt") as r:
114
+ # 'to="torch"' returns a torch.Tensor sharing memory with the file (if mmap)
115
+ embedding = r.read_tensor("embedding", to="torch")
116
+ print(embedding.size())
117
+ ```
118
+
119
+ ### Sparse Tensors
120
+
121
+ Supports **CSR** (Compressed Sparse Row) and **COO** (Coordinate) formats.
122
+
123
+ ```python
124
+ import scipy.sparse
125
+ from ztensor import Writer, Reader
126
+
127
+ csr = scipy.sparse.csr_matrix([[1, 0], [0, 2]], dtype=np.float32)
128
+
129
+ with Writer("sparse.zt") as w:
130
+ # Add CSR tensor
131
+ w.add_sparse_csr("my_csr", csr.data, csr.indices, csr.indptr, csr.shape)
132
+
133
+ with Reader("sparse.zt") as r:
134
+ # Read back as scipy.sparse.csr_matrix
135
+ matrix = r.read_tensor("my_csr", to="numpy")
136
+ ```
137
+
138
+ ### Compression
139
+
140
+ Use Zstandard (zstd) compression to reduce file size.
141
+
142
+ ```python
143
+ with Writer("compressed.zt") as w:
144
+ w.add_tensor("big_data", data, compress=True)
145
+ ```
146
+
147
+ ## Quick Start: Rust
148
+
149
+ ### Basic Usage
150
+
151
+ ```rust
152
+ use ztensor::{ZTensorWriter, ZTensorReader, DType, Compression, ChecksumAlgorithm};
153
+
154
+ // Write
155
+ let mut writer = ZTensorWriter::create("model.zt")?;
156
+ // Zero-copy generic write with generic Compression
157
+ writer.add_object("weights", vec![1024, 768], DType::F32,
158
+ Compression::Raw, &data_vec, ChecksumAlgorithm::None)?;
159
+ writer.finalize()?;
160
+
161
+ // Read
162
+ let mut reader = ZTensorReader::open("model.zt")?;
163
+ // Read as specific type (automatically handles endianness)
164
+ let weights: Vec<f32> = reader.read_object_as("weights")?;
165
+ ```
166
+
167
+ ### Sparse Tensors
168
+
169
+ ```rust
170
+ // Write CSR (using generic method)
171
+ writer.add_csr_object(
172
+ "sparse_data",
173
+ vec![100, 100], // shape
174
+ DType::F32,
175
+ &values, // &[f32]
176
+ &indices, // &[u64]
177
+ &indptr, // &[u64]
178
+ Compression::Raw,
179
+ ChecksumAlgorithm::None
180
+ )?;
181
+
182
+ // Read CSR
183
+ let csr = reader.read_csr_object::<f32>("sparse_data")?;
184
+ println!("Values: {:?}", csr.values);
185
+ ```
186
+
187
+ ### Compression
188
+
189
+ ```rust
190
+ // Write with compression (level 3)
191
+ writer.add_object(
192
+ "compressed_data",
193
+ vec![512, 512],
194
+ DType::F32,
195
+ Compression::Zstd(3), // Use zstd encoding with level 3
196
+ &data, // &[f32]
197
+ ChecksumAlgorithm::Crc32c // Optional checksum
198
+ )?;
199
+
200
+ // Read (auto-decompresses)
201
+ let data: Vec<f32> = reader.read_object_as("compressed_data")?;
202
+ ```
203
+
204
+ ## CLI
205
+
206
+ The `ztensor` CLI tool allows you to inspect and manipulate zTensor files.
207
+
208
+ ### Inspect Metadata
209
+ Print tensor names, shapes, and properties.
210
+ ```bash
211
+ ztensor info model.zt
212
+ ```
213
+
214
+ ### Convert Other Formats
215
+ Convert SafeTensors, GGUF, or Pickle files to zTensor.
216
+ ```bash
217
+ # Auto-detect format from extension
218
+ ztensor convert model.safetensors -o model.zt
219
+
220
+ # Explicit format with compression (default level 3)
221
+ ztensor convert -f gguf -c llama.gguf -o llama.zt
222
+
223
+ # Specify compression level (1-22)
224
+ ztensor convert model.safetensors -o model.zt -l 10
225
+
226
+ # Delete originals after conversion
227
+ ztensor convert --delete-original *.safetensors -o model.zt
228
+ ```
229
+
230
+ ### Compression Tools
231
+ ```bash
232
+ # Compress an existing raw file (default level 3)
233
+ ztensor compress raw.zt -o compressed.zt
234
+
235
+ # Compress with specific level (1-22)
236
+ ztensor compress raw.zt -o highly_compressed.zt -l 19
237
+
238
+ # Decompress a file
239
+ ztensor decompress compressed.zt -o raw.zt
240
+ ```
241
+
242
+ ### File Management
243
+ ```bash
244
+ # Merge multiple files into one
245
+ ztensor merge part1.zt part2.zt -o merged.zt
246
+
247
+ # Migrate legacy v0.1.0 files to v1.1.0
248
+ ztensor migrate old_model.zt -o new_model.zt
249
+ ```
250
+
251
+ ### Download from HuggingFace
252
+ Download safetensors from HuggingFace and convert to zTensor:
253
+ ```bash
254
+ ztensor download-hf microsoft/resnet-18 -o ./models
255
+ ztensor download-hf openai-community/gpt2 -o ./models --compress
256
+ ```
257
+
258
+ ## Supported Data Types
259
+
260
+ | Type | Description |
261
+ |------|-------------|
262
+ | `float32`, `float16`, `bfloat16`, `float64` | Floating point |
263
+ | `int8`, `int16`, `int32`, `int64` | Signed integers |
264
+ | `uint8`, `uint16`, `uint32`, `uint64` | Unsigned integers |
265
+ | `bool` | Boolean |
266
+
267
+ ## File Format
268
+
269
+ See [SPEC.md](SPEC.md) for the complete specification.
270
+
271
+ ## License
272
+
273
+ MIT
274
+
@@ -0,0 +1,10 @@
1
+ ztensor-1.1.1.dist-info/METADATA,sha256=cK11e4sB2e2-npk8yx5UiWe5SeRebPdVe09mg1bcDIE,7554
2
+ ztensor-1.1.1.dist-info/WHEEL,sha256=WDMAB4uGoBTLFFNNHYBIIVDGp2BkavHkkLG_raftdhA,90
3
+ ztensor-1.1.1.dist-info/licenses/LICENSE,sha256=qxF7VFxBvMlfiDRJ5oXQuQYaloq0Tcbk95Pn0DFlnss,1084
4
+ ztensor/__init__.py,sha256=IaclCIjRXKJ8MIXMBZRr-CWa70q1EEfyI8z4Zq2kqF0,30041
5
+ ztensor/numpy.py,sha256=Jdf6WCWZsDU3kyfqXrvRmXCmS6cFmMw8xaak1YrIe1Y,6371
6
+ ztensor/torch.py,sha256=ZXpHyuH8NSyc1rsnBEf84xXDhC7b1Tezs_MIGBH8Rno,16542
7
+ ztensor/ztensor/__init__.py,sha256=DDVvoEhcXithkluOJ4Dd7H6wIqKcxT6mm6vvPgrQMz4,138
8
+ ztensor/ztensor/ffi.py,sha256=8zqlDsVGt4W9RcG-dUv7idsXR-GR21TUYuUrV25LIbU,4723
9
+ ztensor/ztensor/ztensor.dll,sha256=9Ufs-Cft813groyIa7rJ9rIkEd8xNQ4AaGMMtf3RGq0,1019392
10
+ ztensor-1.1.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.10.2)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win32
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 In Gim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.