weftcodec 1.2.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 (40) hide show
  1. weftcodec-1.2.0/PKG-INFO +257 -0
  2. weftcodec-1.2.0/README.md +229 -0
  3. weftcodec-1.2.0/pyproject.toml +42 -0
  4. weftcodec-1.2.0/setup.cfg +4 -0
  5. weftcodec-1.2.0/tests/test_ai_modes.py +527 -0
  6. weftcodec-1.2.0/tests/test_cli.py +85 -0
  7. weftcodec-1.2.0/tests/test_cross_cli.py +335 -0
  8. weftcodec-1.2.0/tests/test_dcp.py +482 -0
  9. weftcodec-1.2.0/tests/test_frame.py +94 -0
  10. weftcodec-1.2.0/tests/test_orbax.py +554 -0
  11. weftcodec-1.2.0/tests/test_random_differential.py +312 -0
  12. weftcodec-1.2.0/tests/test_service.py +251 -0
  13. weftcodec-1.2.0/tests/test_torch_dataset.py +85 -0
  14. weftcodec-1.2.0/tests/test_vectors.py +169 -0
  15. weftcodec-1.2.0/tests/test_wcb.py +94 -0
  16. weftcodec-1.2.0/weftcodec/__init__.py +62 -0
  17. weftcodec-1.2.0/weftcodec/__main__.py +6 -0
  18. weftcodec-1.2.0/weftcodec/ai_modes.py +3360 -0
  19. weftcodec-1.2.0/weftcodec/cli.py +252 -0
  20. weftcodec-1.2.0/weftcodec/crc32c.py +33 -0
  21. weftcodec-1.2.0/weftcodec/dcp.py +2108 -0
  22. weftcodec-1.2.0/weftcodec/dependency.py +224 -0
  23. weftcodec-1.2.0/weftcodec/errors.py +119 -0
  24. weftcodec-1.2.0/weftcodec/frame.py +455 -0
  25. weftcodec-1.2.0/weftcodec/hashing.py +56 -0
  26. weftcodec-1.2.0/weftcodec/huffman.py +212 -0
  27. weftcodec-1.2.0/weftcodec/identity.py +141 -0
  28. weftcodec-1.2.0/weftcodec/limits.py +58 -0
  29. weftcodec-1.2.0/weftcodec/modes.py +718 -0
  30. weftcodec-1.2.0/weftcodec/orbax.py +1734 -0
  31. weftcodec-1.2.0/weftcodec/service.py +959 -0
  32. weftcodec-1.2.0/weftcodec/torch.py +94 -0
  33. weftcodec-1.2.0/weftcodec/varint.py +88 -0
  34. weftcodec-1.2.0/weftcodec/wcb.py +310 -0
  35. weftcodec-1.2.0/weftcodec.egg-info/PKG-INFO +257 -0
  36. weftcodec-1.2.0/weftcodec.egg-info/SOURCES.txt +38 -0
  37. weftcodec-1.2.0/weftcodec.egg-info/dependency_links.txt +1 -0
  38. weftcodec-1.2.0/weftcodec.egg-info/entry_points.txt +2 -0
  39. weftcodec-1.2.0/weftcodec.egg-info/requires.txt +9 -0
  40. weftcodec-1.2.0/weftcodec.egg-info/top_level.txt +1 -0
