# Tessera v2 Lab Report: Pure-Latent 2:1 k-d Tree Codec, Trials, Failures, and Future Pixel Head

> **Status, 2026-11-23.** Detailed companion to the article [Tessera: Content-Adaptive Image Tokenization in FLUX.2 Latent Space](tessera-content-adaptive-tokenization.html). All five curated-set arms and three of five held-out arms (R, RP, D) are complete. Held-out search (S) and RD-tree + prune (DP) are **pending**. A 512 to 4096 px resolution ladder is measured in [section 8](#8-higher-resolution-512-to-4096-px). See also the [interactive demo](https://artifacts.kelechi.cc/tessera_demo_v2/) and the [original proposal](https://artifacts.kelechi.cc/tessera_proposal/).

---

## 1. Executive Summary & Shipped Configuration

Tessera v2 replaces the v1 pixel-space quadtree prototype (fixed PCA/polynomial codes + FLUX 16 px fallback + 150-call merge search) with a **pure-latent 2:1 k-d tree codec** operating on frozen FLUX.2 VAE latents (`64×64×32` at 512×512 px).

### Frozen production checkpoint & operating point

| Component | Exact Specification | Evidence / Provenance |
|---|---|---|
| **Codec checkpoint** | `phase3_large_tl/step_20000.pt` (md5 `fef118176592bdb1bd63a45f404a2b09`, sha256 `6b092cfc9806…`) | HF `tensorkelechi/tessera-checkpoints/phase3_large_tl/step_20000.pt` |
| **Decoder (`TileUp`)** | 22.18M params, widths `(160, 256, 384)`, 4 attention blocks, `zero_mean_resid=True`, `ac_floor=0.26`, `ac_tau=0.2` | `out/phase3_large_tl/train.log` |
| **Encoder (`RectTileDown`)** | 4.55M params, `td_c=160`, `td_hid=512`, `td_1d_pool=True`, `td_prof_c=16`, `td_prof_len=32`, `td_dc_lock=True` | `out/phase3_large_tl/train.log` |
| **Basis + Lift (`RectTileLift`)** | 0.78M params (`tl_hid=256`, `tl_rank=8`, `tl_prof_len=32`) over orthonormal `dc_pca96` / `plane_pca32` basis (`rect_basis_full.pt`, fit on 2,700 images) | `out/tessera_full_stats.json` |
| **TileUp spike guard** | `--tu_spike_k 3`, min area ≥ 64 latent cells (`8×8` and larger); **DC correction OFF** | `out/dc_correct/REPORT.md`, `out/judge_recal/REPORT.md` |
| **Lead encoder** | `LatentRouterRect` (1.05M params, width 96, dilations `1,2,4,8,2,1`, 44-ch input) + Judge verify loop (8 rounds, all-2×2 fallback) | `out/router_pilot/run1/REPORT.md` |
| **Challenger encoder** | `RD-tree` exact bottom-up DP (β=3, τ=2.0, λ=0.002) + Judge verify loop (zero training) | `out/rd_tree/REPORT.md`, `out/final_eval/pod/cur_D/` |
| **Frozen Judge bar (`S15F+`)** | `--judge_scale 1.0 --struct_scale 1.5 --color_floor_de 1.0 --color_max_floor_de 1.8 --tu_spike_k 3`, `mae32_limit = 3.75` | `out/judge_recal/REPORT.md`, `out/mae32_relax/REPORT.md` |

---

## 2. Dataset, Splits, Denominators, and Token vs. Bitstream Accounting

### 2.1 Dataset & split boundaries (`tensorkelechi/tessera-latents512-full`)

Built from `tensorkelechi/tessera-imageset` (WebP-lossless, filtered for RGB, short side ≥ 512 px, JPEG Q ≥ 85 [WikiArt ≥ 70 + blockiness check], 64-bit DCT pHash dedupe Hamming ≤ 4, and SHA-256/pHash exclusion of all evaluation images).

| Domain | Train (`n_train`) | Holdout Full (`n_holdout_full`) | Holdout Balanced (`heldout.pt`) | `heldout_90` (`h90`) | Router Labels (306) | Calib (`calib.pt`) |
|---|---:|---:|---:|---:|---:|---:|
| `chart` | 17,337 | 342 | 125 | 10 | 34 | 5 |
| `document` | 19,296 | 419 | 125 | 10 | 34 | 5 |
| `painting` | 46,957 | 1,025 | 125 | 10 | 34 | 5 |
| `photo` | 58,061 | 1,095 | 125 | 10 | 34 | 5 |
| `pixelart` | 9,559 | 205 | 125 | 10 | 34 | 5 |
| `screenshot` | 15,535 | 298 | 125 | 10 | 34 | 5 |
| `synth_flat` | 6,000 | 200 | 125 | 10 | 34 | 5 |
| `synthetic` | 7,217 | 141 | 125 | 10 | 34 | 5 |
| `texture` | 7,052 | 142 | 125 | 10 | 34 | 5 |
| **Total** | **187,014** | **3,867** | **1,125** | **90** | **306** | **45** |

- **Disjointness guarantees:**
  - `calib.pt` (45 images) is sampled from `train_*_00000.pt` at `--offset_per_domain 500`, strictly disjoint from both the 306 router labels (positions 0–33 per domain) and `heldout.pt`.
  - `heldout_90` (90 images, 10/domain) is drawn strictly from `heldout.pt`, never trained on or labelled.
  - `cur` (24 images in `out/final_eval/curated_imgs/`) is a **curated development & bounty benchmark** (4 flat/sky images [`fs_plain-blue`, `fs_sky`, `mr_simple_plain_blue`, `wms_sky_0`], 11 Mondrians [4 clean synthetic, 5 photographed paintings, 2 synthetic-photographed], 5 distinct Waldos after pHash deduplication of `fs_waldo2`/`j5_waldo3`, a text slide and a rock texture [`j5_text_slide_sans`, `j5_rock_00_Cross_rock_texture_2012_G1`], and a held-out screenshot and a flat blue [`c03d56fb9e5fe67f`, `flat_blue_50_150_220`]). We never conflate `cur` or `calib.pt` with `heldout_90`.

### 2.2 Label counts vs. tile token counts vs. bitstream

1. **Label count (306):** Number of training images whose ground-truth `shape_map` `[2, 64, 64]` was generated by Judge search (`qtok/label_rect.py`) to supervise `LatentRouterRect` (split 279 train / 27 val).
2. **Tile / leaf token count (N):** Number of leaves in the 2:1 k-d tree partition of the `64×64` latent grid. Every leaf emits exactly **one 128-float vector** (`TOK = 32 × 4 = 128`), matching one `2×2` FLUX.2 grid token. All compression ratios and Waldo/Mondrian spreads use N against the 1,024-token grid denominator.
3. **Serialized bitstream overhead:** Starting from the four `32×32` roots, a binary k-d tree with N leaves has N-4 internal split nodes and 2N-4 total nodes. Each non-`2×2` node encodes a 3-way choice `{leaf, split-H, split-V}` (≤ 2 bits/node, or log2 3 ≈ 1.585 bits entropy-coded). Even at worst-case N=1,024, the tree topology takes ≤ 4,096 bits = **512 bytes** (≤ 1 fp32 token equivalent, or 2 fp16 tokens), compared to N × 256 bytes of fp16 token payload (262 KB at N=1,024; 15.6 KB at N=61). Container metadata adds a fixed header of a few dozen bytes.

---

## 3. Architecture & Training Progression

### 3.1 4k-step architecture ablation (`out/ablation_4k/`, RunPod A5000, ~$0.76)

Three variants were trained for 4,000 steps (`pixel_every=1`, `crop=32`, `bs=32`, ~41 min each) to test whether TileUp width and `RectTileLift` mattered:

| Variant | Final `val_lat` | `val_judge` | `heldout_90` mean tokens (`J3.0`) | Pass % | Takeaway |
|---|---:|---:|---:|---:|---|
| `ablate_med_lin` | 0.2206 | 18.52 | 416 | 100% | Baseline medium TileUp, linear lift only |
| `ablate_med_tl` | 0.2205 | 18.63 | 410 | 100% | TileLift marginal at 4k (−6 tok) |
| `ablate_large_tl` | **0.2186** | **18.22** | **401** | **100%** | Best across all three metrics; selected for 20k run |

### 3.2 Full 20k-step training (`phase3_large_tl`, RunPod A5000, ~7.9 h)

- **Config:** `TileUp` 22.18M + `RectTileDown` 4.55M + `RectTileLift` 0.78M + `PatchD` 0.66M; `bs=32`, `pixel_bs=4`, `pixel_crop=32`, `lr=3e-4`, real JPEGs, decoupled pixel gradients (`r_loc/r_col/r_gan ≈ 0.45/0.09/0.04`), `~1.31 s/step`, ~8.6 GB VRAM.
- **Gate 4 eval (`J3.0`, `out/phase3_large_tl/gate4.log`):**
  - `heldout90_raw`: 350.9 mean tokens, 100% pass, 33.05 dB vs grid (1.5 s/img).
  - `heldout90_p32`: **330.6 mean / 193.5 median tokens**, 100% pass, 32.39 dB vs grid (2.7 s/img).
  - `wms` (4 images): 274.8 tok (p48); `finalset` (8): 693.1 (p48) / 688.0 (p192); `rocks` (8): 862.9 (p48).
- **10k → 20k headline progression (`J3.0`, `out/headline_20k/summary.md`):**
  - Canonical `waldo2` / `mondrian_2`: 19.3× (10k p48) → **39.4×** (20k p48, 1024/26); 24.2× (10k fullprune) → **39.9×** (20k fullprune, 998/25).
  - Clean synthetic Mondrians vs 5 distinct Waldos (20 pairs): 14/20 ≥ 16× (10k fullprune, median 19.1×) → **18/20 ≥ 16×** (20k fullprune, median **27.9×**, max **48.0×**).
  - Photographed paintings (25 pairs): 0/25 ≥ 16× (median 3.0×, max 6.1×); synthetic-photographed (10 pairs): 0/10 (median 2.1×).
  - **No regression on `plain-blue`:** 424 → 426 raw, 306 → 308 uncapped between 10k and 20k on identical hardware.

---

## 4. Trials, Diagnostics, and Failures (Complete Log)

This section documents every diagnostic investigation and negative result that shaped the final codec.

### Trial 1: `--split_rank` (ranked top-down splitting) — **DROPPED**
- **Hypothesis (`out/split_rank_cpu/REPORT.md`):** Splitting only the top 25% highest lift-error `bad8` leaves per round instead of all `bad8` leaves would stop over-splitting on Mondrian paintings.
- **Result:** Cost **1.5–4× more Judge calls** for **±15% token swings of mixed sign** (e.g. `Mondrian_B144` worsened 799 → 860 raw; `Piet` 263 → 224 raw).
- **Root cause discovered:** Lift error is noisy on canvas photos (canvas grain scores as high as black bars). The actual bottleneck was two-fold: (a) the 48-call prune cap was cutting off convergence (`Piet` dropped 263 → **172** when uncapped at 192 calls), and (b) `color_mean256` falls through to a global top-10% attribution rule (`judge5_fast.py:294-296`), flagging ~410 cells image-wide whenever systematic VAE colour drift accumulated.

### Trial 2: `--prune_fast` silent early-exit bug — **DIAGNOSED**
- **Symptom (`out/headline_20k/summary.md`):** Gate 4's `finalset_p192` left `Piet` at 251 tokens after only 22 total calls (never reaching the 192-call cap).
- **Root cause:** `--prune_fast` defers "dirty" chunks instead of bisecting them. Because `color_mean256` marks 10% of the image dirty globally, almost every chunk was marked dirty and the pruner exited after 14 calls. Disabling `--prune_fast` (full bisection) dropped `Piet` from **251 → 166** tokens within the same 192-call cap.

### Trial 3: Encoder-side per-tile DC colour correction (`dc_correct`) — **PROVEN, HELD OFF**
- **Method (`out/dc_correct/REPORT.md`, `qtok/dc_correct.py`):** Zero-backprop per-leaf DC slot shift using a 4-probe block-coherent Jacobian A ∈ ℝ^{3× 32} (independent per-tile probes diverged; block-coherent probes converged `|e| 1.37 → 0.50` u8 in 2–3 decodes).
- **Token win:** Fixed colour drift completely at zero token cost: unit checks cut flat RGB error 3–10× (4/4 failing merges passed); uncapped prune dropped `Piet` **172 → 127** and `B144` **691 → 138** tokens.
- **Why held off (no-go):** Unlocking 8×16 and 16×16 tiles exposed a **visible dark dot with a pale/cyan halo in the upper-left quarter of large tiles** (dot metric 44 → 114 on `Piet`, ~20 dots on `B144`), plus canvas-weave substitution and bar-foot smear on `B144`. Decoding the same layout *without* DC deltas produced the exact same dot (112 vs 113), proving the defect lived in `TileUp`, not `dc_correct`. Furthermore, DC deltas break router target self-consistency because a layout is no longer reproducible from its `shape_map` alone.

### Trial 4: Eval-time pixel-scale AC gate — **FAILED**
- **Hypothesis (`out/dc_correct/gate_test/REPORT.md`):** In `plane_pca32`, token-side `ac_gate` computes RMS over 32 PCA coefficients (2.35–3.08 on flat sky vs 0.21–0.24 per-pixel), pinning the gate at 1.0 on flat tiles where the dot appears. Replacing it at eval time with a per-pixel-scale gate should turn off the residual on flat tiles.
- **Result:** Removed the dots (113 → 43–46) but **blurred and washed out bars**; Judge score exploded from **5–6 to 15–17** (even with `pixel_close` edge protection: 14.4–15.8). The trained TileUp residual is load-bearing on both flat and dark tiles.

### Trial 5: Large-tile residual gain vs. per-tile spike clamp (`--tu_spike_k 3`) — **CLAMP ADOPTED**
- **Discovery (`out/dc_correct/large_gain/`):** The dot is a **deterministic positional spike** at in-tile latent cell `(2..3, 2)` carrying **~43×** the tile's median high-pass energy across every shape ≥ 8× 8, on every image, even at zero noise seed (landing at `(2,2)` in 73–100% of tiles).
- **Per-shape gain:** Failed (calibration picked g=0 on 8×16/16×16, leaving 9 dot leaves on 8×8 tiles in `B144`).
- **Spike clamp (`--tu_spike_k 3`, area ≥ 64):** Eliminated dots and halos completely (Piet 0 dot leaves, edge MAE −1.8% at fixed layout; `judge_recal` 11-image pilot reduced dot leaves 7 → 0 under `S15F+`). Adopted as part of `S15F+`.

### Trial 6: Anti-spike TileUp fine-tune (`ft_antispike`) — **NO-GO AT STEP 500**
- **Root cause (`out/ft_antispike/PLAN.md`):** `decomposed_latent_and_hp_var_loss` penalizes `0.35·|H_hat - H_gt|` plus `0.5·smooth_l1(RMS_tile(H_hat), RMS_tile(H_gt))`. Mathematically, a single 2×2 zero-sum spike matches tile RMS exactly while its L1 penalty shrinks as 1/√N (toy 16×16 loss: **0.275** for one spike vs **0.357** for spread grain vs **0.659** for zero grain). Real `step_20000` confirmed this: `L4/RMS = 2.68` vs true `1.39` (`tile_rms = 0.032`).
- **Fix tested:** Warm-start FT from `step_20000` with `--freeze_tiledown`, `--hp_energy_mode block_l1`, `--peak_w 0.5`, `--pix_spike_w 1000`, `--dc_jitter 0.1`.
- **Step-500 probe result (`out/ft_antispike/probe_step500.json`):** Successfully killed the spike (`L4/RMS` 2.68 → **1.314**, `block_l1` 0.222 → **0.091**, `term_max_near_dot` 0.505 → **0.0**), **but failed the grain-collapse gate**: `hp_rms_ratio = 0.7203 < 0.80` (TileUp suppressed genuine high-pass energy instead of spreading it). Stopped at step 500 (~$0.25) and stayed on `step_20000` + `--tu_spike_k 3`.

### Trial 7: Judge recalibration & blind eye check (`out/judge_recal/REPORT.md`) — **ADOPTED (`S15F+`)**
- **Finding:** Adding Lab colour floors (`color_mean256 = 1.0 ΔE`, `color_max256 = 1.8 ΔE`) collapsed flat/sky over-splitting immediately while keeping text protection intact:
  - `plain-blue`: 565 (`J1.0`) / 361 (`J3.0`) → **22** (`S15F+`, 0 dots).
  - `sky`: 792 (`J1.0`) / 511 (`J3.0`) → **65** (`S15F+`, 0 dots; 11 unclamped had 5 dot leaves).
  - `text_slide`: 268 (`J3.0`, rejected by eye) / 476 (`J1.0`) → **357** (`S15F+`, accepted by eye).
  - `held-out screenshot`: 323 (`J3.0`) / 474 (`J1.0`) → **426** (`S15F+`).
  - Floor sensitivity on `color_mean256` ∈ {0.5, 1.0, 1.2, 2.0} ΔE: identical decodes across 1.0–2.0 ΔE (19 tok on plain-blue, 461 on text slide); 0.5 ΔE jumped plain-blue to 88 tok.

### Trial 8: Mondrian gap diagnosis & `mae32` relaxation (`out/mondrian_gap/`, `out/mae32_relax/`) — **RELAXATION REJECTED**
- **Diagnosis:** Why did `wms_mondrian_2` take 101 tokens under `S15F+` vs 25 under `J3.0`? Scoring the 25-token layout under `S15F+` showed two failing gates: `mae32 = 7.14` vs limit `3.75` (1.90×) and `color_max16 = 6.29` vs `3.35` (1.88×), both concentrated on black lines (1 px contrast overshoot / edge fringe). Relaxing `mae32` from `3.75 → 5.0` cut `wms_mondrian_2` from **102 → 63 tokens** (16.2× vs Waldo).
- **Why rejected:** On 5 native-resolution 3× text crops (`j5_text_slide_sans` and held-out screenshot `c03d56fb9e5fe67f`), `mae32 = 5.0` degraded PSNR by **−2 to −4 dB** vs `3.75`, increased MAE vs grid **1.5–5×**, and visibly ghosted/broke 11 px body text ("construction", "you're", "love to hear"). We kept `mae32 = 3.75` globally and rejected content-conditional thresholds to avoid benchmark gaming.

### Trial 9: Edge-priority split search — **MIXED, DROPPED**
- **Result (development log, 2026-11-22):** At a 32-decode cap under `SF+`: `slide` 461 → 357, `Piet` 510 → 537 (worse), `sky` 66 → 66. Dropped.

### Trial 10: RD-tree λ-only cliff & noise-floor τ fix (`out/rd_tree/REPORT.md`) — **CHALLENGER ADOPTED**
- **Failure of spec'd objective (D = mean + β·max + λ):** Because lift error never vanishes on flat tiles (0.28–0.33 at 32×32) while `2×2` has e=0 by construction, sweeping λ produced a cliff: every image stayed at ~1,024 tokens until λ ≈ 3× 10⁻³, then collapsed to 4 tokens (flat images stuck at 695–1,024 tok).
- **Fix:** Adding a dead-zone noise floor D = ReLU(mean + β·max - τ) with β=3, τ=2.0, λ=0.002 resolved the cliff (48% exact cell match to `S15F+` search, mean |log2 tok ratio| = 0.48). One-shot pass was 0% at τ=2.0 and 75.6% at τ=1.0 (at 1.51× tokens), so RD-tree requires verify, where it achieves 24/24 pass and 0 fallbacks on `cur` (413.6 mean tok).

### Trial 11: Stage-2 Router pilot & infrastructure incidents (`out/router_pilot/run1/REPORT.md`)
- **Result:** 306 labels (34/domain, 100% pass, 357 mean tok, 39.8 calls/img, ~$0.50/1k images on A4000 at $0.17/h). Router trained 80 epochs in 472 s (best val ep 50, node acc 0.873; mild overfit after ep 50).
- **Router-alone failure:** 4.4% one-shot pass (`bias=0`), 0% (`bias=0.5, 1.0`) on `calib.pt` (n=45).
- **Router + Verify win:** **45/45 pass, 0 fallbacks**, 1.04–1.07× search tokens, **2.8–3.3 Judge calls/img** (vs 40), **~11× speedup** (636–731 ms vs 7,931 ms). Verify overhead is concentrated in small-token domains (`synth_flat` +50%, `synthetic` +31%, `chart` +22%) vs +2–4% on `photo`/`painting`/`texture`.
- **Operational incidents logged:**
  1. `runpod.sh up` ran `pip install ... transformers>=5.2`, silently upgrading `torch 2.9.1+cu128 → 2.15+cu132` and breaking CUDA/cuDNN (cost ~10 min on CPU before reinstalling cu12 wheels). Needs a torch pin + post-pip CUDA assert.
  2. Idle guard (`IDLE_MIN=10`, terminate) killed the pod mid-copy, losing `cal_rd_A`, `cal_rd_A_prune`, and `cal_rd_B` JSONs (subsequently superseded by the dedicated `final_eval` run).

---

## 5. Complete Final Evaluation Tables (`S15F+`)

### 5.1 Curated 24-image set (`cur`, n=24)

| arm | n | pass | fallback | tok mean | tok med | calls/img | s/img | PSNR/SSIM/LPIPS/DISTS vs grid | vs orig |
|---|---|---|---|---|---|---|---|---|---|
| S | 24 | 100.0% | 0/24 | 348.7 | 233 | 171.0 | 72.5 | 37.81/0.9560/0.0194/0.0432 | 32.38/0.9333/0.0293/0.0623 |
| R | 24 | 100.0% | 0/24 | 384.2 | 304 | 2.7 | 1.3 | 42.43/0.9622/0.0150/0.0353 | 33.20/0.9384/0.0253/0.0554 |
| RP | 24 | 100.0% | 0/24 | 347.1 | 236 | 168.7 | 69.4 | 37.91/0.9554/0.0195/0.0437 | 32.46/0.9328/0.0295/0.0630 |
| D | 24 | 100.0% | 0/24 | 413.6 | 390 | 2.8 | 1.3 | 45.65/0.9683/0.0135/0.0320 | 33.26/0.9427/0.0235/0.0525 |
| DP | 24 | 100.0% | 0/24 | 356.4 | 275 | 172.3 | 53.6 | 37.89/0.9578/0.0182/0.0420 | 32.41/0.9346/0.0281/0.0613 |

Per-image tokens (Judge calls in parentheses; every image passes in every arm):

| image | S | R | RP | D | DP |
|---|---|---|---|---|---|
| c03d56fb9e5fe67f | 428 (266) | 440 (2) | 427 (258) | 499 (3) | 432 (259) |
| flat_blue_50_150_220 | 4 (2) | 16 (1) | 4 (4) | 4 (1) | 4 (2) |
| fs_Mondrian_Composition_B144 | 374 (265) | 467 (3) | 339 (259) | 456 (2) | 355 (258) |
| fs_Piet_Composition | 222 (214) | 268 (4) | 199 (193) | 331 (3) | 205 (182) |
| fs_plain-blue | 22 (27) | 35 (2) | 23 (32) | 34 (2) | 24 (28) |
| fs_sky | 50 (64) | 80 (6) | 68 (64) | 102 (4) | 79 (85) |
| fs_waldo3 | 996 (265) | 997 (2) | 995 (258) | 1002 (2) | 994 (258) |
| j5_00_Composition__1921_-_Piet_Mondrian__ | 230 (221) | 410 (3) | 224 (219) | 407 (2) | 276 (258) |
| j5_01_Piet_Mondriaan__1930_-_Mondrian_C | 236 (226) | 281 (3) | 248 (239) | 315 (2) | 235 (216) |
| j5_02__Composition__by_Piet_Mondrian__1 | 283 (264) | 355 (2) | 278 (258) | 407 (3) | 286 (249) |
| j5_39_waldo_altdorfer_crucifixion | 704 (265) | 750 (2) | 699 (258) | 842 (2) | 748 (258) |
| j5_40_waldo_costumes_station_crowd | 637 (265) | 716 (2) | 616 (258) | 730 (3) | 636 (259) |
| j5_41_waldo_book_page_user | 1023 (265) | 1024 (2) | 1023 (258) | 1024 (2) | 1023 (258) |
| j5_mondrian_5 | 69 (58) | 84 (4) | 69 (55) | 99 (5) | 75 (67) |
| j5_mondrian_7 | 102 (85) | 116 (4) | 100 (75) | 142 (5) | 104 (83) |
| j5_photo_mondrian_4 | 181 (175) | 237 (2) | 206 (182) | 498 (2) | 278 (258) |
| j5_photo_mondrian_5 | 269 (247) | 327 (3) | 280 (259) | 373 (3) | 274 (253) |
| j5_rock_00_Cross_rock_texture_2012_G1 | 988 (265) | 1013 (2) | 987 (258) | 1006 (2) | 989 (258) |
| j5_text_slide_sans | 357 (265) | 368 (2) | 346 (258) | 413 (4) | 343 (260) |
| mr_simple_plain_blue | 20 (26) | 29 (2) | 21 (27) | 32 (1) | 22 (19) |
| waldo2 | 1021 (265) | 1021 (2) | 1021 (258) | 1024 (2) | 1021 (258) |
| wms_mondrian_2 | 102 (75) | 113 (4) | 98 (71) | 115 (5) | 96 (71) |
| wms_mondrian_6 | 47 (33) | 61 (4) | 56 (42) | 67 (5) | 51 (37) |
| wms_sky_0 | 4 (2) | 13 (1) | 4 (5) | 4 (1) | 4 (2) |

### 5.2 Held-out 90-image set (`heldout_90`, n = 90, 10/domain)

Snapshot of `out/final_eval/pod/h90_*` taken 2026-11-23. Every row is a complete 90-image run. Arms with no completed run are marked pending.

| arm | n | pass | fallback | tok mean | tok med | calls/img | s/img | PSNR/SSIM/LPIPS/DISTS vs grid | vs orig |
|---|---|---|---|---|---|---|---|---|---|
| S | pending | | | | | | | | |
| R | 90 | 100.0% | 0/90 | 369.6 | 248 | 2.9 | 1.5 | 35.22/0.9640/0.0209/0.0276 | 32.14/0.9389/0.0296/0.0445 |
| RP | 90 | 100.0% | 0/90 | 329.0 | 213 | 163.9 | 57.1 | 33.46/0.9516/0.0290/0.0367 | 31.21/0.9288/0.0371/0.0509 |
| D | 90 | 100.0% | 1/90 | 406.9 | 258 | 3.3 | 1.6 | 37.05/0.9719/0.0165/0.0226 | 32.51/0.9453/0.0256/0.0408 |
| DP | pending | | | | | | | | |

*FLUX.2 Grid (1,024 tokens) vs Original on `heldout_90`: 35.50 dB PSNR / 0.9657 SSIM / 0.0109 LPIPS / 0.0263 DISTS.*

Mean tokens (pass rate) per domain:

| domain | S | R | RP | D | DP |
|---|---|---|---|---|---|
| chart | pending | 158 (100%) | 121 (100%) | 167 (100%) | pending |
| document | pending | 484 (100%) | 431 (100%) | 510 (100%) | pending |
| painting | pending | 689 (100%) | 619 (100%) | 767 (100%) | pending |
| photo | pending | 635 (100%) | 575 (100%) | 687 (100%) | pending |
| pixelart | pending | 278 (100%) | 244 (100%) | 364 (100%) | pending |
| screenshot | pending | 180 (100%) | 166 (100%) | 198 (100%) | pending |
| synth_flat | pending | 85 (100%) | 62 (100%) | 90 (100%) | pending |
| synthetic | pending | 80 (100%) | 62 (100%) | 89 (100%) | pending |
| texture | pending | 737 (100%) | 680 (100%) | 790 (100%) | pending |

- The single grid fallback is the verified RD-tree on `a7168ccd0e1bcb05` (`pixelart`): 8 verify rounds did not pass, so it shipped as the 1,024-token grid. No router arm fell back.
- **Historical reference (`J3.0`, `phase3_large_tl/step_20000.pt`, top-down + 32-call prune):** 90/90 pass, 330.6 mean / 193.5 median tokens (`chart` 107.5, `document` 373.8, `painting` 637.3, `photo` 644.0, `pixelart` 271.1, `screenshot` 151.4, `synth_flat` 62.5, `synthetic` 21.4, `texture` 706.4). This used the looser `J3.0` bar and is not comparable to the `S15F+` rows.

---|---|---|---|---|---|---|---|---|---|
| S | not run | | | | | | | | |
| R | 90 | 100.0% | 0/90 | 369.6 | 248 | 2.9 | 1.5 | 35.22/0.9640/0.0209/0.0276 | 32.14/0.9389/0.0296/0.0445 |
| RP | not run | | | | | | | | |
| D | 90 | 100.0% | 1/90 | 406.9 | 258 | 3.3 | 1.6 | 37.05/0.9719/0.0165/0.0226 | 32.51/0.9453/0.0256/0.0408 |
| DP | not run | | | | | | | | |

- **Historical reference (`J3.0`, `phase3_large_tl/step_20000.pt`, top-down + 32-call prune):** 90/90 pass, 330.6 mean / 193.5 median tokens (`chart` 107.5, `document` 373.8, `painting` 637.3, `photo` 644.0, `pixelart` 271.1, `screenshot` 151.4, `synth_flat` 62.5, `synthetic` 21.4, `texture` 706.4).

---

## 6. Future Architecture: Direct Pixel Head

Almost every stubborn failure in Trials 3–8 traces back to forcing variable-size coarse tiles through a **frozen 8×-downsampled VAE decoder** (`AutoencoderKLFlux2`):

| Pure-latent bottleneck (v2) | Root mechanism | How a direct Pixel Head resolves it |
|---|---|---|
| **Flat-tile colour drift** (1–4 RGB, shattering skies without colour floors) | Dec(E[z]) ≠ E[Dec(z)] through non-linear VAE GroupNorm/SiLU layers | Direct RGB prediction with explicit per-tile mean-colour supervision in pixel space; zero VAE nonlinearity between token DC and decoded RGB |
| **Positional dark dot / spike exploit** (43× HP energy at cell `(2,2)`) | Latent-space HP RMS loss can be cheated by a single 2×2 latent spike that decodes to a localized RGB dot | Direct pixel-space perceptual + adversarial (PatchGAN) + local block-energy loss; seeded noise injection for matched film grain |
| **1 px bar overshoot & text softness** (forcing `wms_mondrian_2` to ~100–113 tok under `mae32=3.75`) | 8× latent spatial quantization + frozen VAE decoder blurs or overshoots sub-cell sharp edges | Pixel-space upsampling head with direct 1 px edge/stroke gradients and neighbour context across tile seams |
| **Verify-loop latency** (~1.3 s/img for 2.7–3.3 calls) | Each Judge check requires running the full FLUX.2 VAE decoder | Lightweight pixel head decodes in milliseconds; optionally supports localized partial-canvas re-decode during verification |

### Proposed hybrid pixel-head design (v3 roadmap)

1. **Keep the 2:1 k-d tree, 128-float token interface, and `LatentRouterRect`:** Downstream generative models (`BreadthGenRect`, packed FlexAttention + 2D center RoPE) see the exact same variable-length sequence of 128-float tokens.
2. **Decode directly to RGB:** Replace `TileUp → Frozen FLUX.2 VAE Decoder` with a multiscale ConvNeXt/attention **Pixel Head** that takes the lifted tile canvas (plus shape-embedding & seeded grain channels) and outputs RGB directly, while optionally retaining a lightweight residual skip from the FLUX.2 decoder on `2×2` passthrough leaves or training the pixel head end-to-end to match/beat FLUX.2 on 16 px tiles as well.
3. **Train against `S15F+`-aligned pixel objectives:** Direct Lab colour-mean loss on coarse tiles, multi-scale LPIPS + DISTS + PatchD, and per-window `mae32` hinge loss so training and Judge verification optimize the exact same perceptual surface.
4. **Higher resolution:** sections 1–7 are measured at 512 px; the blockwise 512 to 4096 px ladder is in section 8. Whole-image (cross-block) coding and verification remain untested.

---

## 7. Blind comparison on the four curated Mondrians

One reviewer rated the verified router and the FLUX.2 grid equally close to the displayed source on all four curated Mondrians. The adaptive layouts used 61–116 tokens and the grid used 1,024. Each sheet independently shuffled the reconstruction labels.

| Sheet | Image | Tessera column | Tessera tokens | Verdict |
|---|---|---|---:|---|
| 1 | wms_mondrian_2 | A | 113 | Tie |
| 2 | j5_mondrian_5 | B | 84 | Tie |
| 3 | wms_mondrian_6 | A | 61 | Tie |
| 4 | j5_mondrian_7 | B | 116 | Tie |

## 8. Higher resolution: 512 to 4096 px

Everything above is at 512 px. The following measures the same public `tessera` CLI (router mode, strict `S15F+` Judge, verify on) on the same kinds of picture at 512, 1024, 2048 and 4096 px. The CLI itself is 512 px only, so every larger image is cut into independent 512×512 blocks; each block is encoded and Judge-verified on its own (369 of 369 blocks in the five classes below pass, 0 grid fallbacks). The baseline is the blockwise FLUX.2 grid: 1,024 tokens per block.

<style>.chart-dark{display:none}html[data-theme="dark"] .chart-light{display:none}html[data-theme="dark"] .chart-dark{display:block}</style>

<div class="chart-light">
<picture>
<source media="(max-width: 640px)" srcset="images/tessera_results/tessera_ladder_ratio_mobile.svg">
<img src="images/tessera_results/tessera_ladder_ratio.svg" alt="Compression ratio against the FLUX grid for five image classes, 512 to 4096 pixels, log scales" loading="lazy">
</picture>
</div>

<div class="chart-dark">
<picture>
<source media="(max-width: 640px)" srcset="images/tessera_results/tessera_ladder_ratio_mobile_dark.svg">
<img src="images/tessera_results/tessera_ladder_ratio_dark.svg" alt="Compression ratio against the FLUX grid for five image classes, 512 to 4096 pixels, log scales" loading="lazy">
</picture>
</div>

*Compression ratio against the blockwise FLUX.2 grid, one line per image class. RTX 4090 and RTX 4000 Ada runs of the public CLI in router mode at S15F+, every 512 px block verified. Waldo and the painting end at 4096×2048 and 4096×2560.*

| image class | 512² | 1024² | 2048² | 4096² |
|---|---|---|---|---|
| FLUX grid tokens | 1,024 | 4,096 | 16,384 | 65,536 |
| Smooth sky (synthetic) | 69 (14.8×) | 102 (40.2×) | 270 (60.7×) | 825 (79.4×) |
| Clean Mondrian (synthetic) | 120 (8.5×) | 295 (13.9×) | 837 (19.6×) | 2,253 (29.1×) |
| Text slide | 368 (2.8×) | 980 (4.2×) | 2,057 (8.0×) | 4,283 (15.3×) |
| Dense painting (Veronese) | 629 (1.6×) | 2,431 (1.7×) | 10,309 (1.6×) | 26,537 (1.5×) |
| Where's Waldo (4K page) | 1,023 (1.0×) | 4,065 (1.0×) | 15,783 (1.0×) | 30,904 (1.1×) |

*Tokens (× fewer than the blockwise FLUX.2 grid). Flat blue, not drawn, is 64× at every size (16 tokens per block). The painting's 4096 rung is 4096×2560 (grid 40,960) and Waldo's is 4096×2048 (grid 32,768) because both source pages are wider than tall; sky and Mondrian are 4096×4096. Mondrian, sky and the slide are rendered natively at each size (features scale with the image); the painting is native 1:1 crops of a 4,214 px file; Waldo 512–2048 are Lanczos downscales of the central 2,304 px square of a 4K page and its 4096 rung is the native 4096×2048 band.*


**What it shows.** Smooth and sparse content gets cheaper per pixel as the image grows: sky goes from 14.8× to 79.4×, the clean Mondrian from 8.5× to 29.1×, the results slide from 2.8× to 15.3×. Flat blue stays at 64×. Dense real images do not: the painting stays at 1.5–1.7× and the Waldo page at 1.0–1.1×.

### Mondrian vs Waldo at matched sizes

At the same pixel size the same encoder gives a clean synthetic Mondrian and the Waldo page very different budgets:

| size | Mondrian tokens | Waldo tokens | Waldo ÷ Mondrian |
|---|---|---|---|
| 512² | 120 | 1,023 | 8.5× |
| 1024² | 295 | 4,065 | 13.8× |
| 2048² | 837 | 15,783 | 18.9× |
| 4096×2048 | 1,317 | 30,904 | 23.5× |

<style>.chart-dark{display:none}html[data-theme="dark"] .chart-light{display:none}html[data-theme="dark"] .chart-dark{display:block}</style>

<div class="chart-light">
<picture>
<source media="(max-width: 640px)" srcset="images/tessera_results/tessera_ladder_bounty_mobile.svg">
<img src="images/tessera_results/tessera_ladder_bounty.svg" alt="Tokens for a synthetic Mondrian and a Where's Waldo page at 512, 1024, 2048 and 4096 by 2048 pixels, with the ratio between them" loading="lazy">
</picture>
</div>

<div class="chart-dark">
<picture>
<source media="(max-width: 640px)" srcset="images/tessera_results/tessera_ladder_bounty_mobile_dark.svg">
<img src="images/tessera_results/tessera_ladder_bounty_dark.svg" alt="Tokens for a synthetic Mondrian and a Where's Waldo page at 512, 1024, 2048 and 4096 by 2048 pixels, with the ratio between them" loading="lazy">
</picture>
</div>

*Same pixel size, same encoder and bar. The Mondrian is a ladder scene, not the curated 61-token one, and Waldo 512–2048 are downscales of a 4K page, so this is a scaling comparison, not the 512 px bounty number.*

### Latency per 512 block

Per 512×512 block, warm median of 3 on an RTX 4090: VAE encode about 14 ms, tokenise and error maps about 18 ms, router 13–24 ms, verify loop 0.06–0.28 s (1–4 Judge calls, depends on the picture), tile decode (TileUp + FLUX decoder) 45–56 ms against 39.5 ms for the plain FLUX grid decode.


### Seam error (border step vs interior step, mean absolute level difference)

| case, size | Tessera border / interior | blockwise FLUX border / interior | native FLUX border / interior |
|---|---|---|---|
| sky 4096² | 2.8 / 0.08 | 2.52 / 0.09 | not run |
| Mondrian 4096² | 2.89 / 0.06 | 2.52 / 0.03 | 0.12 / 0.06 (tiled) |
| Mondrian 4096×2048 | 2.29 / 0.08 | 1.78 / 0.05 | 0.09 / 0.06 (tiled) |
| slide 4096² | 1.87 / 0.17 | 1.36 / 0.1 | not run |
| painting 4096×2560 | 6.35 / 4.1 | 4.36 / 3.07 | not run |
| Waldo 4096×2048 | 8.61 / 3.96 | 7.74 / 3.71 | 3.67 / 3.63 (tiled) |

Border is the 1 px step across x or y = 512k, interior the same measure 256 px inside a block; a stitched codec without seams has border ≈ interior. Full tables: `out/resolution_ladder/tables.md` and `ladder_summary.csv`.

**Caveats.**
- Blocks are encoded and verified independently, with no cross-block context and no whole-image check. Block borders can therefore show a step. The blockwise FLUX grid has the same seams; measured as the border-to-interior step error, Tessera adds about 0.2–1.2 levels over the blockwise grid on sky, Mondrian, slide and Waldo, and about 2 on the dense painting. A native full-image FLUX round trip has no seams (border ≈ interior; the 4096 native baseline used overlap-blended tiled encode and decode because a single pass does not fit in memory).
- Dense real images stay near 1–1.7×: the painting is 1.5–1.7× at every size and the Waldo page 1.0–1.1×.
- The public CLI is 512 px only; this ladder tiles it. A native 4096² encoder does not exist in this codebase.
- All blocks pass the Judge (0 grid fallbacks), but the Judge reference is the blockwise FLUX round trip of the same block, not the original. Pixel quality against the original is 1–8 dB (PSNR) below the blockwise grid on the synthetic scenes.
- The 512 px headline (61 tokens for a clean Mondrian against 1,021 for a Waldo page) is unchanged. The ladder is a separate scaling result on different pictures, not a replacement: its Mondrian is a four-colour-field ladder scene (120 tokens at 512 px), not the curated one.
- Hardware: tokens and verification come from RTX 4090 (all classes but Mondrian and Waldo-4K) and RTX 4000 Ada (clean Mondrian and the Waldo 4K page) runs of the same public CLI at commit 3f0a9b3; timings are from the 4090. One scene per class, no confidence intervals.


---

## Related

- [Article: Tessera: Content-Adaptive Image Tokenization in FLUX.2 Latent Space](tessera-content-adaptive-tokenization.html) ([markdown](tessera-content-adaptive-tokenization.md))
- [Interactive demo](https://artifacts.kelechi.cc/tessera_demo_v2/)
- [Original proposal](https://artifacts.kelechi.cc/tessera_proposal/)
- [Markdown source of this report](tessera-v2-lab-report.md)
