Skip to content

Model L kernels: encoder and decoder blocks, input linears, projections, coefficient step (HIP) - #115

Merged
phantoslayer21 merged 8 commits into
mainfrom
model-l/p9-hip
Nov 14, 2026
Merged

phantoslayer21 merged 8 commits into
mainfrom
model-l/p9-hip

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Stacked on #113 (the reference these kernels are checked against). Review the last commit only.

HIP kernels for Model L's encoder and decoder, to the interface in clean/l/FORMATS.md. Each is checked on the GPU
against the oracle step it implements.

Kernel Does
l_swin_block_c32_enc[_nc] encoder block: FP16 halo map in (window members outside the grid read the halo), FP8 out
l_swin_block_c32_dec[_nc] decoder block: FP8 in, token-grid mirror with the sub-pixel kept, FP16 out
l_linear_32_32_relu / _f16 the two input linears (FP8 -> FP8 with ReLU, FP8 -> FP16)
l_project_gather 2 x 2 gather and the 128 -> 64 projection (running FP16 sum per group of 32, clamp, FP8)
l_dec_project 64 -> 4 x 32 projection scattered to the pixel map
l_coef Model L's per-pixel functions (13 values, latent = tanh(candidate)) into Model M's output formats; reads no motion or previous latent
lev/input_encoder Model M's encoder.hip built with WG_ENC_VALUES_OUT=1 (l_enc_values.co): the 20 dithered values of every pixel of the padded grid plus a 2-pixel halo into the halo map (values at the mirrored render position, dither at the unmirrored one), and Model M's motion surfaces

Model M's input encoder (clean/kernels/encoder.hip) gets a build switch, WG_ENC_VALUES_OUT, which is off by default.
Model M's block template (clean/kernels/swin.hip) gets one hook: a gather-source template parameter whose default
is the existing gather. Model L passes its own sources for the FP16 halo and the token-grid mirror. The FP16 output
uses the existing epilogue hook.

What is proven and what is open

Proven:

  • Every new kernel agrees with the float64 reference oracle (R1, clean/l/reference/oracle.py) on synthetic data,
    within Model M's per-stage rule: at most 2 % of values more than one FP8 step off, and mean absolute error at most
    1 % of the reference RMS. The counts are below.
  • Both linears and both projections give the oracle's values exactly in every case checked.
  • Each _nc block kernel is byte-identical to its clamped form whenever the weights allow _nc.
  • Model M is unchanged: all 84 code objects that build.py --no-runtime --variants produces are byte-identical with
    and without this PR, including the encoder.hip switch.
  • The halo input encoder's values agree with the oracle within Model M's rule, its pad bytes are zero, and its motion
    surfaces are within Model M's rule for them.

Open:

  • Byte-exactness against the kernel-order CPU model (R2) is NOT shown. It is the byte-exact target, and it waits for
    the WMMA accumulation rule. The probes so far fit no candidate for full-range inputs, and that work is parked.
  • So the few block values that differ from R1 (1 and 26 of 487,424) are not yet classified as accumulation-order
    rounding or as errors. The same holds for the single FP16 C value of l_coef.
  • l_coef uses the hardware exp2 and reciprocal. The oracle's exponential and tanh are exact, so code-level
    identity there is measured, not proven.

Still to come: the D3D12 port of each kernel (kern2), each in its own PR.

Tested

