SNAPKITTYWEST commited on
Commit
be4e085
Β·
verified Β·
1 Parent(s): 9e551a1

Model card: restore full README from GitHub, add commercial license option

Browse files
Files changed (1) hide show
  1. README.md +526 -0
README.md CHANGED
@@ -14,3 +14,529 @@ tags:
14
 
15
  > Mirrored from [https://github.com/SNAPKITTYWEST/tensor-roll](https://github.com/SNAPKITTYWEST/tensor-roll) at commit `f8cb763`. Part of the **SnapKitty October 2026 main drop**.
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  > Mirrored from [https://github.com/SNAPKITTYWEST/tensor-roll](https://github.com/SNAPKITTYWEST/tensor-roll) at commit `f8cb763`. Part of the **SnapKitty October 2026 main drop**.
16
 
17
+ # TENSOR ROLL v1.0
18
+
19
+ **Recursive CUDA-Q Model Quantizer β€” compress a 30B-class teacher into an ~8B student under a hard parameter budget, from the terminal.**
20
+
21
+ ```
22
+ GLIMMER 30B β†’ TENSOR ROLL β†’ CUDA β†’ CUDA-Q β†’ Q# β†’ 8B NANO MODEL
23
+ ```
24
+
25
+ ![Tensor Roll demo](docs/tensor-roll-demo.png)
26
+
27
+ Tensor Roll treats model compression as a searchable computational system. A recursive
28
+ `TensorRoll(T, axis, depth, rank, quantum_policy)` operator partitions every tensor,
29
+ measures each partition (norm, rank, entropy, spectral contribution, reconstruction error),
30
+ and searches a global representation plan under a hard budget of **P ≀ 8.5B parameters**
31
+ (target ~8.0B). The resulting student is distilled with a 7-term loss, fine-tuned, exported
32
+ to FP16 / BF16 / INT8 / INT4 and a checksummed `.trq` container β€” then served from a
33
+ sandboxed terminal runtime.
34
+
35
+ Everything is written from scratch on NumPy: the tensor core, the transformer,
36
+ distillation, the quantizers, the `.trq` codec, the OS sandbox, and the CLI.
37
+ Every execution report carries an honest backend label β€” `cpu-numpy`, `qsim-classical`,
38
+ or `unavailable` β€” so a backend is never claimed that wasn't actually executed.
39
+
40
+ ## Features
41
+
42
+ - **Recursive TensorRoll operator** β€” `TensorRoll(T, axis, depth, rank, quantum_policy)`
43
+ recursively partitions tensors and evaluates eight decision classes per region
44
+ (`PRESERVE`, `QUANTIZE`, `FACTORIZE`, `MERGED`, `ROUTED`, `RECONSTRUCTED`,
45
+ `PRUNED`, `QUANTUM-ENCODED`) from measured (cost, retained-energy, error) triples.
46
+ - **Out-of-core streaming (Rule Zero)** β€” the teacher is never required in RAM.
47
+ Sharded, memory-mapped ingestion with a configurable working-set ceiling
48
+ (`--memory-budget`), recursive tensor windowing, explicit eviction, and
49
+ checkpoint/resume.
50
+ - **SCAN β†’ PLAN β†’ EXECUTE global budget planner** β€” lightweight scan, global
51
+ allocation solved under Ξ£ target ≀ 8.5B, then streaming execution.
52
+ Sensitivity-aware: budget flows non-uniformly to the tensors that earn it.
53
+ - **From-scratch NumPy core** β€” no PyTorch, Transformers, llama.cpp, or ONNX
54
+ wrappers. The only runtime dependency is NumPy.
55
+ - **7-term recursive distillation** β€” task, logits, hidden-state, attention,
56
+ embedding, reconstruction, and roll losses, with resumable stages 0–7.
57
+ - **FP16 / BF16 / INT8 / INT4 + `.trq`** β€” multiple physical exports plus the
58
+ Tensor Roll container format: magic header, tensor index, quantization
59
+ metadata, codebooks, per-tensor and file-level SHA-256 checksums, provenance.
60
+ - **OS-level sandbox** β€” process-group isolation, resource limits, environment
61
+ filtering, jail path policy, allow/deny binary policy, network namespace
62
+ isolation, and a JSONL audit log. Model tool requests route through the
63
+ sandbox supervisor.
64
+ - **14-command terminal CLI** β€” one coherent surface (`tensor-roll`) from
65
+ ingestion to chat, plus `tensor-roll doctor` for the backend capability report.
66
+ - **Honest backend dispatch** β€” classical GEMM, CUDA-Q kernels, and Q# operations
67
+ share one dispatch boundary with explicit per-invocation reporting
68
+ (backend, device, dims, precision, time, memory, depth, shots, reconstruction
69
+ error). `tensor-roll doctor` distinguishes *source present* from
70
+ *backend executed*.
71
+
72
+ ![Tensor Roll architecture](docs/img/architecture.png)
73
+
74
+ ## A novel method, executed
75
+
76
+ Tensor Roll is not a compression proposal β€” it is a compression method that
77
+ runs. What is novel is the composition, and every piece of it exists as code
78
+ in this repository:
79
+
80
+ **1. The recursive `TensorRoll` operator is the compression primitive.**
81
+ Most quantizers apply one fixed recipe (prune, quantize, hope).
82
+ `TensorRoll(T, axis, depth, rank, quantum_policy)` β€” implemented in
83
+ `tensor_roll/core.py` β€” recursively partitions every tensor, measures each
84
+ partition (norm, SVD rank, entropy, variance, spectral contribution,
85
+ reconstruction error), and *searches* a representation per region from eight
86
+ decision classes: `PRESERVE`, `QUANTIZE`, `FACTORIZE`, `MERGED`, `ROUTED`,
87
+ `RECONSTRUCTED`, `PRUNED`, `QUANTUM-ENCODED`. The decision is data-driven,
88
+ per region, per recursion level β€” executed by `tensor-roll roll`.
89
+
90
+ ![The TensorRoll operator](docs/img/flow-operator.png)
91
+
92
+ **2. Rule Zero: the model is never required in RAM.**
93
+ `tensor_roll/ooc.py` streams the teacher through sharded, memory-mapped
94
+ windows with a hard working-set ceiling (`--memory-budget`), explicit
95
+ eviction, and crash-safe checkpoint/resume. A 30.19B-parameter manifest is
96
+ planned to an 8.000B target in under 0.1 s at 35 MB peak RSS with zero
97
+ weights allocated β€” the planner reasons over metadata, not tensors.
98
+
99
+ **3. SCAN β†’ PLAN β†’ EXECUTE solves the budget globally.**
100
+ `tensor_roll/planner.py` scans cheaply, then allocates the ≀ 8.5B budget
101
+ across all tensors with a sensitivity-aware greedy knapsack over measured
102
+ (cost, retained-energy) pairs β€” budget flows non-uniformly to the tensors
103
+ that earn it β€” before streaming execution begins. One global plan, not
104
+ greedy layer-by-layer heuristics.
105
+
106
+ **4. Heterogeneous dispatch with honest backend states.**
107
+ `tensor_roll/boundary.py` lowers one backend-neutral TensorRoll IR
108
+ (`LOAD Β· ROLL Β· GEMM Β· QUANTIZE Β· EMIT`, `tensor_roll/ir.py`) to CPU-NumPy,
109
+ CUDA, CUDA-Q, and Q# (`cuda/`, `cudaq/`, `qsharp/`). `tensor-roll doctor`
110
+ (`tensor_roll/doctor.py`) probes every backend at runtime and reports
111
+ `AVAILABLE` / `UNAVAILABLE` / `NOT EXECUTED` per invocation β€” source present
112
+ is never reported as backend executed.
113
+
114
+ ![Honest heterogeneous dispatch](docs/img/flow-dispatch.png)
115
+
116
+ **5. The `.trq` artifact is versioned, checksummed, and self-describing.**
117
+ `tensor_roll/trq.py` writes `TRQ1` containers: JSON header, per-tensor index
118
+ with dtype/quant codes, codebooks, per-tensor and file-level SHA-256, and
119
+ provenance records. Corrupt or tampered artifacts are rejected on load β€”
120
+ verified by round-trip tests across all five variants
121
+ (FP32 / FP16 / BF16 / INT8 / INT4).
122
+
123
+ Executed means: 70/70 tests green, 14/14 CLI commands live, and every number
124
+ in the [Measured benchmarks](#measured-benchmarks) gallery below was produced
125
+ by running this code on a real machine.
126
+
127
+ ## Requirements
128
+
129
+ Python 3.10+ and NumPy. CPU + NumPy runs everywhere; CUDA, CUDA-Q, and Q#
130
+ backends activate automatically when the hardware/toolchain is present β€”
131
+ `tensor-roll doctor` reports exactly what is available on your machine.
132
+
133
+ ## Installation
134
+
135
+ ```bash
136
+ git clone https://github.com/AHMADALIPARR/tensor-roll.git
137
+ cd tensor-roll
138
+ pip install .
139
+ ```
140
+
141
+ This installs the `tensor-roll` console script (`pyproject.toml`, setuptools).
142
+ For development, `pip install -e .` works the same way.
143
+
144
+ Verify:
145
+
146
+ ```bash
147
+ $ tensor-roll --help
148
+ usage: tensor-roll [-h] [--workdir WORKDIR]
149
+ {inspect,ingest,map,roll,qkernel,compress,train,finetune,quantize,evaluate,benchmark,chat,sandbox,demo}
150
+ ...
151
+
152
+ Tensor Roll β€” Recursive CUDA-Q Model Quantizer
153
+ ```
154
+
155
+ ## Quickstart
156
+
157
+ ![Tensor Roll pipeline](docs/img/flow-pipeline.png)
158
+
159
+ Check your backends, then run a tiny end-to-end pass:
160
+
161
+ ```bash
162
+ $ tensor-roll doctor
163
+ Tensor Roll Backend Report
164
+ CPU AVAILABLE
165
+ NumPy AVAILABLE
166
+ CUDA UNAVAILABLE
167
+ CUDA-Q UNAVAILABLE
168
+ Q# UNAVAILABLE
169
+ GPU NONE
170
+ CUDA source VERIFIED
171
+ CUDA-Q source VERIFIED
172
+ Q# source VERIFIED
173
+ Execution:
174
+ CPU PASS
175
+ CUDA NOT EXECUTED
176
+ CUDA-Q NOT EXECUTED
177
+ Q# NOT EXECUTED
178
+ ```
179
+
180
+ ```bash
181
+ $ tensor-roll --workdir ./tr-quick ingest --scale tiny --steps 20
182
+ training tiny teacher Config(vocab=32, d=48, heads=3, layers=2, dff=96, seq=16) (41.1K params, seed=11)
183
+ teacher: 41.1K params, held-out loss=3.0724 acc=0.149, 3.9s on cpu-numpy
184
+
185
+ $ tensor-roll --workdir ./tr-quick map
186
+ tensor shape params rank entropy spectral
187
+ L0.W1 [48, 96] 4608 48 3.632 0.055
188
+ L0.W2 [96, 48] 4608 48 3.607 0.059
189
+ L0.Wk [48, 48] 2304 48 3.377 0.077
190
+ ...
191
+
192
+ $ tensor-roll --workdir ./tr-quick roll --depth 2
193
+ [ROLL 0001] source: L0.W1/0/0 shape: [12, 96] depth: 2 params: 1152 rank: 12 entropy: 2.434 spectral: 0.125 cost: 288 retained-energy: 1.0000 recon-err: 4.60e-03 backend: cpu-numpy decision: QUANTIZE
194
+ [ROLL 0002] source: L0.W1/0/1 shape: [12, 96] depth: 2 params: 1152 rank: 12 entropy: 2.438 spectral: 0.123 cost: 288 retained-energy: 1.0000 recon-err: 4.61e-03 backend: cpu-numpy decision: QUANTIZE
195
+ ...
196
+ ```
197
+
198
+ The full demonstration runs the complete pipeline and drops into an inference REPL:
199
+
200
+ ```bash
201
+ $ tensor-roll demo --fast
202
+ ```
203
+
204
+ ![Tensor Roll terminal session](docs/img/quickstart-terminal.png)
205
+
206
+ ---
207
+
208
+ ## User Guide
209
+
210
+ Every command accepts a global `--workdir DIR` (default: `./tensor-roll-work`).
211
+ All examples below use real flags from `tensor-roll <cmd> --help`.
212
+
213
+ ### `inspect` β€” tensor inventory and metrics
214
+
215
+ Lists every tensor with shape, dtype, and Frobenius norm.
216
+
217
+ Flags: `--what {teacher,student,trq}`, `--trq TRQ`
218
+
219
+ ```bash
220
+ $ tensor-roll --workdir ./tr-quick inspect --what teacher
221
+ teacher: Config(vocab=32, d=48, heads=3, layers=2, dff=96, seq=16), 41.1K params
222
+ L0.W1 [48, 96] float32 ||.||=8.1667
223
+ L0.W2 [96, 48] float32 ||.||=8.1073
224
+ L0.Wk [48, 48] float32 ||.||=6.9597
225
+ ...
226
+ ```
227
+
228
+ ### `ingest` β€” build or load the teacher model
229
+
230
+ Trains a tiny from-scratch teacher (`--scale tiny`) or streams a large
231
+ teacher from sharded weights (`--scale 30b` with `--teacher` on `compress`).
232
+
233
+ Flags: `--scale {tiny,30b}`, `--steps`, `--batch`, `--lr`, `--seed`
234
+
235
+ ```bash
236
+ $ tensor-roll --workdir ./tr-quick ingest --scale tiny --steps 20
237
+ training tiny teacher Config(vocab=32, d=48, heads=3, layers=2, dff=96, seq=16) (41.1K params, seed=11)
238
+ teacher: 41.1K params, held-out loss=3.0724 acc=0.149, 3.9s on cpu-numpy
239
+ ```
240
+
241
+ ### `map` β€” per-tensor metric map
242
+
243
+ One row per tensor: parameter count, numerical rank, entropy, and spectral
244
+ contribution β€” the raw material the planner allocates budget from.
245
+
246
+ ```bash
247
+ $ tensor-roll --workdir ./tr-quick map
248
+ tensor shape params rank entropy spectral
249
+ L0.W1 [48, 96] 4608 48 3.632 0.055
250
+ L0.W2 [96, 48] 4608 48 3.607 0.059
251
+ ...
252
+ ```
253
+
254
+ ### `roll` β€” run the TensorRoll operator
255
+
256
+ Recursively partitions each tensor and prints one `[ROLL n]` line per leaf:
257
+ source, shape, depth, measured metrics, backend, and the selected decision.
258
+
259
+ Flags: `--depth`, `--quantum-policy {off,explore,selective}`, `--budget-ratio`
260
+
261
+ ```bash
262
+ $ tensor-roll --workdir ./tr-quick roll --depth 2 --quantum-policy explore
263
+ [ROLL 0001] source: L0.W1/0/0 shape: [12, 96] depth: 2 params: 1152 rank: 12 entropy: 2.434 spectral: 0.125 cost: 288 retained-energy: 1.0000 recon-err: 4.60e-03 backend: cpu-numpy decision: QUANTIZE
264
+ ...
265
+ ```
266
+
267
+ ### `qkernel` β€” the tensor_roll kernel family
268
+
269
+ Runs `tensor_roll_encode / rotate / entangle / measure / reconstruct /
270
+ recursive` on a tensor block through the quantum path, with full
271
+ per-invocation reporting and a checksummed boundary trace.
272
+
273
+ Flags: `--tensor`, `--shots`, `--encoding {amplitude,angle}`, `--seed`
274
+
275
+ ```bash
276
+ $ tensor-roll --workdir ./tr-quick qkernel --shots 512
277
+ tensor_roll kernel family on L0.W1(8, 8) (top-left 8x8 block, 64 elems -> 6 qubits, amplitude encoding)
278
+ tensor_roll_encode backend=qsim-classical device=cpu (statevector simulator) dims=[(8, 8), (64,)] prec=complex128 t=0.10ms mem=1.50KB depth=0 shots=β€” recon_err=β€”
279
+ tensor_roll_measure backend=qsim-classical device=cpu (statevector simulator) dims=[(64,)] prec=complex128 t=0.85ms mem=1.00KB depth=0 shots=512 outcomes=51 H=5.17b recon_err=β€”
280
+ tensor_roll_reconstruct backend=qsim-classical device=cpu (statevector simulator) dims=[(64,), (8, 8)] prec=float64 t=0.05ms mem=512.00B depth=0 shots=512 outcomes=51 H=5.17b recon_err=7.85e-01
281
+ ...
282
+ block rel recon error: 0.7850 (recursive: 0.1916) in 0.00s β€” backend qsim-classical (statevector simulator, NOT a QPU)
283
+ boundary trace: /tmp/trqs/qkernel/boundary.json (28 gates, 54 outcomes, sha256 verified, recon[0]=0.1531)
284
+ ```
285
+
286
+ ### `compress` β€” search the 8B representation
287
+
288
+ The core command. Runs SCAN β†’ PLAN β†’ EXECUTE: scans tensor statistics,
289
+ solves the global budget (Ξ£ target ≀ 8.5B, default target 8B), then streams
290
+ the transformation. `--out-of-core` enforces Rule Zero β€” the teacher is
291
+ memory-mapped and windowed, never fully loaded. `--resume` continues from
292
+ per-tensor checkpoints after an interruption.
293
+
294
+ Flags: `--budget-ratio`, `--seed`, `--teacher`, `--target-params`,
295
+ `--memory-budget`, `--out-of-core`, `--resume`
296
+
297
+ ```bash
298
+ # In-RAM path (small teachers)
299
+ $ tensor-roll --workdir ./tr-quick compress
300
+
301
+ # Streaming path (large teachers) β€” bounded 5G working set, resumable
302
+ $ tensor-roll compress --teacher /models/glimmer-30b \
303
+ --target-params 8B --memory-budget 5G --out-of-core
304
+ $ tensor-roll compress --out-of-core --resume
305
+ ```
306
+
307
+ ### `train` β€” recursive distillation stages
308
+
309
+ Distills the student against the teacher with the 7-term loss
310
+ (task + logits + hidden + attention + embedding + reconstruction + roll).
311
+ `--stage all` runs stages 0–7; any single stage can be re-run. Checkpoints
312
+ make training resumable and deterministic.
313
+
314
+ Flags: `--stage` (`all` or 0–7), `--steps`, `--batch`, `--lr`, `--seed`
315
+
316
+ ```bash
317
+ $ tensor-roll --workdir ./tr-quick train --stage all --steps 40
318
+ $ tensor-roll --workdir ./tr-quick train --stage 3 --steps 40 # re-run one stage
319
+ ```
320
+
321
+ ### `finetune` β€” task fine-tuning
322
+
323
+ Task fine-tuning pass on the distilled student.
324
+
325
+ Flags: `--steps`, `--batch`, `--seed`
326
+
327
+ ```bash
328
+ $ tensor-roll --workdir ./tr-quick finetune --steps 40
329
+ ```
330
+
331
+ ### `quantize` β€” FP16 / BF16 / INT8 / INT4 + `.trq` export
332
+
333
+ Converts the trained student into every physical representation and writes
334
+ the `.trq` containers with quantization metadata, codebooks, scales,
335
+ checksums, and provenance.
336
+
337
+ ```bash
338
+ $ tensor-roll --workdir ./tr-quick quantize
339
+ ```
340
+
341
+ ### `evaluate` β€” measured quality metrics
342
+
343
+ Reports measured quality of the student variants (perplexity, accuracy,
344
+ teacher divergence) β€” every number computed, none invented.
345
+
346
+ ```bash
347
+ $ tensor-roll --workdir ./tr-quick evaluate
348
+ ```
349
+
350
+ ### `benchmark` β€” measured comparison table
351
+
352
+ Side-by-side measured comparison across variants (parameters, artifact
353
+ size, load time, latency, tokens/sec, perplexity). Backends that cannot
354
+ execute on the machine are reported as not executed, never estimated.
355
+
356
+ ```bash
357
+ $ tensor-roll --workdir ./tr-quick benchmark
358
+ ```
359
+
360
+ ### `chat` β€” terminal inference REPL
361
+
362
+ Interactive inference against any exported variant, with optional
363
+ teacher/student side-by-side comparison.
364
+
365
+ Flags: `--variant {fp32,fp16,bf16,int8,int4}`, `--compare`, `--max-tokens`
366
+
367
+ ```bash
368
+ $ tensor-roll --workdir ./tr-quick chat --variant int8
369
+ $ tensor-roll --workdir ./tr-quick chat --variant int4 --compare --max-tokens 64
370
+ ```
371
+
372
+ ### `sandbox` β€” OS-level sandbox supervisor
373
+
374
+ Runs a command inside the sandbox or demonstrates the allow/deny policy.
375
+ See [Sandbox](#sandbox) below.
376
+
377
+ Flags: `--cmd CMD`, `--demo`
378
+
379
+ ```bash
380
+ $ tensor-roll sandbox --cmd "echo hello-from-the-jail"
381
+ $ tensor-roll sandbox --demo
382
+ jail: /tmp/trdoc/sandbox/jail netns_available=True
383
+ [ALLOW] ALLOW echo: policy pass
384
+ out: hello-tensor-roll
385
+ [ALLOW] ALLOW jail write+read: policy pass
386
+ out: jail-write-ok
387
+ [DENY] DENY shadow: absolute path outside jail rejected: /etc/shadow
388
+ [DENY] DENY curl: denied binary: curl
389
+ [DENY] DENY rm: denied binary: rm
390
+ audit log: /tmp/trdoc/sandbox/audit.log
391
+ ```
392
+
393
+ ### `demo` β€” full executable demonstration
394
+
395
+ Runs the entire pipeline end to end and drops into the inference REPL.
396
+ `--fast` uses reduced training steps (still real training).
397
+
398
+ Flags: `--fast`
399
+
400
+ ```bash
401
+ $ tensor-roll demo --fast
402
+ ```
403
+
404
+ ### `doctor` β€” backend capability report
405
+
406
+ Prints the backend matrix: what is available, what executed, and what did
407
+ not β€” with reasons. Also writes `doctor_report.json` with `--json`.
408
+
409
+ ```bash
410
+ $ tensor-roll doctor
411
+ $ tensor-roll doctor --json
412
+ ```
413
+
414
+ ---
415
+
416
+ ## The `.trq` Container Format
417
+
418
+ Tensor Roll artifacts ship as `.trq` files β€” a real binary codec
419
+ (`tensor_roll/trq.py`), little-endian, versioned, fully checksummed:
420
+
421
+ ![TRQ1 container layout](docs/img/trq-format.png)
422
+
423
+ ```
424
+ magic 4 bytes b'TRQ1'
425
+ header_len u32
426
+ header JSON {version, arch, n_tensors, provenance, roll_meta, created}
427
+ per tensor:
428
+ name_len u16
429
+ name bytes
430
+ ndim u8
431
+ shape ndim Γ— u64
432
+ dtype_code u8 0=fp32 1=fp16 2=bf16 3=int8 4=int4-packed
433
+ quant_code u8 0=none 1=int8-asym 2=int4-group32 3=fp16-cast 4=bf16-cast
434
+ meta_len u32
435
+ meta JSON {quantization metadata: scales/zeros (base64 f64),
436
+ roll metadata, codebooks}
437
+ data_len u64
438
+ data bytes
439
+ checksum 32 bytes sha256(data)
440
+ footer 32 bytes sha256(all preceding bytes)
441
+ ```
442
+
443
+ `read_trq()` verifies the file checksum and every per-tensor checksum and
444
+ raises on any mismatch β€” corrupt files never load silently.
445
+
446
+ Inspect any artifact:
447
+
448
+ ```bash
449
+ $ tensor-roll --workdir ./tr-quick inspect --what trq --trq student-int4.trq
450
+ ```
451
+
452
+ ## Sandbox
453
+
454
+ ![Sandbox supervisor](docs/img/sandbox.png)
455
+
456
+ Inference and training tools execute inside a constrained OS environment β€”
457
+ the model never implicitly inherits unrestricted host permissions:
458
+
459
+ - **Process isolation** β€” dedicated process groups, killed on timeout
460
+ - **Filesystem jail** β€” absolute paths outside the jail are rejected
461
+ - **Resource limits** β€” rlimits on CPU, memory, and process count
462
+ - **Network policy** β€” network namespace isolation (`CLONE_NEWNET`)
463
+ - **Binary policy** β€” explicit allow/deny list per command
464
+ - **Environment filtering** β€” the sandbox does not inherit the host env
465
+ - **Audit logging** β€” every decision appended to a JSONL audit log
466
+
467
+ Terminal commands requested by the model pass through the sandbox
468
+ supervisor:
469
+
470
+ ```
471
+ USER β†’ TERMINAL β†’ TENSOR ROLL β†’ MODEL β†’ TOOL REQUEST
472
+ β†’ SANDBOX SUPERVISOR β†’ POLICY β†’ DENY | EXECUTE (isolated process)
473
+ ```
474
+
475
+ ## Measured Results
476
+
477
+ Every number below was measured by running the test suite and the pipeline
478
+ on this machine (2 CPUs, 7 GB RAM, no GPU) β€” nothing estimated:
479
+
480
+ | Check | Result |
481
+ |---|---|
482
+ | Test suite | **70 / 70 pass** (`python -m unittest discover -s tests`) |
483
+ | CLI commands | **14 / 14 live** (+ `doctor` backend report) |
484
+ | Validation compression | teacher **41.1K** β†’ student **11.4K** = **27.8%** (target ratio 8.5/30 = **28.3%**) |
485
+ | Structural planning | virtual 30.19B-param manifest β†’ **8.000B** plan, < 0.1 s, 35 MB peak RSS |
486
+ | `.trq` round-trip | all variants verified, checksums enforced |
487
+ | Sandbox | allow demonstrated, deny demonstrated, audit log written |
488
+
489
+ ## Measured benchmarks
490
+
491
+ Every chart below plots numbers measured by running the pipeline and the
492
+ test suite on this machine (2 CPUs, 7 GB RAM, no GPU) β€” nothing estimated:
493
+
494
+ ![Compression β€” measured](docs/img/metrics-compression.png)
495
+ *Validation compression: teacher 41.1K β†’ student 11.4K params (27.8%),
496
+ against the 28.3% target ratio (8.5B / 30B).*
497
+
498
+ ![Student quality β€” measured perplexity](docs/img/metrics-quality.png)
499
+ *Measured student perplexity: INT8 8.39 vs INT4 15.13 β€” presented as recorded.*
500
+
501
+ ![Structural scale test β€” virtual 30B](docs/img/metrics-scale.png)
502
+ *Virtual 30B structural test: 30.19B-param manifest β†’ 8.000B plan in < 0.1 s,
503
+ 35 MB peak RSS, zero weights allocated.*
504
+
505
+ ![Verification suite β€” measured](docs/img/metrics-suite.png)
506
+ *70/70 tests pass, 14/14 CLI commands live, 5/5 `.trq` variants round-trip
507
+ verified, crash-resume recovery byte-identical.*
508
+
509
+ ## Layout
510
+
511
+ ```
512
+ tensor_roll/ Python package: core, qsim, model, search, distill, quant,
513
+ trq, sandbox, boundary, cli, ooc, planner, fidelity,
514
+ doctor, ir, conformance
515
+ cudaq/ real CUDA-Q kernels (tensor_roll_kernels.py)
516
+ qsharp/ real Q# operations (TensorRoll.qs)
517
+ cuda/ CUDA GEMM sources
518
+ docs/ ARCHITECTURE.md, BOUNDARIES.md, demo assets
519
+ docs/img/ v1.0 product imagery
520
+ experiments/ measured experiment reports (JSON)
521
+ tests/ 70 tests, all green
522
+ ```
523
+
524
+ ## Author
525
+
526
+ **Ahmad Parr** β€” <Ahmedparr93@gmail.com>
527
+
528
+ ## Version
529
+
530
+ **v1.0** (2026-09-29)
531
+
532
+ ## License
533
+
534
+ AGPL-3.0-or-later β€” see [LICENSE](LICENSE). Every source file carries the
535
+ SPDX header `AGPL-3.0-or-later`, Copyright (C) 2026 SnapKitty Collective.
536
+
537
+ ### πŸ’Ό Commercial License
538
+
539
+ SnapKitty code is free and open under **AGPL-3.0** for open-source use. Building a commercial product or service? A **proprietary commercial license** from Snapkitty Collective LLC lets you ship this code without the AGPL's source-sharing and network-use obligations.
540
+
541
+ **[β†’ Get a commercial license](mailto:A.parr@belespritdaccord.uk?subject=Commercial%20license:%20tensor-roll)** Β· A.parr@belespritdaccord.uk
542
+