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

2026-07-09

Transaction Science
wai-rs: hyper_scale_decoder — floor (>>) not truncation; byte-exact vs the REFERENCE decoder
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]>
2026-07-09 07:01:28 -04:00