Skip to content

Model L reconstruction: CPU oracle (4 x 4 gather, linear-colour history and fallback, LDR) and the D / render variant rule - #124

Merged
phantoslayer21 merged 7 commits into
mainfrom
model-l/p12-ref
Nov 14, 2026
Merged

phantoslayer21 merged 7 commits into
mainfrom
model-l/p12-ref

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

#113 and #115 are merged. Against main, this PR changes only:

  • clean/l/reference/recon.py;
  • table.py, oracle.py;
  • clean/l/tests/test_l_recon.py, test_l_reference.py;
  • test_l_map.py (the map test now finds the map revision by its "preset": "L" key, because revision 1.1 updated
    the v1 file in place, and checks the table's 13 value positions against it instead of skipping).

The CPU oracle of Model L's output reconstruction (stage "post"), clean/l/reference/recon.py, driven by the
structure table's recon entry.

Model L's reconstruction is Model M's (clean/reference/post.py) with three changes:

  • a 4 x 4 colour gather (taps -1 ... 2 in both directions; rows from the even row of each pair, as Model M);
  • history candidates combined in linear colour: each valid sample is decoded and divided by the previous exposure,
    then w1 L1 + w2 L2, times the current exposure;
  • an invalid or reset sample falls back to the render pixel's plain linear colour.

The learned scale comes from the post stage. Everything else is Model M's functions, by import.

Behaviour confirmed by the spec side (for Model L and Model M) and implemented with known-answer tests:

  • Zero total gather weight (every tap underflows) has no special path: the normal formulas run with NaN, and the
    decode passes NaN through. The stored history is h(E(NaN)) = -1.4404296875 per channel in HDR and NaN in LDR; the
    display and the reduced code are 0 (also for any 2 x 2 block holding such a pixel). Model M's reference
    (clean/reference/post.py dec) maps NaN to D(1e-4) instead. That reference is not changed here.
  • LDR:
    • identity transfer, no exposure reads;
    • display codes are 11/11/10 bits of the plain colour, floor(clamp(O^ N + 1/2, 0, N));
    • the output stage unpacks code RN32(1/N) to FP16 and filters it with no decode and no exposure
      (recon.output_filter, Model M's taps).
  • History of another size with reset false is refused (a size change needs reset).

clean/l/FORMATS.md now points at the oracle and its pinned behaviour. It also says the kernel summation order
(taps, candidates) is not fixed yet: this oracle sums the gather columns first, Model M's rows first, and the
kernel's order will decide.

The table's recon entry now names the rule as a D / render ratio, with D = ((3 ow + 1) div 2, (3 oh + 1) div 2):
float32(D) / float32(render) >= 3.0 on both axes. table.recon_variant computes it. The two variants only tile the
work differently and compute the same function, so the oracle has one form.

PROVISIONAL is now empty. UNCONFIRMED keeps U1 (the encoder halo at tiny render sizes).

Tested

Record: CPU only (this PR has no kernel, so there is no GPU part). python -m unittest discover -s clean/l/tests -t .
passes all 45 tests, none skipped, at head de4d346. New in test_l_recon.py:

  • With Model M's recon entry (3 x 3, encoded domain), the L oracle gives Model M's oracle byte for byte (history,
    reduced, display), with and without reset.
  • The 4 x 4 gather against a tap-by-tap loop.
  • Reset: every sample takes the linear-colour fallback, combined in linear colour.
  • The linear combination against a direct recomputation of the candidates.
  • LDR reads no exposure.
  • Zero total gather weight (a, b = 65504, c = 0): HDR history -1.4404296875, display 0, reduced 0; LDR history NaN,
    display codes 0, reduced 0.
  • LDR constant image end to end (colour and history 0.5): display codes 1024 / 1024 / 512; after the output filter,
    exactly code RN32(1/N) in FP16, at exposure 1 and 5 alike (constants 0x3A001002, 0x3A802008).
  • A history of another size without reset is refused.
  • The variant rule at its edges:
    • 4K Performance (3840 x 2160 from 1920 x 1080) is exactly 3.0 and takes 3/1;
    • one render pixel more on either axis takes 3/2;
    • output = 2 x render takes 3/1 (the ratio is D / render, not output / render).

Not tested

  • The HIP kernel and its D3D12 port: next, each in its own PR.
  • Kernel-order exactness: the kernel's half-precision and fused-rounding forms are not part of this float64 oracle.
  • Motion at output resolution: the path is Model M's code, called the same way, and is not separately exercised.
  • Model M's reference keeps its own NaN decode; aligning it with the confirmed behaviour is a separate decision.

@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 01:47
….1 updated the v1 file in place)

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…behaviour (known-answer tests), LDR output filter, history size check; FORMATS points at the oracle

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
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