lab

Chameleon v2: Replacing the Style Describer with One Linear Projection (and De-Leaking Krea 2's Sref Space)

Project chameleon v2, $1.76 of RunPod GPU time. Every number below comes from our own runs, with 95% code-bootstrap confidence intervals where paired. We report the dead ends alongside the wins: several sensible ideas failed cleanly on cheap probes before the final method clicked.


0. TL;DR

Eight random Chameleon v2 FLUX.2-klein-4B sref codes, each shown on a woman portrait and a lighthouse side by side
Eight deterministic --sref codes on FLUX.2-klein-4B (4 steps, zero describer, one 128-D linear projection). Each integer seed drives a distinct, consistent style across both subjects — woodblock pop art, synthwave, electric cyan, xerox ink, soft pastel, painterly sepia, 3D clay, and dark matte illustration.

1. The Analogy: Firing the Art Critic and Building a Brain-Wave Mixing Board

Imagine the frozen diffusion model — Qwen-Image 2.1 or FLUX.2-klein — as a master painter who only takes instructions through a headset.

At inference time there is no art critic and no essay:


2. Reverse-Engineering lyraaaa/krea2-sref-adapter

Before touching a GPU, we downloaded all four .npz weight files from lyraaaa/krea2-sref-adapter (sref_space.npz, sref_space_lg.npz, sref_space_variant.npz, sref_image.npz) alongside nodes.py and inspected their exact geometry.

What sits inside those 85 MB files

File Key Shape Dtype Geometry
sref_space.npz (default) basis, sd (64, 108, 6144), (64,) fp16, fp32 Exact orthonormal rows (B @ B^T = I_64, cond = 1.00002); sd L2 552.50; eff. rank 15.0 (PR) / 27.4 (entropy)
sref_space_lg.npz (lg) basis, sd (64, 108, 6144), (64,) fp16, fp32 Exact orthonormal rows (cond = 1.00002); sd L2 568.08; median principal cosine 0.972 vs default
sref_space_variant.npz basis, sd (64, 108, 6144), (64,) fp16, fp32 Oblique rows (slice norms 35.6–61.1, cond = 5.01); token-cov sqrt(tr) = 534.70
sref_image.npz encode, bias, gram (64, 108, 6144), (64,), (64, 64) fp16, fp32, fp32 gram == B_var @ B_var^T (max diff 0.0097); exact oblique right-inverse encode @ B_var^T = I_64 (max err 6.1e-6)

Four concrete lessons fell straight out of that inspection:

  1. Where the signal lives: Krea 2 formats a 256×384 reference image through Qwen3-VL -> txtfusion -> txtmlp into 108 position-less tokens (pos = 0). Across those 108 positions, 97.97% of basis energy sits on the 96 <|image_pad|> vision tokens (8×12 grid), with < 1.3% each on the 6 prefix and 6 suffix tokens.
  2. Why encode is not a naive pseudoinverse: Even though encode @ B_var^T = I_64 to fp16 precision, encode differs from the Euclidean pseudoinverse G_var^-1 B_var by 43.2% relative norm — ~39.7% of encode's norm sits in row(B_var)^perp. That orthogonal component W_perp is the exact signature of a whitened/discriminant linear readout projecting out correlated non-style variance before mapping into the 64 style coordinates.
  3. Norm calibration matters: In nodes.py, image coordinates are rescaled to STYLE_SIZE = 540.0 in the gram metric (sqrt(a^T G a)) before multiplying by strength = 6.0. That 540.0 is simply the rounded expected Frobenius norm of a random code (sqrt(sum(sd^2 * diag(G))) = 534.7–568.1).
  4. Why it doesn't port 1-to-1 to Qwen-Image 2.1 or FLUX.2-klein:
    • In Qwen-Image 2.1 (src/chameleon/qport/dit.py), Dit.prefill overwrites every <|image_pad|> row with img_in(vae_latents) — the DiT never sees Qwen3-VL's vision tokens, and its text stream uses sequential 1D RoPE with causal masking.
    • In FLUX.2-klein-4B (src/chameleon/klein.py), the encoder is text-only Qwen3-4B (layers 9/18/27 stacked to 7680-d), with bidirectional text attention and decoupled text RoPE (0, 0, 0, l) — closer to Krea 2's bag of tokens, but with no vision encoder at all.

So we borrowed Lyra's algebra (zero neural training, fixed linear basis + sd in a native conditioning stream, STYLE_SIZE norm calibration, scalar alpha amplification, content-whitening encode, and 1M-code nearest_code lookup) and aimed it at the conditioning highway both Qwen-Image and Klein actually read natively.


3. Stage 1: Fast-Fail Channel Oracles on Qwen-Image 2.1 ($0.457)

Before scaling anything, we ran four cheap channel probes on the 10 Ceiling Midjourney codes (configs/ceiling, 2 default + 2 nature prompts, 1024 px, judged with CSD, OneIG, DINO_fed, CLIP-T) on a Secure A40 ($0.59/hr). Our rerun of v1's hand-written rich text ceiling scored .503 / .449, reproducing v1's .502 / .457 and validating harness parity.

Probe (1024 px, 10 ceiling codes) CSD default CSD nature OneIG d/n DINO_fed d/n CLIP-T d/n Verdict
rich hand-written ceiling (rerun) .503 [.397, .609] .449 [.334, .568] .592 / .534 .214 / .060 .227 / .246 Reference ceiling (copies slightly on default)
1A extrap2_loosen on rich .472 [.369, .576] .376 [.278, .478] .514 / .409 .164 / .057 .217 / .244 Failed at 1024 px (won 512 px screen .444/.401, lost −.074 on nature at 1024)
1B pad64 rank-64 PCA oracle (α4, l2) .329 [.268, .395] .311 [.258, .372] .450 / .387 .082 / .038 .257 / .247 Only viable zero-describer channel (lowest copying ever measured; crisp random --sref codes)
1C Qwen3-VL image readouts (512 px screen) .288 / .306 .176 / .274 – .058 / .217 .240 / .195 Killed (text readouts < .25 macro; raw vision tokens copied heavily at DINO_fed .217)
1D pooled win12_19 KV + 1B combo .329 [.267, .396] .313 [.260, .374] .441 / .394 .081 / .038 .257 / .247 Killed (standalone .070 = no style; combo +.000/+.002 — 16–64 pooled keys diluted against ~4k image tokens)
v1 baselines (r7 / win12_19 / LoRA) .381 / .385 / .445 .312 / .328 / .345 – – – Prior v1 benchmarks on the exact same 10 codes

Three sharp findings shaped Stage 2:

  1. 512 px screens lie about alpha and loosen: Probe 1A beat rich at 512 px (.444 vs .384) and lost significantly at 1024 px (−.074 on nature). We calibrated all Stage 2 choices directly at 1024 px.
  2. summary32 was completely dead (.071 CSD = no style) and pinned pos = 0 RoPE slightly hurt (.302 vs .311 sequential). Simple right-padded/truncated text tokens (pad) with sequential positions won.
  3. Why Probe 1B's 8 random --sref codes looked great while its image oracle lost .17 CSD: Even on 2,000 styles, random Gaussian draws in Qwen-Image's post-txt_in space produced clean cyan ink, flat pastel, bold vector art, and even white 3D matte clay sculpture (a material Chameleon v1's describer never captured). The bottleneck was unsupervised PCA over unaligned prose plus truncating 90-word descriptions at 64 tokens.

4. Stage 2: Content-Whitened Supervised RRR on Qwen-Image 2.1 & FLUX.2-klein-4B ($0.836 + $0.164 edits)

Exact closed-form math (zero backprop, < 2 GB RAM)

From our Phase 0 audit (runs/v2_phase1/alignment.json), we had an exact 1-to-1 join across 320,000 MegaStyle image embeddings (runs/grid_prior/pooled_f00001..4.npy, 1152-d, 8 images per style) and 40,000 DeepSeek VLM style descriptions (tensorkelechi/chameleon-style-labels).

Using the first 20,000 styles (160,000 individual images, shards f00001 + f00002) — a 140:1 sample-to-feature ratio — we stream descriptions in batches through the frozen text encoder without ever storing the 24 GB raw target matrix Y ([20000, K*D]):

1. Stream 20k descriptions -> accumulate ONLY:
     sum_y [K*D]                         (for global mean mu)
     EtY   = sum_s (sum_{i=1}^8 e_{s,i}) @ y_s^T    [1152, K*D] (~1.8 GB fp32)

2. Build input covariance over ALL 160,000 individual images:
     EtE   = sum_{s,i} e_{s,i} e_{s,i}^T            [1152, 1152]
           = 8 * (Sigma_B + Sigma_W)     <-- contains within-style content variance!

3. Solve closed-form Content-Whitened Ridge Regression:
     W     = solve(EtE_c + lam * I, EtY_c)          [1152, K*D]

4. Exact Reduced-Rank SVD of C_style^(1/2) @ W = U S V^T:
     basis  = V[:r]                      [r, K, D]  (orthonormal pure-style basis)
     sd     = S[:r]                      [r]        (empirical std per style axis)
     encode = (W @ V[:r].T).T            [r, 1152]  (content-whitened image encoder)
     STYLE_SIZE = sqrt(sum(sd^2))                   (expected random-code L2 norm)

At inference time:

Notice one diagnostic detail from the fits: a single image's raw uncalibrated regression predicts only 2.5–4.4% of a held-out description's full token variance, and its raw norm comes out 2–4× too small. That is why Lyra's norm calibration (STYLE_SIZE) plus alpha amplification (α=3 on Qwen, α=5 on Klein) turned a timid raw regression into crisp, full-strength style transfer.

1024 px calibration & winning specs

Both models were calibrated directly at 1024 px on an RTX A5000 ($0.27/hr):

Headline quantitative comparison (1024 px CSD ↑, 95% code-bootstrap CIs)

Benchmark CSD comparison across Chameleon v1, Stage 1 PCA, and Chameleon v2 on Qwen-Image 2.1 and FLUX.2-klein-4B
Benchmark CSD comparison across Chameleon v1, Stage 1 PCA, and Chameleon v2 on Qwen-Image 2.1 and FLUX.2-klein-4B

1024 px CSD across benchmarks (higher is better). Stage 2 Content-Whitened RRR jumps +.107 CSD over Stage 1's unsupervised PCA oracle on Qwen-Image 2.1 without any AR describer, and carries over cleanly to 4-step FLUX.2-klein-4B.

Benchmark (1024 px, true image-to-sref) v1 r7 (59.8M AR) v1 win12_19 v1 LoRA v1 rich ceiling v2 Qwen (RRR) v2 Klein (RRR, Tessera-ready)
20 MJ codes, default .433 – – – .414 [.331, .496] .361 [.300, .417]
20 MJ codes, nature .390 – – – .365 [.285, .446] .364 [.299, .425]
10 ceiling, default* .381 .385 .445 .503 .436 [.295, .574] .313 [.218, .389]
10 ceiling, nature .312 .328 .345 .449 .354 [.224, .491] .329 [.227, .415]
Photo edit (8 codes × 3 photos) – – – – .404 (DINO_photo .741) .391 [.316, .465] (DINO_photo .663)
Random --sref (within / between / gap) – – – – .558 / .213 / .345 .498 / .101 / .397
No-style floor – – – – .114 .050
Plain-text ceiling – – – .503 (Qwen) – .497 (DINO_fed .201)

*10 ceiling default was the 1024 px calibration split; 10 ceiling nature and MJ codes 11–20 are strictly held out. Note that v1 per-code records live on Google Drive (tensordrive2: OAuth expired), so v1 comparisons are unpaired while Stage 1 vs Stage 2 and Qwen vs Klein comparisons are paired.

What the numbers (and eyes) tell us: Qwen-Image v2 vs. FLUX.2-klein v2

Chameleon v2 FLUX.2-klein-4B showcase card for vivid pop gouache across six prompts
FLUX.2-klein-4B v2 — vivid pop gouache (mj_1499232858). Single reference image encoded through MegaStyle + one closed-form linear matrix (zero describer). Every prompt — including stubborn nature birds — shifts cleanly into flat pop-art gouache without copying the reference subject.
Chameleon v2 FLUX.2-klein-4B showcase card for violet dusk across six prompts
FLUX.2-klein-4B v2 — violet dusk (mj_235080088, `.584` CSD). Consistent dusk palette and painterly texture across all six prompts in 4 denoising steps.
Ten Midjourney styles applied with Chameleon v2 on FLUX.2-klein-4B across five prompts
Ten styles × five prompts on FLUX.2-klein-4B v2 (no held-out references shown). Honest miss visible on row 10 (mj_2077236407, ornate mythic mural) and colour shift on neon matrix green (blue/purple on Klein vs green on Qwen below).
FLUX.2-klein-4B v2 photo restyling across 8 styles on Vermeer, eagle, and chameleon
FLUX.2-klein-4B v2 native photo restyling (CSD .391, 4 steps, full photo reference at t = 10, zero describer). Aggressive restyling across paintings and stubborn nature photos alike — pop gouache, monochrome comic, ember rim light, cel-shaded storybook, and sepia manga ink.
Qwen-Image 2.1 v2 photo restyling across 8 styles on Vermeer, eagle, and chameleon
Qwen-Image 2.1 v2 native photo restyling (CSD .404, DINO_photo .741, DINO_fed .085, restyle depth 13 on eagle and chameleon). Preserves faces and details more conservatively while holding exact colours like neon matrix green and muted navy slate.
Side-by-side comparison of Chameleon v1 head_grid against Chameleon v2 Qwen-Image and FLUX.2-klein-4B on identical styles, prompt, and photos
Chameleon v1 vs. v2 head-to-head (same fed reference image, identical heron prompt and Vermeer/eagle/chameleon edit targets). Chameleon v2 drops the 59.8M AR describer completely while matching or beating v1 visually on vivid gouache and navy slate.
Monotonic strength sweep from 0x to 2x and smooth linear interpolation between two styles in 128-D space
Single-pass strength dial (×0 to ×2 of α) and smooth linear interpolation between two styles in 128-D coordinate space. Round-trip image → nearest of 1M codes achieves cosine .74–.82 on Qwen and .55–.72 on Klein.

5. Bonus: Diagnosing & Fixing Object Copying in Lyra's Krea 2 Adapter ($0.305)

Lyra's README for krea2-sref-adapter notes an honest limitation: "Some codes bring a recurring object along with the look." With budget remaining under our $2.00 cap, we applied the exact same content-whitening lens directly to Lyra's 64-D Krea 2 space.

The analogy: unplugging 4 "ghost-object" sliders

Think of Lyra's 64-D basis as a 64-slider soundboard built from raw Qwen3-VL image tokens. We ran 868 images grouped into 126 styles (multiple different subjects per style) through Krea 2's own Qwen3-VL -> txtfusion -> txtmlp -> sref_image.npz["encode"] (matching Lyra's read() to 7e-4) and measured two variances inside the whitened 64-D space:

Surprise: Lyra's image codes actually vary more with the subject (178k) than with the style (154k).

Solving the generalized Fisher eigenproblem Sigma_W v = lam * (Sigma_B + eps * I) v immediately isolates the directions with the worst subject-to-style ratio (top 4 ratios: [11.52, 10.85, 10.21, 8.82]). Removing just those 4 directions (fisher k = 4, ~15% of a random default code's energy) via orthogonal nullspace projection — preserving STYLE_SIZE and producing drop-in sref_space*_clean.npz and sref_image_clean.npz files with zero retraining and zero changes to Lyra's node — immediately jumped held-out style retrieval from .389 to .456.

Krea 2 within-style vs between-style variance and before-vs-after Fisher k=4 de-leaking metrics
Krea 2 within-style vs between-style variance and before-vs-after Fisher k=4 de-leaking metrics

Left: within-style variance (178k) exceeds between-style variance (154k) inside Lyra's 64-D Krea 2 space. Right: removing just the top 4 Fisher subject directions cuts cross-prompt object copying while raising style consistency and image-to-sref CSD.

Before vs. after on Krea 2 Turbo (640 px, Comfy-Org/Krea-2 fp8, Lyra's exact settings)

Benchmark CSD_group ↑ DINO_fed ↓ Cross-prompt DINO ↓ CLIP-T ↑ CSD within / between code
Test A original (default space, 8 codes × 3 prompts) – – .141 .235 .383 / .140
Test A cleaned (fisher k=4, drop-in .npz) – – .087 .233 .425 / .124
Test B original (sref_image + variant, 10 MJ codes) .353 .171 – .228 –
Test B cleaned (fisher k=4, drop-in .npz) .382 .166 – .232 –
Paired Δ (cleaned − original) +.030 [+.004, +.055] −.005 (n.s.) −.054 [−.133, +.001] ≈ 0 –
Krea 2 worst object-copying sref codes before and after removing 4 Fisher subject directions across woman portrait, lighthouse, and ceramic teapot
Before (left of each pair) vs. after fisher k=4 cleanup (right) on Krea 2 Turbo. Top row (code 2394083199, cross-prompt DINO .421 → .136): Monet-style women in white dresses completely disappear from the lighthouse and ceramic teapot while the exact impressionist brushwork and palette remain intact. Row 4: the bystander torso next to the teapot vanishes too. Row 2 (370647992): the grimacing comic face weakens but partially survives.

Honest takeaways from Stage 2.5:


6. Spend Ledger & Honest Limits

Every experiment ran on RunPod with automated pod-side GraphQL self-termination and a hard $2.00 total cap. All pods were terminated and verified pods == [] at $0/hr.

Stage Scope GPU Settled USD
Stage 1 Phase 1 channel oracles (Probes 1A–1D, 1024 px ceiling confirm) A40 Secure ($0.59/hr, 2 pods) $0.4574
Stage 2 20k Content-Whitened RRR fits + full 1024 px evals (Qwen + Klein) Secure RTX A5000 ($0.27/hr) + 2 aborted SSH setups $0.8360
Stage 2.5 Krea 2 fisher k=4 diagnosis, drop-in .npz, before/after eval A40 Secure ($0.59/hr, 27.4 min) + failed 4090 alloc $0.3054
Stage 3 24 FLUX.2-klein-4B photo edits (t = 10) + judges (incl. 1 SSH-drop rerun) A40 Secure ($0.59/hr, 2 short pods) $0.1636
Total Full Chameleon v2 + Krea 2 de-leak All pods terminated (pods == []) $1.762

Open limits and next steps

  1. Basis vs. encoder ceiling: Our 20k-style linear fit already matches v1 r7 within ~.02 CSD on 20 MJ codes and beats it on the 10 ceiling codes, while staying ~.07–.10 below hand-written descriptions (.503). Whether a richer image encoder (e.g., MegaStyle 4×4 spatial grid features alongside pooled 1152-d, or scaling to all 40k styles) closes the remaining gap is an immediate, cheap follow-up.
  2. Klein photo edits vs. face preservation: Klein's α = 5 restyles paintings and animals boldly in 4 steps, but alters Vermeer's face more aggressively than Qwen (DINO_photo −.223). Sweeping α = 2.5–3.5 for edit mode (separate from α = 5 for T2I) is a trivial zero-training dial.
  3. Tessera×Klein composition: Because sref_klein.npz lives entirely in the untouched 7680-d text-conditioning stream, testing Chameleon v2 --sref codes directly on top of a Tessera-tokenized FLUX.2-klein DiT requires zero retraining of either adapter.

Code is on GitHub (Chameleon v2 on main, original AR describer preserved on branch v1); cleaned Krea 2 de-leaking tooling (tools/deleak_basis.py + backwards-compatible clean toggle for nodes.py) is prepared as a local PR branch against lyramakesmusic/krea2-sref-adapter.