Skip to content

Model L reconstruction oracle: steps 4-6 in float32 (the gap #135 found) - #137

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/recon-blend-f32
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/recon-blend-f32

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Settles the gap #135 found between l_post_recon and its oracle on frames with special input values.

Which side is wrong: the oracle. The spec side's order for Model L's reconstruction is float32 round-to-nearest
unless stated, with fused multiply-adds where it says so. The kernel follows that order. The oracle (recon.py) ran
steps 4 to 6 in float64:

  • the history candidates;
  • the combination;
  • the blend.

Where a large fallback colour (about 1e3 and up, the special values' 1e3 ... 1e6) is cancelled in the blend,
H^ = fused((C - Hl) beta' + Hl) rounds C - Hl to float32 first. A small H^ then carries the rounding of a large Hl, and
the float64 form lands many FP16 steps away. Reset frames have the most of these, since every sample is the fallback.
This matches what #135 sees: clusters, about twice as many on reset frames. The other special values behave the same
in both forms:

  • NaN colours (E_in maps NaN to 0; a NaN fallback ends in the NaN guard);
  • +inf (Hl = inf, then the NaN guard);
  • small negatives.

What changes

  • clean/l/reference/recon.py: with the table's new "blend": "float32", steps 4 to 6 run in float32, one rounding
    per operation:

    • L_i = f32(f32(D(h_i)) / e_prev);
    • Hl = f32(fused(w1 L1 + f32(w2 L2)) e);
    • alpha = sat(f32(f32(s W) g-bar));
    • beta' = fused(alpha f32(1 - beta-bar) + beta-bar);
    • H^ = fused(f32(C - Hl) beta' + Hl), and O^ likewise.

    Model M's entry keeps "blend": "float64", so the byte-exact reduction to Model M's oracle still holds.

  • clean/l/reference/table.py: the blend entries.

  • clean/l/tests/test_l_recon.py: the linear-combination, reset and offset-0.05 checks now recompute the float32
    order exactly (they compared float64 at 1e-12). New: the blend's float32 form holds exactly with large fallback
    colours, and the float64 form is more than 1 FP16 step away there.

  • clean/l/runner/l_post_check.py: three special-colour cases with the encoder's special values. The pixels where
    the blend cancels a large Hl (amplification of 256 or more) are reported apart. The criteria still cover every
    pixel.

  • clean/l/FORMATS.md: the blend precision.

The kernel does not change.

Tested

  • CPU: python -m unittest discover -s clean/l/tests -t .: 49 tests OK. clean.tests.test_post_reference OK.
  • CPU, oracle against itself (12 synthetic 64 x 40 frames, every third with reset): float64 blend vs float32 blend.
    • Without special colours: 34 of 466,560 history values differ, none by more than 1 FP16 step.
    • With the encoder's special colours: 724 differ, 453 by more than 1 step, at most 60 steps. 214 of the affected
      pixels have a fallback colour of 1e3 or more.

GPU record

RX 9070 XT, locked GPU slot model-l-blend-1, head c23653e, 2 seeds, synthetic data, clean/l/runner/l_post_check.py
(kernel unchanged, oracle with the float32 blend).

  • 19 of 20 cases pass. Negative control: fails, as required. Sentinels, alpha, top bits and slack hold in every
    case.
  • All cases together:
    • history: 22 of 143,928 values differ, 4 by more than 1 FP16 step (at most 2);
    • display: 23 differ, 4 by more than 1 step;
    • reduced codes: 1 of 35,460 differs, by 1;
    • largest mean error / RMS: 4.5e-7.
  • Special colours (6 cases): 15 of 61,482 history values differ. No ill-conditioned pixel in these cases.
  • The one failing case (special, 99 x 57, seed 89): 4 of 16,929 history values are 2 steps off, which is 0.024 %
    against the 0.01 % allowed.
    • The float64-blend oracle has 11 values over 1 step on the same output.
    • The 4 values are green at four neighbouring pixels. Their beta' is 1, so H^ = C: the gathered colour differs.
    • Cause, reproduced: one render pixel's green feature h(E_in(e c)) = 0.890625 sits 2 float32 ulps of log2 from the
      next FP16 value. The kernel's hardware log2 (v_log_f32, not correctly rounded) lands on the other side. Forcing
      that one feature to the next FP16 value in the oracle gives 0 steps at all 4 values (0 over 1 step anywhere,
      4 values differ in all). The step grows to 2 because the window's green also holds a clamped negative colour
      (E = -1.44), so the half accumulators cancel.
    • Ruled out: the input encode's float32 form, and a 1-ulp change of the gather's exp2 (neither moves the oracle).
    • This is the open kernel-order point, the hardware log2 / exp2 / reciprocal. It is not special-value handling.

Not tested

…rms (table blend: float32)

The spec side's order is float32 round-to-nearest unless stated. The oracle ran the
candidates, combination and blend in float64; where a large fallback colour is cancelled
in the blend, that lands many FP16 steps from the model. l_post_check gains special-colour
cases (NaN, 1e3..1e6, negatives, +inf) with ill-conditioned pixels reported apart.

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 03:37
@phantoslayer21
phantoslayer21 merged commit cc0a6df into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/recon-blend-f32 branch November 14, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant