Skip to content

core: sixteen host bf16 copies are bf16_round's, identical on all 2^32 inputs - #1864

Merged
ashhart merged 6 commits into
ashhart:mainfrom
jschmied:bf16-host-core
Nov 2, 2026
Merged

ashhart merged 6 commits into
ashhart:mainfrom
jschmied:bf16-host-core

Conversation

@jschmied

@jschmied jschmied commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Part of #1863. Sixteen host fp32 → bf16 copies, in 14 files, become aliases of core/bf16_round.zig. Each is identical to bits() / round32() on all 2^32 fp32 inputs (checked exhaustively in ReleaseFast), so no word changes. The callers don't change.

family copies reaches core through
core contract/contract.zig toBf16 ../bf16_round.zig
Flash Next toBf16 in cuda_{mix,prompt_wt,attn,embed,qmm,ple,hc,gdn,moe}.zig, roundBf16 in cuda_mix.zig and cuda_hc.zig (→ round32) @import("core")
GLM glm/cuda_weights.zig toBf16, tests/cuda/glm_loader_gate.zig bf16 the core they already import
DeepSeek v4.1 named.zig bf16Round @import("core")
Qwen4 rounding_bound.zig bf64 (f64 → f64, = core.bf16; also on 2^26 random f64 words) core.contract.bf16_round, which the host, Metal and CUDA facades all export

Tests kept in the tree (the exhaustive run is about 1.2 s a copy in ReleaseFast, minutes in Debug):

  • core/bf16_round.zig keeps the replaced spelling verbatim and compares it with bits() on all 2^25 words with exponent 0 or 255 (every zero, subnormal, infinity and NaN), every tie with both neighbours, and 2^20 random words: 1.8 s in Debug. Planted controls: without the NaN branch it fails at the first NaN (0x7f80 for 0x7fc0); with ties rounded away it fails at the first subnormal tie.
  • qwen4/rounding_bound.zig keeps the old bf64 and compares it with core's by f64 bits on every fp32 tie and its neighbours, the fp32 edges, and 2^20 random f64 words.

Ten more copies are identical but don't move here, because their files can't reach core without build changes: fabric/ (no imports), living/affine.zig (core imports living), core/affine4_host.zig and core/quant/convert.zig (the relative import collides with the contract module), and four Metal-only files. I can list the change each would need.

Checks (GB10): lean 0 new, zig build test and the CI set pass, git diff --check clean.

@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. This is ready to land on our side: our gate passes on current main, and a GB10 run on Qwen3.8-27B gave identical prompt tokens in all 20 rows.

For the record, the speed cells read slightly lower (2K prefill 1438.6 to 1381.0 tok/s, decode 24.7 to 24.6). That run used our older base, new, new, base order, where base's first server is always fastest: base's own two runs were 1459 and 1418. The change only touches load-time host copies, so we read it as order noise, not a slowdown.

It's still marked as a draft, though, so GitHub won't let us merge it. If it's finished, could you mark it ready for review? We'll land it on the next cycle. The same goes for #1853, once our Gemma run on it finishes.

@ashhart
ashhart merged commit ba7b2c4 into ashhart:main Nov 2, 2026
1 of 9 checks passed
@ashhart

ashhart commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 3, 2026

Copy link
Copy Markdown
Owner

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.

2 participants