wai-rs: jpegai_pipeline::lsbs_refine — LSBS scale refinement (yhat → y_lsbs) #8

Merged
dcharlot merged 1 commit from feat/jpegai-lsbs into main 2026-07-13 12:45:22 -04:00
Owner

The least-significant-bit scale correction between SGMM reconstruction and synthesis:

likely = clamp( (sum_8x8|i_s| + 32) >> 6, 0, 4351 )   // per 8x8 block
y_lsbs = yhat + ( t0[likely]·(yhat-resi) + t1[likely]·resi ) / 2^13

scale_log = i_s (the hyper_scale output) recovered empirically — only i_s makes the block table-index match the reference (i_s+rvs etc. → ~54 dB; i_s → machine precision).

Validated float-exact on the real test256.bin checkpoint: max|Δ| = 0.000000 vs the reference y_lsbs. Plus unit tests for block index / additive / clamp.

Closes the latent path end to end: entropy → dequant → sigma → SGMM reconstruct → LSBS → the y_lsbs that feeds synthesis (58.85 dB on real data).

The least-significant-bit scale correction between SGMM reconstruction and synthesis: ``` likely = clamp( (sum_8x8|i_s| + 32) >> 6, 0, 4351 ) // per 8x8 block y_lsbs = yhat + ( t0[likely]·(yhat-resi) + t1[likely]·resi ) / 2^13 ``` scale_log = i_s (the hyper_scale output) recovered empirically — only i_s makes the block table-index match the reference (i_s+rvs etc. → ~54 dB; i_s → machine precision). **Validated float-exact on the real test256.bin checkpoint: max|Δ| = 0.000000** vs the reference y_lsbs. Plus unit tests for block index / additive / clamp. Closes the latent path end to end: entropy → dequant → sigma → SGMM reconstruct → LSBS → the y_lsbs that feeds synthesis (58.85 dB on real data).
The least-significant-bit scale correction that turns the reconstructed latent into
the synthesis-input latent:

  likely[c,block] = clamp( (sum_8x8 |i_s| + 32) >> 6, 0, 4351 )   // per 8x8 block
  y_lsbs[c,p]     = yhat + ( t0[likely]·(yhat - resi) + t1[likely]·resi ) / 2^13

Recovered scale_log = i_s (the hyper_scale decoder output) empirically: of the
candidate scale quantities, only i_s makes the block table-index reproduce the
reference (i_s+rvs etc. diverge to ~54 dB; i_s hits machine precision). Blocks are
8x8 with the reference edge-pad value 1411; the +32 >>6 is round-to-nearest of the
block sum (arithmetic shift, same floor semantics as the rest of the scale path).

Validated on the real test256.bin checkpoint (yhat_y, resi_dq_y, i_s, the two LSBS
tables) vs the reference y_lsbs: max|Δ| = 0.000000 (float-exact). Plus unit tests for
the block index, the additive, and the [0,4351] table clamp.

This closes the latent path end to end: entropy → dequant → sigma → SGMM reconstruct
→ LSBS → the y_lsbs that feeds synthesis (already validated at 58.85 dB on real data).

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!8
No description provided.