wai-rs: hyper_scale_decoder floor(>>) not truncation — byte-exact vs the reference decoder #4

Merged
dcharlot merged 1 commit from hyperscale-floorfix into main 2026-07-12 12:22:07 -04:00
Owner

The per-channel power-of-two division is an arithmetic right shift (floor) in the reference decoder; the exported ONNX Div truncates toward zero, which differs on negatives (~1 LSB). Switching decode_hyper_scale from / to >> takes it from 30765/40960 to 40960/40960 BYTE-EXACT vs the reference i_s on real test256.bin data.

Retargets the calibration test from the (truncating) onnx.reference golden to the real reference-decoder i_s — the correct target.

General rule this establishes: the exported ONNX integer Div is a lossy stand-in for >>; trust the reference source, not the ONNX.

The per-channel power-of-two division is an arithmetic right shift (floor) in the reference decoder; the exported ONNX Div truncates toward zero, which differs on negatives (~1 LSB). Switching decode_hyper_scale from `/` to `>>` takes it from 30765/40960 to **40960/40960 BYTE-EXACT** vs the reference i_s on real test256.bin data. Retargets the calibration test from the (truncating) onnx.reference golden to the real reference-decoder i_s — the correct target. General rule this establishes: the exported ONNX integer `Div` is a lossy stand-in for `>>`; trust the reference source, not the ONNX.
The fully-integer hyper_scale_decoder does its per-channel ÷2^n as an ARITHMETIC
RIGHT SHIFT (floor), matching the real reference decoder. The exported ONNX
represents it as integer `Div` (truncation toward zero), which differs from `>>` on
negatives by 1 LSB — a ~1-LSB-wrong export. decode_hyper_scale used `/` (matching the
ONNX); switch it to `>>` (matching the reference).

Impact, on the real test256.bin hyper-latent (z[1,160,4,4] → i_s[1,160,16,16]): the
old truncation matched only 30765/40960 of the reference i_s (the rest off by exactly
+1, at the negative-remainder positions surfaced by the final abs); with `>>` it is
40960/40960 BYTE-EXACT vs the reference decoder.

Retargets tests/jpegai_hyperscale_calibration.rs from the (truncating) onnx.reference
golden to the real reference-decoder i_s — the correct target — validated byte-exact
on real data. Structural lib test unaffected (shape/range/determinism).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Transaction-Science/open-standards!4
No description provided.