Expand description
Overfitted image codec (Phase 2, Track D): Cool-chic 5 style decoder in
exact 32-bit integer arithmetic, so the CPU reference and the GPU kernels
([crate::imggpu]) decode the same bytes to the same pixels.
The encoder side is the Cool-chic 5 reference (PyTorch, per-image
overfitting); tools/coolchic/export_cc.py dumps a trained image as a
Ccx file (integer latents + dequantized nets). encode turns that
into a TCI1 stream:
- Nets (ARM, IFCEs, upsampling, synthesis): each tensor as its
quantization exponent
splus integersk = v·2^s(zigzag varints), then fixed point with a per-layer weight precisionfwchosen by the encoder so that no accumulation leavesi32on this image (checked ini64; the decoder re-checks). - Latents: per grid (coarse → fine), Laplace probabilities from the
integer ARM (spatial causal context + IFCE inter-feature context),
quantized to
NFBμ-fraction ×NLBlog-scale buckets, coded with 16-bit-word rANS. Rows are spread overlanesindependent rANS streams and decoded in a wavefront (t = x + s·y,sfrom the context template), so every lane advances in lockstep; optional column tiles (tile_w) cut contexts at tile borders for more parallel blocks. - Synthesis: learned separable upsampling pyramid, then the synthesis
MLP / 3×3 residual convs, all
QA-bit fixed point; pixels areclamp(⌊255·v⌉, 0, 255).
Structs§
- Ccx
- A model exported by
export_cc.py: named f64 arrays with shapes. - Conv
- A synthesis convolution (
k×k, replicate padding). - Filt
- A symmetric 1-D upsampling / pre-concatenation filter.
- Guard
- Overflow guard: every accumulation is computed in
i64and must fiti32(so the GPU’s wrappingi32gives the same bits). - Layout
- Wavefront layout of one grid: tiles of
th × tw,laneslanes per tile. - Lin
- One linear layer
out × inp(w[o·inp + i]), fixed point. - Mlp
- ARM / IFCE MLP: hidden ReLU layers (square hidden layers residual inside
the ReLU when
residual), a linear output layer, and an optional linear stabiliser branch over the input added to the output. - Model
- Everything the decoder needs except the latent payload.
- Parsed
- Parsed stream.
- QT
- A quantized tensor: values
k · 2^{−s}. - RansDec
- Decoder side of one lane.
- Stats
- Encoder statistics.
Constants§
- CTX_
ORDER - Cool-chic’s context priority order (
get_priority_order, 9×9 causal mask) as(dy, dx). - FB_
SHIFT - μ-fraction bucket width
2^FB_SHIFT / 256. - LB_
SHIFT - Log-scale bucket width
2^LB_SHIFT / 256. - MAGIC
- Stream magic.
- NFB
- μ-fraction buckets.
- NLB
- Log-scale buckets over
ln b ∈ [−5, 5]. - NSYM
- Symbols per table.
- PB
- rANS probability precision.
- QA
- Fractional bits of upsampling / synthesis activations.
- QA_ARM
- Fractional bits of ARM activations (latents enter as
v << QA_ARM). - R
- Residual alphabet
r ∈ [−R, R]plus two escapes.
Functions§
- arm_
input - Gather the ARM input for global
(y, x)of a grid (values so far inlat, context cut at the tile border) intobuf(Q8). - bucket
(base, table offset)from the ARM output (μ, ln b inQ8).- dec_sym
- Decode one latent value with the table at
off(cum[0..=NSYM]). - decode
- Full CPU decode: stream → RGB8 (
h·w·3). Errors if any accumulation leavesi32(the GPU would wrap). - decode_
latents - Decode the latent grids (finest first) on the CPU. Lane
l’s rANS state runs on across grids (coarse → fine). - encode
- Encode an export into a
TCI1stream with the given lanes / tile width. - ifce_
ctx - Inter-feature context of grid
g([h·w][nifce],Q8) from the already-decoded coarser grids, or empty when the grid has no IFCE. - parse
- Parse a
TCI1stream. - psnr
- PSNR (dB) of two RGB8 buffers.
- segment_
graph - A synthesis segment: one (possibly 3×3) conv followed by 1×1 convs.
Params: the first conv’s taps
[cin][k][k](replicate-padded gather), then (if it is residual) itscincentre values; whenlast, then thestabinput channels. Outputs: the segment’s channels, or (whenlast) the three 8-bit pixel values. - segments
- Synthesis split into segments (each starts at a 3×3 conv or the input).
- slope_
of - Smallest
switht(y, x) = x + s·ystrictly after every context. - synthesize
- Synthesis → interleaved RGB8.
- tables
- Laplace CDF tables
[fb][lb][sym+1](cumulative,Q(PB)), built with plain IEEE f64 ops on the host and shared by both decoders. - upsample
- Upsampling pyramid → dense synthesis input
[C][h·w](Q(QA)).