Expand description
Learned probabilities for TCG3 code-blocks, in 32-bit integer arithmetic
end to end, so a WGSL kernel (no i64) reproduces every probability.
- Features: the TCG3-visible context (
Feats::raw: block-local causal neighbours, coarser-level parent, residual magnitudes) plus the class one-hot, as signedQ8log-magnitudes (integerlg_q8). - Network: M1b’s MLP (
learned::Net, ReLU, Q8 weights, Q16 biases), evaluated withi32accumulators: weights clamped to±2047(±8.0), activations to[0, 2^14](hidden) /±2^14(outputs), biases to±2^24, so no partial sum can overflow (28·2^11·2^14 + 2^24 < 2^31). - Output: a 2-component discretized logistic mixture (π logit, μ₁, μ₂,
log₂ s₁, log₂ s₂, all Q8). CDF in Q16 from two integer tables (σ in
Q16 over
|z| ≤ 16,2^{f/256}in Q16), built on the CPU with basic IEEE operations only and uploaded to the GPU as data. - Binarization (as M1b, without the APM): zero flag, sign, exp-Golomb
bucket by unary tail ratios, mantissa by integer bisection; each
decision’s
P(1)is an integer ratio of Q16 CDF masses.
Structs§
- AdCfg
- Adaptive-layer settings (stream header).
- Adapt
- Per-lane adaptive state over the MLP output: an adaptive probability map
(secondary estimation) per decision type, interpolated over
ABstretch-domain bins, count-based power-of-two rate. Integer only; reset per block. - Mix3
- Mixture parameters.
- Net32
- A network prepared for 32-bit inference.
Constants§
- AB
- APM bins per context (step 1.0 in the logistic domain,
±8). - AC
- APM contexts.
- NFL
- Features actually used (the rest of the
NFinputs are zero). - ZM
|z|range of the σ table (Q8).
Functions§
- ad_init
- A lane’s fresh adaptive state as the kernels hold it:
(p << 8) | countper bin (count 0), the layout of the adaptive residual graph’sadt. - code_
learned - Code residual
rundermxonlane. - code_
learned_ ad code_learnedthrough the lane’s adaptive layer.- feat_
vec3 - Integer feature vector of a coefficient.
- ratio16
P(1)·2^16from masses (num ≤ den ≤ 2^16), clamped for rANS.- sig16
- σ(z), z in Q8 → Q16.
- stretch_
tab - Inverse of
sig16on ap >> 4grid: the smallest Q8zwithsig16(z) ≥ p(p = 16·i + 8), sostretch(p) ∈ [−ZM, ZM]. - tables
- σ table (Q16,
k/256,k = 0..=ZM) and2^{f/256}table (Q16). - zval
d · 2^{−ls/256}(both Q8; result Q8) saturated to±(ZM+1), withlsclamped to[−16·256, 24·256]:t = ⌊d·m/2^16⌉with the Q16 mantissam = 2^{(256−f)/256}, then an arithmetic or saturating shift.