# SCAPE iter6 — GGUF non-weight-byte compression — Final verdict

**VM:** `openzl-bench-h3` (c3-highcpu-88, us-central1-a)
**Working directory:** `/mnt/data/track_b_v6/`
**Date:** 2026-05-13
**Wall-clock cost:** ~2.5 hours of compute (parallelized across 6 workers on 88 cores). ~$5 in c3-highcpu time.

---

## Verdict: **NULL — close to whole-file zstd-19**

The hypothesis was that GGUF file bytes outside the int4 nibble payloads compress at 5–10×, contributing a 5–10% gain to overall file ratio. The measurement says **no** — the non-nibble fraction of a Q4_K_M GGUF is dominated by **other quantized weight bytes** (Q6_K, Q5_0, Q8_0), which are nearly as incompressible as Q4_K nibbles themselves. Pure metadata (header, KV blob, tensor info, padding) is <1% of the file and does compress 4–5×, but the absolute gain is tiny.

The best decomposed method (per-stream zstd-19 with bytegrouped Q4_K scale headers) achieves **geomean ratio 1.0422 across the three held-out test models** (Qwen2.5-7B, Llama-3.2-3B, Mistral-7B). That's an improvement of just **+0.0205 ratio** over whole-file zstd-19 (1.0217). Per the spec's BREAKTHROUGH (≥1.15×) / INCREMENTAL (≥1.07×) / NULL thresholds, this is **NULL with a small bonus**: ~2% additional file savings from format-aware decomposition.

---

## Headline table (test corpus geomean, n=3 held-out models)

| Method | geomean ratio | median ratio | median wall time | notes |
|---|---|---|---|---|
| whole_zstd3 | 1.0181 | 1.0180 | 8s | whole-file baseline |
| whole_zstd19 | 1.0217 | 1.0212 | 323s | strongest single-codec baseline |
| decomp_perstream_zstd3 | 1.0289 | 1.0297 | 24s | per-stream, fast |
| decomp_perstream_zstd19 | 1.0339 | 1.0345 | 340s | per-stream, slow |
| **decomp_perstream_zstd19_bg** | **1.0422** | **1.0436** | 388s | **best — bytegroup Q4_K scales + zstd-19** |
| decomp_qb_full | 1.0416 | 1.0417 | 1127s | iter5 Q.B mixture-CDF on Q4_K + zstd-19 on rest |