@@ -0,0 +1,257 @@
1
+ Metadata-Version: 2.4
2
+ Name: weftcodec
3
+ Version: 1.2.0
4
+ Summary: Independent Python reader for Weft WFT1 frames and canonical WCB, with a PyTorch-facing dataset over a WeftFS mount
5
+ Author: WeftFS contributors
6
+ License: Apache-2.0
7
+ Project-URL: Source, https://github.com/infinityabundance/WeftFS
8
+ Keywords: weft,weftfs,codec,wft1,wcb,blake3,pytorch
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: System :: Filesystems
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ Requires-Dist: blake3>=0.3.1
22
+ Requires-Dist: zstandard>=0.22
23
+ Provides-Extra: torch
24
+ Requires-Dist: torch; extra == "torch"
25
+ Provides-Extra: orbax
26
+ Requires-Dist: jax[cpu]>=0.4; extra == "orbax"
27
+ Requires-Dist: orbax-checkpoint>=0.5; extra == "orbax"
28
+
29
+ # weftcodec (Python)
30
+
31
+ An independent Python implementation of the WeftCodec v1 **reader**: WFT1 frame
32
+ parsing, canonical WCB decode/encode, domain-separated BLAKE3 content roots, and
33
+ a PyTorch-facing dataset over a mounted WeftFS directory.
34
+
35
+ There are **no Rust or Go extension modules**. This is a third implementation,
36
+ written from the normative specification and tested against Rust-generated
37
+ conformance vectors.
38
+
39
+ ## Install
40
+
41
+ ```sh
42
+ pip install dist/weftcodec-1.2.0-py3-none-any.whl
43
+ # with the optional dataset extra
44
+ pip install "dist/weftcodec-1.2.0-py3-none-any.whl[torch]"
45
+ # with the optional JAX/Orbax adapter extra
46
+ pip install "dist/weftcodec-1.2.0-py3-none-any.whl[orbax]"
47
+ ```
48
+
49
+ Dependencies: `blake3`, `zstandard`. `torch`, `jax`, and `orbax-checkpoint`
50
+ are optional and are only imported by their adapter modules.
51
+
52
+ > **PyPI publication requires an API token we do not have.** The wheel is built
53
+ > in the Docker court and attached to the GitHub release; it is not published to
54
+ > PyPI.
55
+
56
+ ## Usage
57
+
58
+ ```sh
59
+ python -m weftcodec verify FRAME # validate structure + hashes
60
+ python -m weftcodec decode FRAME OUT # exact plaintext bytes
61
+ python -m weftcodec inspect FRAME # metadata as JSON
62
+ python -m weftcodec verify FRAME --deps DEPS_DIR # REFERENCE/DELTA/DICTIONARY
63
+ ```
64
+
65
+ Exit codes: `0` success, `1` codec or I/O failure, `2` usage error.
66
+
67
+ ```python
68
+ from weftcodec import parse, content_root, verify_frame
69
+ from weftcodec.dependency import DirectoryResolver
70
+ from weftcodec.modes import decode_bytes
71
+
72
+ resolver = DirectoryResolver("deps") # files named by lowercase hex
73
+ frame_bytes = open("frame.wft1", "rb").read()
74
+ frame = parse(frame_bytes)
75
+ plaintext = decode_bytes(frame_bytes, resolver)
76
+ assert content_root(plaintext) == frame.header.content_hash
77
+
78
+ result = verify_frame("frame.wft1", resolver)
79
+ print(result.ok, result.mode, result.content_hash, result.computed_content_hash)
80
+ ```
81
+
82
+ ### WCB
83
+
84
+ ```python
85
+ from weftcodec import wcb
86
+
87
+ value = wcb.decode(bytes.fromhex("08030501610301050162050374776f05016300"))
88
+ assert wcb.encode(value) == bytes.fromhex("08030501610301050162050374776f05016300")
89
+ ```
90
+
91
+ Python/WCB mapping: `None`→null, `bool`, `U64`, `I64`, `str`, `bytes`,
92
+ `list`/`tuple`, `dict` (text keys), `Timestamp`. Map keys are sorted by their
93
+ full encoded bytes; duplicates are rejected.
94
+
95
+ ### PyTorch dataset
96
+
97
+ ```python
98
+ from weftcodec.torch import WeftMapDataset
99
+
100
+ dataset = WeftMapDataset("/mnt/weft/dataset")
101
+ path, raw = dataset[0] # (relative path, bytes)
102
+
103
+ import torch
104
+ tensors = WeftMapDataset("/mnt/weft/dataset", dtype=torch.uint8)
105
+ path, tensor = tensors[0] # torch.frombuffer view
106
+ ```
107
+
108
+ Entries are sorted by POSIX-relative path, so ordering is deterministic across
109
+ processes.
110
+
111
+ ### PyTorch Distributed Checkpoint adapter
112
+
113
+ `weftcodec.dcp` implements the shape of
114
+ `torch.distributed.checkpoint.StorageWriter` / `StorageReader` over a WeftFS
115
+ store. The training process does not need a FUSE mount: every durable byte goes
116
+ through the Rust `weftfs` CLI (`checkpoint write` / `checkpoint restore`).
117
+
118
+ ```python
119
+ import torch
120
+ import torch.distributed.checkpoint as dcp
121
+ from weftcodec.dcp import WeftStorageWriter, WeftStorageReader, init_store
122
+
123
+ init_store("/data/weft-store")
124
+
125
+ model = MyModel()
126
+ dcp.save(
127
+ model.state_dict(),
128
+ storage_writer=WeftStorageWriter(
129
+ "run-0001", # single WeftFS checkpoint name
130
+ store_root="/data/weft-store",
131
+ topology=8, # store every tensor split 8 ways on axis 0
132
+ shard_strategy="zstd", # exact; tensor-sharded is the mode-10 option
133
+ ),
134
+ no_dist=True,
135
+ )
136
+
137
+ fresh = MyModel()
138
+ dcp.load(
139
+ fresh.state_dict(),
140
+ storage_reader=WeftStorageReader("run-0001", store_root="/data/weft-store"),
141
+ no_dist=True,
142
+ )
143
+ ```
144
+
145
+ Async save (the encode/store work runs on a `ThreadPoolExecutor` worker, with a
146
+ hard per-tensor staging bound; tensors are still copied through host memory):
147
+
148
+ ```python
149
+ from weftcodec.dcp import save_checkpoint_async
150
+
151
+ handle = save_checkpoint_async(
152
+ model.state_dict(),
153
+ checkpoint_id="run-0002",
154
+ store_root="/data/weft-store",
155
+ topology=8,
156
+ staging_bytes=256 * 1024 * 1024, # 256 MiB bound on one resolved tensor copy
157
+ )
158
+ metadata = handle.result() # raises the save error on this thread
159
+ ```
160
+
161
+ Every checkpoint is a canonical `weft.checkpoint.v1` manifest plus mode-10 or
162
+ exact codec shards; the DCP metadata is canonical WCB at
163
+ `/checkpoints/<name>/dcp.metadata`. The adapter verifies each tensor's BLAKE3
164
+ content root against the Rust manifest before/after every transfer. Verify with:
165
+
166
+ ```sh
167
+ weftfs --store /data/weft-store checkpoint verify --name run-0001 --json
168
+ weftfs --store /data/weft-store verify --full --json
169
+ ```
170
+
171
+ A checkpoint written by the Rust CLI alone (plain safetensors tensor names) is
172
+ readable too: the adapter synthesises DCP metadata from the manifest and reports
173
+ `reader.metadata_source == "manifest"`. Supported tensor dtypes are exactly the
174
+ WEFT-TENSOR v1 set (`f16`, `bf16`, `f32`, `f64`, `i8`, `u8`, `i16`, `i32`,
175
+ `i64`); everything else is rejected, never coerced. ShardedTensor, DTensor and
176
+ custom `planner_data` are not persisted. See `docs/PYTORCH-DCP.md` for the full
177
+ contract and non-claims.
178
+
179
+ ### JAX / Orbax adapter
180
+
181
+ `weftcodec.orbax` is an Orbax `AsyncCheckpointHandler` that stores a JAX PyTree
182
+ as one canonical `weft.checkpoint.v1` checkpoint through the same Rust CLI and
183
+ the same adapter plumbing as the DCP path. Each flattened leaf is recorded in a
184
+ canonical WCB `weft.orbax.v1` record with its path, dtype, shape, BLAKE3 content
185
+ root and logical root; the Orbax directory only carries a small canonical
186
+ locator pointing at the store.
187
+
188
+ ```python
189
+ import jax
190
+ from weftcodec.orbax import WeftOrbaxHandler, WeftSaveArgs, WeftRestoreArgs
191
+
192
+ handler = WeftOrbaxHandler(staging_bytes=256 * 1024 * 1024)
193
+ target = jax.tree_util.tree_map(
194
+ lambda a: jax.ShapeDtypeStruct(a.shape, a.dtype, sharding=a.sharding), params
195
+ )
196
+ # Drive it with orbax.checkpoint.Checkpointer, AsyncCheckpointer, or
197
+ # CheckpointManager:
198
+ # save(directory, args=WeftSaveArgs(
199
+ # item=params, store_root="/data/weft-store", checkpoint_id="run-0001"))
200
+ # restore(directory, args=WeftRestoreArgs(item=target))
201
+ ```
202
+
203
+ Supported leaf dtypes are the same exact WEFT-TENSOR v1 set. A target PyTree
204
+ with a missing, extra, differently typed, or differently shaped leaf fails
205
+ closed; different JAX sharding topologies are accepted because the stored
206
+ logical tensor is topology independent. `staging_bytes` bounds the staging
207
+ container and the restored bytes. See `docs/JAX-ORBAX.md` for the full contract,
208
+ measured comparison against Orbax's own OCDBT checkpoint, and non-claims (CPU
209
+ only, single process, no TPU/GPU, no multi-host JAX).
210
+
211
+ ## Supported modes
212
+
213
+ | Mode | Value | Python reader |
214
+ |---|---:|---|
215
+ | `RAW` | 0 | implemented |
216
+ | `ZSTD` | 1 | implemented (`zstandard`) |
217
+ | `REFERENCE` | 2 | implemented |
218
+ | `DELTA` | 3 | implemented |
219
+ | `DICTIONARY` | 4 | implemented (raw-content zstd dictionary) |
220
+ | `STRUCTURED` | 5 | implemented (canonical WCB validation) |
221
+ | `TENSOR` | 6 | implemented (descriptor validation) |
222
+ | `TOKEN_SEQUENCE` | 7 | implemented (descriptor + varint payload) |
223
+ | `QUANTIZED_TENSOR` | 8 | implemented (descriptor validation) |
224
+ | `FLOAT_TENSOR` | 9 | implemented (all five dtypes, `huffman-canonical-v1` exponent plane) |
225
+ | `TENSOR_SHARDED` | 10 | implemented (q4_0/q8_0 shards, plane verification, shard-set root) |
226
+ | `WEIGHT_DELTA` | 11 | implemented (base resolution, modular word subtraction, `delta_root`) |
227
+ | `KV_CACHE` | 12 | implemented (one page per frame, byte-plane decode) |
228
+ | `ACTIVATION_STREAM` | 13 | implemented (one chunk per frame, `digest_root`, stream root) |
229
+ | `SEMANTIC_DELTA` | 14 | implemented (policy verification against the resolved base) |
230
+ | `TENSOR_TILED` | 15 | implemented (per-tile roots and whole-tensor logical root) |
231
+ | `SPARSE_DELTA` | 16 | implemented (`zero-run-v1`, `delta_root`) |
232
+
233
+ Every allocated mode 0–18 is implemented. There is no approximate or lossy
234
+ decode path. Reserved mode values 17–127 and experimental values 128–255 are
235
+ rejected by `weftcodec.frame` with `UnsupportedMode`.
236
+
237
+ The reader is deliberately a decoder, not a WEFT-TENSOR container reader: it
238
+ does not claim WeftQL selectors, Context Roots, capability envelopes,
239
+ `weft.checkpoint.v1` manifests, WFA1 archives, or `weft.tensor.layout.v1` /
240
+ `weft.tensor.shard.v1` records. `TENSOR_TILED` supports full decode; the
241
+ region reader is not implemented in Python.
242
+
243
+ ## Tests
244
+
245
+ ```sh
246
+ pytest -q
247
+ ```
248
+
249
+ The suite consumes `../WeftCodec/conformance/v1/**` (Rust-generated vectors) and
250
+ runs the Rust CLI for cross-language encode/decode checks when
251
+ `/work/.docker-cache/target-rust/release/weftcodec` is available. The PyTorch test
252
+ uses `pytest.importorskip("torch")`.
253
+
254
+ `test_ai_modes.py` decodes every valid AI-mode vector to its recorded bytes and
255
+ recomputes every recorded root; `test_random_differential.py` generates at least
256
+ 2,000 frames per mode 9–16 from a deterministic PRNG and compares the Python
257
+ reader against the Rust CLI on every frame, plus 1,600 body mutants.
@@ -0,0 +1,229 @@
1
+ # weftcodec (Python)
2
+
3
+ An independent Python implementation of the WeftCodec v1 **reader**: WFT1 frame
4
+ parsing, canonical WCB decode/encode, domain-separated BLAKE3 content roots, and
5
+ a PyTorch-facing dataset over a mounted WeftFS directory.
6
+
7
+ There are **no Rust or Go extension modules**. This is a third implementation,
8
+ written from the normative specification and tested against Rust-generated
9
+ conformance vectors.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ pip install dist/weftcodec-1.2.0-py3-none-any.whl
15
+ # with the optional dataset extra
16
+ pip install "dist/weftcodec-1.2.0-py3-none-any.whl[torch]"
17
+ # with the optional JAX/Orbax adapter extra
18
+ pip install "dist/weftcodec-1.2.0-py3-none-any.whl[orbax]"
19
+ ```
20
+
21
+ Dependencies: `blake3`, `zstandard`. `torch`, `jax`, and `orbax-checkpoint`
22
+ are optional and are only imported by their adapter modules.
23
+
24
+ > **PyPI publication requires an API token we do not have.** The wheel is built
25
+ > in the Docker court and attached to the GitHub release; it is not published to
26
+ > PyPI.
27
+
28
+ ## Usage
29
+
30
+ ```sh
31
+ python -m weftcodec verify FRAME # validate structure + hashes
32
+ python -m weftcodec decode FRAME OUT # exact plaintext bytes
33
+ python -m weftcodec inspect FRAME # metadata as JSON
34
+ python -m weftcodec verify FRAME --deps DEPS_DIR # REFERENCE/DELTA/DICTIONARY
35
+ ```
36
+
37
+ Exit codes: `0` success, `1` codec or I/O failure, `2` usage error.
38
+
39
+ ```python
40
+ from weftcodec import parse, content_root, verify_frame
41
+ from weftcodec.dependency import DirectoryResolver
42
+ from weftcodec.modes import decode_bytes
43
+
44
+ resolver = DirectoryResolver("deps") # files named by lowercase hex
45
+ frame_bytes = open("frame.wft1", "rb").read()
46
+ frame = parse(frame_bytes)
47
+ plaintext = decode_bytes(frame_bytes, resolver)
48
+ assert content_root(plaintext) == frame.header.content_hash
49
+
50
+ result = verify_frame("frame.wft1", resolver)
51
+ print(result.ok, result.mode, result.content_hash, result.computed_content_hash)
52
+ ```
53
+
54
+ ### WCB
55
+
56
+ ```python
57
+ from weftcodec import wcb
58
+
59
+ value = wcb.decode(bytes.fromhex("08030501610301050162050374776f05016300"))
60
+ assert wcb.encode(value) == bytes.fromhex("08030501610301050162050374776f05016300")
61
+ ```
62
+
63
+ Python/WCB mapping: `None`→null, `bool`, `U64`, `I64`, `str`, `bytes`,
64
+ `list`/`tuple`, `dict` (text keys), `Timestamp`. Map keys are sorted by their
65
+ full encoded bytes; duplicates are rejected.
66
+
67
+ ### PyTorch dataset
68
+
69
+ ```python
70
+ from weftcodec.torch import WeftMapDataset
71
+
72
+ dataset = WeftMapDataset("/mnt/weft/dataset")
73
+ path, raw = dataset[0] # (relative path, bytes)
74
+
75
+ import torch
76
+ tensors = WeftMapDataset("/mnt/weft/dataset", dtype=torch.uint8)
77
+ path, tensor = tensors[0] # torch.frombuffer view
78
+ ```
79
+
80
+ Entries are sorted by POSIX-relative path, so ordering is deterministic across
81
+ processes.
82
+
83
+ ### PyTorch Distributed Checkpoint adapter
84
+
85
+ `weftcodec.dcp` implements the shape of
86
+ `torch.distributed.checkpoint.StorageWriter` / `StorageReader` over a WeftFS
87
+ store. The training process does not need a FUSE mount: every durable byte goes
88
+ through the Rust `weftfs` CLI (`checkpoint write` / `checkpoint restore`).
89
+
90
+ ```python
91
+ import torch
92
+ import torch.distributed.checkpoint as dcp
93
+ from weftcodec.dcp import WeftStorageWriter, WeftStorageReader, init_store
94
+
95
+ init_store("/data/weft-store")
96
+
97
+ model = MyModel()
98
+ dcp.save(
99
+ model.state_dict(),
100
+ storage_writer=WeftStorageWriter(
101
+ "run-0001", # single WeftFS checkpoint name
102
+ store_root="/data/weft-store",
103
+ topology=8, # store every tensor split 8 ways on axis 0
104
+ shard_strategy="zstd", # exact; tensor-sharded is the mode-10 option
105
+ ),
106
+ no_dist=True,
107
+ )
108
+
109
+ fresh = MyModel()
110
+ dcp.load(
111
+ fresh.state_dict(),
112
+ storage_reader=WeftStorageReader("run-0001", store_root="/data/weft-store"),
113
+ no_dist=True,
114
+ )
115
+ ```
116
+
117
+ Async save (the encode/store work runs on a `ThreadPoolExecutor` worker, with a
118
+ hard per-tensor staging bound; tensors are still copied through host memory):
119
+
120
+ ```python
121
+ from weftcodec.dcp import save_checkpoint_async
122
+
123
+ handle = save_checkpoint_async(
124
+ model.state_dict(),
125
+ checkpoint_id="run-0002",
126
+ store_root="/data/weft-store",
127
+ topology=8,
128
+ staging_bytes=256 * 1024 * 1024, # 256 MiB bound on one resolved tensor copy
129
+ )
130
+ metadata = handle.result() # raises the save error on this thread
131
+ ```
132
+
133
+ Every checkpoint is a canonical `weft.checkpoint.v1` manifest plus mode-10 or
134
+ exact codec shards; the DCP metadata is canonical WCB at
135
+ `/checkpoints/<name>/dcp.metadata`. The adapter verifies each tensor's BLAKE3
136
+ content root against the Rust manifest before/after every transfer. Verify with:
137
+
138
+ ```sh
139
+ weftfs --store /data/weft-store checkpoint verify --name run-0001 --json
140
+ weftfs --store /data/weft-store verify --full --json
141
+ ```
142
+
143
+ A checkpoint written by the Rust CLI alone (plain safetensors tensor names) is
144
+ readable too: the adapter synthesises DCP metadata from the manifest and reports
145
+ `reader.metadata_source == "manifest"`. Supported tensor dtypes are exactly the
146
+ WEFT-TENSOR v1 set (`f16`, `bf16`, `f32`, `f64`, `i8`, `u8`, `i16`, `i32`,
147
+ `i64`); everything else is rejected, never coerced. ShardedTensor, DTensor and
148
+ custom `planner_data` are not persisted. See `docs/PYTORCH-DCP.md` for the full
149
+ contract and non-claims.
150
+
151
+ ### JAX / Orbax adapter
152
+
153
+ `weftcodec.orbax` is an Orbax `AsyncCheckpointHandler` that stores a JAX PyTree
154
+ as one canonical `weft.checkpoint.v1` checkpoint through the same Rust CLI and
155
+ the same adapter plumbing as the DCP path. Each flattened leaf is recorded in a
156
+ canonical WCB `weft.orbax.v1` record with its path, dtype, shape, BLAKE3 content
157
+ root and logical root; the Orbax directory only carries a small canonical
158
+ locator pointing at the store.
159
+
160
+ ```python
161
+ import jax
162
+ from weftcodec.orbax import WeftOrbaxHandler, WeftSaveArgs, WeftRestoreArgs
163
+
164
+ handler = WeftOrbaxHandler(staging_bytes=256 * 1024 * 1024)
165
+ target = jax.tree_util.tree_map(
166
+ lambda a: jax.ShapeDtypeStruct(a.shape, a.dtype, sharding=a.sharding), params
167
+ )
168
+ # Drive it with orbax.checkpoint.Checkpointer, AsyncCheckpointer, or
169
+ # CheckpointManager:
170
+ # save(directory, args=WeftSaveArgs(
171
+ # item=params, store_root="/data/weft-store", checkpoint_id="run-0001"))
172
+ # restore(directory, args=WeftRestoreArgs(item=target))
173
+ ```
174
+
175
+ Supported leaf dtypes are the same exact WEFT-TENSOR v1 set. A target PyTree
176
+ with a missing, extra, differently typed, or differently shaped leaf fails
177
+ closed; different JAX sharding topologies are accepted because the stored
178
+ logical tensor is topology independent. `staging_bytes` bounds the staging
179
+ container and the restored bytes. See `docs/JAX-ORBAX.md` for the full contract,
180
+ measured comparison against Orbax's own OCDBT checkpoint, and non-claims (CPU
181
+ only, single process, no TPU/GPU, no multi-host JAX).
182
+
183
+ ## Supported modes
184
+
185
+ | Mode | Value | Python reader |
186
+ |---|---:|---|
187
+ | `RAW` | 0 | implemented |
188
+ | `ZSTD` | 1 | implemented (`zstandard`) |
189
+ | `REFERENCE` | 2 | implemented |
190
+ | `DELTA` | 3 | implemented |
191
+ | `DICTIONARY` | 4 | implemented (raw-content zstd dictionary) |
192
+ | `STRUCTURED` | 5 | implemented (canonical WCB validation) |
193
+ | `TENSOR` | 6 | implemented (descriptor validation) |
194
+ | `TOKEN_SEQUENCE` | 7 | implemented (descriptor + varint payload) |
195
+ | `QUANTIZED_TENSOR` | 8 | implemented (descriptor validation) |
196
+ | `FLOAT_TENSOR` | 9 | implemented (all five dtypes, `huffman-canonical-v1` exponent plane) |
197
+ | `TENSOR_SHARDED` | 10 | implemented (q4_0/q8_0 shards, plane verification, shard-set root) |
198
+ | `WEIGHT_DELTA` | 11 | implemented (base resolution, modular word subtraction, `delta_root`) |
199
+ | `KV_CACHE` | 12 | implemented (one page per frame, byte-plane decode) |
200
+ | `ACTIVATION_STREAM` | 13 | implemented (one chunk per frame, `digest_root`, stream root) |
201
+ | `SEMANTIC_DELTA` | 14 | implemented (policy verification against the resolved base) |
202
+ | `TENSOR_TILED` | 15 | implemented (per-tile roots and whole-tensor logical root) |
203
+ | `SPARSE_DELTA` | 16 | implemented (`zero-run-v1`, `delta_root`) |
204
+
205
+ Every allocated mode 0–18 is implemented. There is no approximate or lossy
206
+ decode path. Reserved mode values 17–127 and experimental values 128–255 are
207
+ rejected by `weftcodec.frame` with `UnsupportedMode`.
208
+
209
+ The reader is deliberately a decoder, not a WEFT-TENSOR container reader: it
210
+ does not claim WeftQL selectors, Context Roots, capability envelopes,
211
+ `weft.checkpoint.v1` manifests, WFA1 archives, or `weft.tensor.layout.v1` /
212
+ `weft.tensor.shard.v1` records. `TENSOR_TILED` supports full decode; the
213
+ region reader is not implemented in Python.
214
+
215
+ ## Tests
216
+
217
+ ```sh
218
+ pytest -q
219
+ ```
220
+
221
+ The suite consumes `../WeftCodec/conformance/v1/**` (Rust-generated vectors) and
222
+ runs the Rust CLI for cross-language encode/decode checks when
223
+ `/work/.docker-cache/target-rust/release/weftcodec` is available. The PyTorch test
224
+ uses `pytest.importorskip("torch")`.
225
+
226
+ `test_ai_modes.py` decodes every valid AI-mode vector to its recorded bytes and
227
+ recomputes every recorded root; `test_random_differential.py` generates at least
228
+ 2,000 frames per mode 9–16 from a deterministic PRNG and compares the Python
229
+ reader against the Rust CLI on every frame, plus 1,600 body mutants.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "weftcodec"
7
+ version = "1.2.0"
8
+ description = "Independent Python reader for Weft WFT1 frames and canonical WCB, with a PyTorch-facing dataset over a WeftFS mount"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "WeftFS contributors" }]
13
+ keywords = ["weft", "weftfs", "codec", "wft1", "wcb", "blake3", "pytorch"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "License :: OSI Approved :: Apache Software License",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Topic :: System :: Filesystems",
25
+ ]
26
+ dependencies = ["blake3>=0.3.1", "zstandard>=0.22"]
27
+
28
+ [project.optional-dependencies]
29
+ torch = ["torch"]
30
+ orbax = ["jax[cpu]>=0.4", "orbax-checkpoint>=0.5"]
31
+
32
+ [project.scripts]
33
+ weftcodec-py = "weftcodec.cli:main"
34
+
35
+ [project.urls]
36
+ Source = "https://github.com/infinityabundance/WeftFS"
37
+
38
+ [tool.setuptools]
39
+ packages = ["weftcodec"]
40
+
41
+ [tool.pytest.ini_options]
42
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+