Skip to content

bf16_round: one std-only module, and the remaining fp32-to-bf16 copies on its bits() (#1863) - #2052

Merged
ashhart merged 3 commits into
mainfrom
lead/1863-bf16-rest
Nov 3, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/1863-bf16-rest

Conversation

@ashhart

@ashhart ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Part of #1863, after #1986. The rest of the engine's hand-written fp32-to-bf16 rounding copies move onto core's bf16_round.bits().

  • Commit 1: bf16_round becomes a small std-only module that every module imports by name. A Zig 0.17 file joins one module per compilation, so a shared file couldn't be imported by path from several modules. The easy set moves onto it: Gemma 4 DFlash weights, core affine4, pair_rows_layout, affine4_host, quant/convert, the Qwen-VL tower, the MOSS-Image encoder, the Qwen-Image host and the GLM vision tower.
  • Commit 2: affine_mm, the MOSS-Image host, H3 modulation, the fabric collectives and living affine move onto it too.

Exactness: 15 copies move. Nine give identical bits on every input. The other six give identical bits on every non-NaN input, and a NaN now stays NaN where the old copy had no NaN rule (affine4, pair_rows_layout, affine_mm, H3 modulation, the MOSS-Image encoder, Gemma 4 DFlash). Each moved copy has a bit-identical test, and each test was checked to fail when broken. h3/modulation was run by no test step, so this adds test-h3-modulation-bf16 under test.

Checks: zig build, zig build dev-tools and zig build test pass; lean stays at 424, and zig fmt is clean.

ashhart added a commit that referenced this pull request Nov 3, 2026
GLM's attn, eh and launch checks and CUDA FP8 KV reference, Nemotron's
training scan check, LFM2's DSpark taps test, Flash Next's HIP kernel
tests and the XPU FP64 GDN reference added the rounding bias with a plain
`+` and no NaN branch, so 0xffff8000-0xffffffff overflowed (a Debug panic).
Each now imports bf16_round by name, as #2052's callers do; a path import
would put core/bf16_round.zig in a second module beside the named one, so
tf-kernel-contract and the other tools importing the engine would not
compile. No build change. A test in each file pins 0xffffffff to a NaN
and the old bits on every bf16 value's tie and carry edges plus random
words; a one-off sweep of all 2^32 inputs gives the old bits on every
non-NaN and a NaN on every NaN.

Part of #1863; sits on #2052.
… easy-set copies on its bits()

core/contract.zig and the engine share builds (tf-kernel-contract, fsr-metal-contract), so a second path
import of core/bf16_round.zig puts the file in two modules; the named module, wired like save_guard, has
one owner. Each replaced copy keeps its public name as an alias and is checked bit for bit against its old
spelling on every zero, subnormal, infinity, tie and NaN class; NaN now stays NaN in each.
…lectives and living affine on its bits()

Each copy keeps its name as an alias and is checked bit for bit against its old spelling on every zero,
subnormal, infinity, tie and NaN class. affine_mm's and H3's copies had no NaN rule (a NaN came out +-Inf
or a zero); it now stays NaN, as the other four already did. H3's modulation had no test run, so its
check gets test-h3-modulation-bf16 under zig build test.
ashhart added a commit that referenced this pull request Nov 3, 2026
…st under zig build test

xpu/fp64_gdn.zig was compiled only into the xpu-qwen27 runner executable, so its test ran under no
build step, even with an Intel GPU. hostTests now roots a host module at it with the same stand-ins as
the host Qwen27 module (empty kernel images, the host ze table, core), so it needs neither ocloc nor a
device and runs on Linux and macOS. Dropping bits()'s NaN branch fails it at 0xffffffff.

Part of #1863; sits on #2052.
@ashhart
ashhart force-pushed the lead/1863-bf16-rest branch from bd96fdd to 9c7b30e Compare November 3, 2026 23:02
@ashhart
ashhart merged commit 023def3 into main Nov 3, 2026
4 of 11 checks passed
ashhart added a commit that referenced this pull request Nov 4, 2026
GLM's attn, eh and launch checks and CUDA FP8 KV reference, Nemotron's
training scan check, LFM2's DSpark taps test, Flash Next's HIP kernel
tests and the XPU FP64 GDN reference added the rounding bias with a plain
`+` and no NaN branch, so 0xffff8000-0xffffffff overflowed (a Debug panic).
Each now imports bf16_round by name, as #2052's callers do; a path import
would put core/bf16_round.zig in a second module beside the named one, so
tf-kernel-contract and the other tools importing the engine would not
compile. No build change. A test in each file pins 0xffffffff to a NaN
and the old bits on every bf16 value's tie and carry edges plus random
words; a one-off sweep of all 2^32 inputs gives the old bits on every
non-NaN and a NaN on every NaN.

Part of #1863; sits on #2052.
ashhart added a commit that referenced this pull request Nov 4, 2026
…st under zig build test

xpu/fp64_gdn.zig was compiled only into the xpu-qwen27 runner executable, so its test ran under no
build step, even with an Intel GPU. hostTests now roots a host module at it with the same stand-ins as
the host Qwen27 module (empty kernel images, the host ze table, core), so it needs neither ocloc nor a
device and runs on Linux and macOS. Dropping bits()'s NaN branch fails it at 0xffffffff.

Part of #1863; sits on #2052.
ashhart added a commit that referenced this pull request Nov 4, 2026
GLM's attn, eh and launch checks and CUDA FP8 KV reference, Nemotron's
training scan check, LFM2's DSpark taps test, Flash Next's HIP kernel
tests and the XPU FP64 GDN reference added the rounding bias with a plain
`+` and no NaN branch, so 0xffff8000-0xffffffff overflowed (a Debug panic).
Each now imports bf16_round by name, as #2052's callers do; a path import
would put core/bf16_round.zig in a second module beside the named one, so
tf-kernel-contract and the other tools importing the engine would not
compile. No build change. A test in each file pins 0xffffffff to a NaN
and the old bits on every bf16 value's tie and carry edges plus random
words; a one-off sweep of all 2^32 inputs gives the old bits on every
non-NaN and a NaN on every NaN.

Part of #1863; sits on #2052.
ashhart added a commit that referenced this pull request Nov 4, 2026
…st under zig build test

xpu/fp64_gdn.zig was compiled only into the xpu-qwen27 runner executable, so its test ran under no
build step, even with an Intel GPU. hostTests now roots a host module at it with the same stand-ins as
the host Qwen27 module (empty kernel images, the host ze table, core), so it needs neither ocloc nor a
device and runs on Linux and macOS. Dropping bits()'s NaN branch fails it at 0xffffffff.

Part of #1863; sits on #2052.
@ashhart
ashhart deleted the lead/1863-bf16-rest branch November 10, 2026 16:34
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