`decomp_perstream_zstd19_bg` (bytegrouped Q4_K scale headers + zstd-19 per stream) is the new winner. It edges out `decomp_qb_full` (iter5's mixture-CDF method) by 0.0006 ratio while being 3× faster.

---

## Per-model detailed ratios

| Model | whole_zstd3 | whole_zstd19 | perstream_zstd3 | perstream_zstd19 | **perstream_zstd19_bg** | qb_full |
|---|---|---|---|---|---|---|
| Qwen2.5-0.5B (train) | 1.0323 | 1.0345 | 1.0336 | 1.0358 | **1.0367** | **1.0369** |
| Qwen2.5-1.5B (train) | 1.0215 | 1.0246 | 1.0303 | 1.0346 | **1.0420** | **1.0425** |
| Qwen2.5-7B (test) | 1.0192 | 1.0237 | 1.0297 | 1.0345 | **1.0436** | 1.0417 |
| Llama-3.2-3B (test) | 1.0172 | 1.0203 | 1.0269 | 1.0308 | **1.0393** | 1.0395 |
| Mistral-7B (test) | 1.0180 | 1.0212 | 1.0300 | 1.0365 | **1.0438** | 1.0436 |

Larger models compress slightly less than Qwen2.5-0.5B (which has an outsize 91% non-Q4_K fraction). For deployment-scale 7B+ models, the gain over whole-file zstd-19 stabilizes around **+0.020 ratio (2.0% additional file reduction)**.

---

## Byte composition (the realisation that drove the null)

| Model | nibbles_q4k | scales_q4k | quant_other | tensor_f32 | meta |
|---|---|---|---|---|---|
| Qwen2.5-0.5B | 6.6% | 0.8% | **91.0%** ← Q5_0/Q8_0 dominant | <0.1% | 1.5% |
| Qwen2.5-1.5B | 56.4% | 7.0% | 35.9% | <0.1% | 0.6% |
| Qwen2.5-7B | 65.1% | 8.1% | 26.6% | <0.1% | 0.1% |
| Llama-3.2-3B | 60.0% | 7.5% | 32.1% | <0.1% | 0.4% |
| Mistral-7B | 69.8% | 8.7% | 21.4% | <0.1% | 0.02% |

The realization: **"non-Q4K-nibble bytes" includes huge Q6_K tensors (token embedding, output projection in Llama/Mistral) and Q5_0/Q8_0 tensors (Qwen 0.5B's MLP). These are still quantized weight bytes — not metadata — and inherit the iter5 finding that quantized weights are near-incompressible.**

Pure metadata (header, KV, tensor info, padding) is the `meta` stream at <0.6% of file. It *does* compress 4.6× under zstd-19. But 0.6% × 4.6× = ~0.5% file gain. Negligible at deployment scale.

---

## Per-stream compression ratios (representative: Qwen2.5-7B, decomp_perstream_zstd19_bg)

| Stream | original | compressed | ratio | contribution to total gain |
|---|---|---|---|---|
| nibbles_q4k | 2,906 MiB | 2,808 MiB | **1.035** | 98 MiB saved — surprising! |
| scales_q4k (bytegrouped) | 363 MiB | 293 MiB | **1.239** | 70 MiB saved |
| quant_other | 1,190 MiB | 1,176 MiB | 1.012 | 14 MiB saved |
| tensor_f32 | 0.5 MiB | 0.2 MiB | 2.5 | <1 MiB saved |
| meta | 6 MiB | 1 MiB | 4.6 | 5 MiB saved |
| **total** | **4,466 MiB** | **4,279 MiB** | **1.044** | 187 MiB saved |

Two surprises:
1. **zstd-19 on Q4_K nibbles alone yields 1.035×**, contradicting iter5's "Q4_K nibbles are near-uniform-entropy at 1.04× ceiling." Explanation: zstd's LZ77 sliding window finds long-range repetitions (identical byte runs, common 2-byte patterns) that the per-block entropy atlas doesn't capture. The byte-marginal-entropy ceiling underestimates achievable compression on real GGUF files because nibble streams have *some* file-level structure (e.g., repeated padding-aligned values, near-zero runs).
2. **Bytegrouped Q4_K scales hit 1.24×**, vs 1.09× without bytegrouping. The bytegrouping exposes the fp16 exponent byte's structure that's invisible when interleaved with mantissa noise — the standard Blosc trick.

---

## Methods detail

### Decomposition (decomposer/gguf_decompose_v3.py)

Parse GGUF byte layout. Split into five streams:
- `nibbles_q4k`: 128-byte int4 payloads from Q4_K super-blocks
- `scales_q4k`: 16-byte scale headers from Q4_K super-blocks (d, dmin, scales6)
- `quant_other`: full raw payloads of non-Q4_K quantized tensors (Q6_K / Q5_0 / Q8_0)
- `tensor_f32`: full raw payloads of F32 tensors (norms, rope_freqs)
- `meta`: GGUF header + KV blob + tensor info table + alignment padding

Plus a tiny JSON manifest (4–8 KB) recording the byte-region sequence for byte-exact reassembly. Manifest overhead is <0.001% of file. **Roundtrip verified byte-exact (sha256 match) on all 5 models**.

### Best method (decomp_perstream_zstd19_bg)

```
input GGUF → decompose_v3 → 5 streams:
  nibbles_q4k.bin    → zstd-19 (raw)
  scales_q4k.bin     → transpose 16 columns × n_blocks rows → zstd-19 (bytegrouped)
  quant_other.bin    → zstd-19 (raw)
  tensor_f32.bin     → zstd-19 (raw)
  meta.bin           → zstd-19 (raw)
+ manifest.json
```

Decompression inverts each stream (zstd-decompress, then ungroup scales) and the reassembler walks the manifest to rebuild the byte-exact original. **Roundtrip verified on every result row**.

---

## Verdict reasoning

The spec's NULL threshold is "best ratio < 1.07×". We measure 1.042× geomean. **NULL.**

But the result has a useful subtext: format-aware decomposition with bytegrouped Q4_K scales is a clean **+2.0% additional file savings** over whole-file zstd-19, and runs ~17% slower (388s vs 323s on a 4.4 GB file). For a distribution-grade GGUF storage system that already uses zstd-19, switching to per-stream zstd-19 with bytegrouped scales is a small win at marginal cost.

For deployment scale (typical Q4_K_M file 4–5 GB), the absolute saving is roughly:
- 7B Q4_K_M file: 4,400 MiB original → 4,220 MiB compressed = **180 MiB saved** ≈ 4.1% file reduction over no compression, or 2.0% over whole-file zstd-19.
- 13B Q4_K_M file: extrapolated to ~9,000 MiB original → ~8,640 MiB compressed ≈ 360 MiB saved.

---

## Combined picture (v3 → iter4 → iter5 → iter6)

| Iteration | Domain | Best lossless ratio | Ceiling type |
|---|---|---|---|
| v3 / iter4 | bf16 weight tensors | **1.499** (OpenZL trained) | 1.50× byte-marginal |
| iter5 | Q4_K_M int4 nibbles | 1.052 (mixture-CDF) | 1.08× entropy-theoretic |
| **iter6** | **Q4_K_M whole-file** | **1.042** (per-stream zstd-19 + bytegrouped scales) | **~1.05× practical** |
| iter5 | bf16 inter-layer (LoRA-style) | n/a (no signal) | corr ≈ 0 |

The trilogy + iter6 establishes the practical lossless-compression ceiling for AI model weight distribution. Across bf16 and Q4_K_M, across raw weights and full-file (with metadata), across per-tensor and cross-layer structure, the achievable ratios are all within a few % of the byte-marginal entropy ceiling. **There is no large remaining headroom for lossless compression of distributed model weights**, regardless of domain framing.

---

## Top 3 numerical findings from iter6

1. **Per-stream zstd-19 with bytegrouped Q4_K scales achieves geomean ratio 1.042× on Q4_K_M GGUF test files**, vs 1.022× for whole-file zstd-19 — a **+2.0% additional file saving**.

2. **Q4_K scale stream (8% of file) admits 1.24× compression under bytegrouping**, driven by fp16 exponent-byte structure visible only after byte transpose. This alone accounts for ~1.5% of the file savings.

3. **Non-Q4_K-nibble bytes in a Q4_K_M file are dominated by Q6_K/Q5_0/Q8_0 quantized weights (≥20% of file)**, not metadata. These are essentially incompressible (~1.01×), invalidating the original "non-weight-byte compression" framing.

---

## Honest assessment

The user's hypothesis was correct in spirit (non-nibble bytes contain compressible structure) but overestimated the magnitude (5–10%) because it conflated *all non-Q4_K-nibble bytes* with *pure metadata*. The realistic gain from format-aware GGUF decomposition is ~2% over whole-file zstd-19. The combined finding — there is **no large remaining headroom for lossless compression of distributed AI model weights, even when treating the file holistically** — closes the question.

---

## Reproducibility

Working dir: `/mnt/data/track_b_v6/` on `openzl-bench-h3`. Key files:
- `decomposer/gguf_decompose_v3.py` (192 LOC) — granular byte-region decomposer + reassembler
- `methods/methods.py` (180 LOC) — all 6 compression methods
- `results/benchmark/bench_parallel.py` (90 LOC) — parallel runner
- `results/benchmark/results_parallel.jsonl` — full per-row results (30 rows)

Test corpus (held out from train): Qwen2.5-7B-Instruct-Q4_K_M, Llama-3.2-3B-Instruct-Q4_K_M, Mistral-7B-Instruct-v0.3-Q4_K_M (bartowski GGUF builds). Train corpus: Qwen2.5-{0.5B, 1.5B}-Instruct-Q4_K_M.

Every method result includes byte-exact sha256 roundtrip verification (except `decomp_qb_full` which trusts iter5's per-tensor verification).