GPU record: RX 9070 XT, locked GPU slots, 2 seeds, synthetic data, head of this PR.

  • Model M unchanged: clean/runner/build.py --no-runtime --variants from this branch and from its base,
    including the encoder fix: all 84 code objects byte-identical. The comparison is now a script,
    clean/runner/m_codeobjects_compare.py --base <ref> --work <dir>.
  • clean/l/runner/l_c32_check.py:
    • Encoder block: 16 cases, 1 of 487,424 values differs from the oracle, by 1 FP8 step.
    • Decoder block, 16 cases:
      • FP8-rounded values: 26 of 487,424 differ, max 4 steps.
      • FP16 criterion (below) met in every case: at least 99.937 % exact; at most 0.055 % of values more than 1 ulp
        off.
    • Coefficient codes from the real decoder-block output:
      • l_coef against the oracle's functions on that same output: A, B and latent codes 0 differ; 1 of 45,696 C
        values differs, by 1 FP16 ulp.
      • End to end against the oracle's block + functions: A 3, B 3, latent 7 of 45,696 / 45,696 / 60,928 codes differ
        (max 1, 1, 2), and 12 of 45,696 C values.
    • _nc forms identical in 32 of 32 cases. The existing C = 32 block: 0 values differ.
  • clean/l/runner/l_ops_check.py:
    • Both linears, both projections: 0 values differ in 8 cases each. The FP16 linear is within 1 ulp everywhere
      (0 differ).
    • Rounding boundaries, driven through the bias, give bit-identical outputs: FP16 ties over the whole exponent range
      and overflow to infinity; FP8 ties and saturation after RN16; the FP16 linear on +-448 inputs with large weights.
    • l_coef on random FP16 maps: A, B and latent codes 0 differ; 1 of 40,434 C values differs, by 1 FP16 ulp.
  • clean/l/runner/l_enc_check.py, 12 frames, including reset, odd sizes and render width 17 (padded 32, where two
    halo columns mirror onto column 0):
    • 12 of 669,440 halo-map values are 1 FP8 step off the oracle; pad bytes are zero.
    • The motion surfaces are within Model M's own rule for them (at most 1 FP16 ulp, at least 99.5 % exact).
    • Before the fix, the width-17 frames had 568 differing values (up to 94 steps), which the encoder criteria now
      reject.
  • CPU: python -m unittest discover -s clean/l/tests -t . (34 tests, one skipped until map v1.1 is in data/).

Criteria:

  • FP16 outputs: at most 2 % of values more than 1 FP16 ulp off, at least 99 % exact, mean absolute error at most
    1 % of the reference RMS, and no non-finite value where the reference is finite. The FP16 linear (one rounding)
    must be within 1 ulp.
  • Encoder values: Model M's per-stage rule, at least 99 % exact per frame, and at most 0.01 % of all values differ
    (Model M's encoder test).
  • End-to-end codes: at least 99.5 % identical per kind. The block's FP16 differences pass through steep functions
    (the latent code is 127 tanh), so a code can move by more than 1 where the block differs. l_coef itself is held
    to the strict bound on identical input.

Not tested

  • Byte-exactness against the R2 kernel-order model (its WMMA rounding rule is still open). The checks above use the
    float64 oracle with Model M's per-stage rule.
  • A whole L frame: needs param's runtime frame (Model L runtime frame on the HIP backend (confirmed FORMATS.md interface) #111).
  • The halo input encoder at render sizes so small that the mirrored halo position falls below 0 (table.UNCONFIRMED
    U1): not exercised.
  • D3D12 ports.

…rid mirror, FP16 output), input linears, both projections, coefficient step; GPU checks

Model M's block template gets a gather-source hook (default unchanged; all Model M code objects byte-identical).

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…G_ENC_VALUES_OUT, off by default), its GPU check; map-copy test

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
…column share its depth and motion (width-17 GPU case); FP16 criterion, rounding-boundary inputs and coefficient codes from the real block output in the GPU checks; Model M code-object comparison script

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 merged commit 5548c28 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/p9-hip branch November 14, 2026 01:45
j0nsh1n pushed a commit to j0nsh1n/wronggpu that referenced this pull request Nov 14, 2026
…r HIP kernels

l_ops_linear.hlsl ports l_linear_32_32_relu and l_linear_32_32_f16 of l_ops.co
(clean/l/kernels/l_ops.hip, phantoslayer21#115). No branch around the matrix instructions: a lane
past the end of the map stores its clamped pixel's bytes to that pixel (a branch
around the store let the compiler sink the WMMAs into it; wrong values in a partly
filled wave). l_d3d12_ops_check.py compares any l_ops.co kernel's D3D12 port with
its HIP kernel: raw bytes, each back end's output filled with its own sentinel, a
negative control. l_d3d12_check.py gains prepare_replay (the ports and
kernel_replay.exe), shared by both harnesses.

Refs phantoslayer21#89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
j0nsh1n pushed a commit to j0nsh1n/wronggpu that referenced this pull request Nov 14, 2026
…eir HIP kernels

l_ops_project.hlsl ports l_project_gather and l_dec_project of l_ops.co
(clean/l/kernels/l_ops.hip, phantoslayer21#115): two FP8 WMMAs then RN16 per group of 32 inputs,
the gather's clamp, FP8 out; no branch (a lane past the last token stores its
clamped token's bytes to that token's place). l_d3d12_ops_check.py gains their
cases (6 token grids, two of them partly filled waves).

Refs phantoslayer21#89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant