interplane.Get Omega
Read in your language

aien-train

AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.

Brought by drakestapleton

branch main Branches Tags History

aien-train / docs / omegallm / CONTRACT-BF16.md

255 lines · 14274 bytes Raw Blame History Source

Omega LLM BF16 tensor-core contract

This contract adds a BF16 tensor-core GEMM path to the GB10 build (TARGET=gb10). It extends CONTRACT-V2.md, which remains normative for everything this file does not change. The CPU product and the Python referee do not change. The BF16 path is opt-in, and every existing command keeps its exact behaviour.

Compatibility rule: every kernel slot except the new BF16 slots 27..36 keeps its exact code and register bytes. The AArch64 build is byte-identical to the base 273ca2a build. Host evidence for both statements is in evidence/OMEGALLM/gpu-bf/ (f32-identity.txt, build.txt).

1. Numerics

QuantityFormat
Master weights, Adam moments, checkpointf32 / f64 as v2 (unchanged)
GEMM operands on the BF16 pathf32 in memory, rounded to bf16 by round to nearest even (F2FP.BF16.F32.PACK_AB) while staged into shared memory
GEMM accumulationf32 (HMMA.16816.F32.BF16)
GEMM epilogue (alpha, beta, fused epilogues 1 and 2)f32, identical to the f32 kernels' gkepi64
GEMMs with n = E (32x32 tiles)f32 kernels, unchanged
gevalf32 kernels only, so the held-out loss metric does not change

The bf16 unit roundoff is u = 2^-8, compared with 2^-24 for f32. All weight updates stay in f32, and only GEMM inputs lose precision.

2. Kernels

There are ten kernels, slots 27..36 (gk.om gkgemmb). Each 128-thread block computes one 64x64 tile of C. K advances in tiles of 32, with two 8192-byte shared-memory buffers. Each warp issues eight HMMA.16816 per k16 step.

SlotOperand modes / epilogue
27 + ma + 2 mb + 4 betathe eight plain kernels (ma, mb in {0, 1}: 1 = K-contiguous)
35fused epilogue 1 (ma 1, mb 0)
36fused epilogue 2 (ma 1, mb 1)

Preconditions are checked on the host. Operand pointers and batch strides must be 16-byte aligned. Loads are 16-byte: mode 1 needs a stride that is a multiple of 16, and mode 0 needs outer stride 4 with a depth stride that is a multiple of 16. k must be a multiple of 32. There is no fallback: a GEMM the kernels cannot take fails with nverr -22.

gkbf 1 selects the path. Callers control this flag for BF16 training, diagnostic gates, and the selected inference projections described below. With gkbf 0, dispatch remains f32. Existing commands retain their previous selection.

Encoding provenance: the instruction words were verified with nvdisasm -b SM121 against ptxas 13.0 sm_121 output for mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32, cvt.rn.bf16x2.f32 and ld.global.v4.f32.

InstructionWords
HMMA.16816.F32.BF160x000000060c08723c 0x010fe20000041808
F2FP.BF16.F32.PACK_AB0x000000000309723e 0x000fe200000010ff

3. Commands

CommandArgumentsMeaningFailure exit
gtrainbCK TRAIN UNTIL EVERYgtrainf with gkbf 1as gtrainf
gprofbCK TRAIN Ngprof with gkbf 1as gprof
gbcmpCK DATA Ssampled check of every BF16 GEMM of one gradient pass48
gbcmp2CK DATA Sgcmp2 step parity with the BF16 bound49
gbfragCKexact check of all ten kernels on fixed data50

4. Gates

4.1 gbfrag (exact)

gbfrag runs thirteen cases: eight plain kernels, epilogues 1 and 2, and cz 1, 2 and 3 (cz 1 and 2 need k = m, so those cases use k = 128). Each case runs twice, once with the operand roles swapped. The data uses nz 6, h2 3 and padded strides, and every operand word the kernel must not read is NaN. These cases reach at most four K tiles (k = 128).

Every product is therefore a multiple of 2^-9 (2^-10 with alpha 1/2), and every partial sum stays below 2^11, so the f32 accumulation is exact. The reference applies bf16 RNE to the operands, and the chip result must equal it element by element. The fractional values need more than eight significand bits, so a kernel that skips the rounding or rounds toward zero differs from the reference.

Every C row has eight padding columns after column n - 1 (row stride n + 8). Before each case gbfrag writes NaN into them, and into the same columns of Y (epilogue 1) or M (epilogue 2). After the launch, every padding word that is no longer NaN counts as a mismatch, so a store outside columns 0..n-1 of its row, such as a wrong column offset, fails the case. The BF16 dispatch takes only m and n that are multiples of 64 (gk.om gktile), so these cases have no partial tiles. This check was added after bf-g1 (2026-11-04, evidence/OMEGALLM/gpu-bf/fix-pad/); its chip run is NOT_RUN until the integrator's pre-registered window. Mutant n (section 5) is its negative control: after each short case's launch the host writes 0.0 into C's first padding word (block 0, row 0, column n), so gbfrag must report exactly one mismatch per short case (26 GF lines with bad 1, 8 GFL lines with bad 0, GFS 26) and fail with exit 50.

Eight long-K cases (GFL pass ma mb bad) then cover the K loop: m = n = 64, k = 16384 (512 K tiles), nz 1, beta 0, alpha 1, all four operand-mode pairs, both role passes. Operands are zero except at kk ≡ 0 (mod 29), 565 terms, at least one in every 32-wide K tile, so a dropped, repeated or misplaced tile changes C. Sums stay below 565·5·17/8 < 2^13 (565*5*17/8 -> 48025/8 = 6003.125, Wolfram) in multiples of 2^-9, so the f32 result is exact. The logits buffer is NaN-filled first (A at 0, B at 6 MiB, C at 12 MiB, at least 4 Mi floats needed), and C's eight padding columns per row must still be NaN afterwards.

4.2 gbcmp (sampled, every BF16 GEMM of a step)

gbcmp runs one gradient pass (gggrad, no Adam) with every BF16 launch checked. Each launch checks 66 samples: 64 random positions (31-bit LCG) plus the two corners. Each sample is compared with an f64 sum over the bf16-rounded operands, over the K range that the kernel reads. The bound is

|chip - ref| <= (kn·2^-23 + 2^-22)·(|alpha|·Σ|a·b| + |old C|)

The first term is the f32 accumulation error over kn terms, with kn·u_f32 and u_f32 = 2^-24 doubled for slack; the second covers the epilogue's rounding. Wolfram: N[2^-23] -> 1.1920928955078125*^-7, N[2^-22] -> 2.384185791015625*^-7.

Fused epilogues are checked exactly:

The gate also fails when no BF16 GEMM ran, or when coverage misses any combination the step uses: epilogues 1 and 2, cz 3, and beta false and true. Which kernel ids ran is printed, not gated; gbfrag covers every id.

The bound grows with kn. At B 64 (kn = 16384) it is about one K tile's share of Σ|a·b| (16384*2^-23+2^-22 -> 0.00195336 against 32/16384 -> 0.001953125), so gbcmp at the training shape cannot see a single wrong K tile; at B 8 (kn = 2048) the margin is 64x. Long K loops are therefore checked exactly by gbfrag's long-K cases, not by gbcmp.

Because the bf16 rounding is in the reference, gbcmp checks the kernel against the stated numerics. It does not measure how far bf16 is from f32. That is the job of 4.3 and 4.4.

4.3 gbcmp2 (step parity, heuristic bound)

gbcmp2 is gcmp2 (the chip gradient compared with the CPU f64 gradient on the same batch) run with gkbf 1. Its tolerance is the first-order normwise heuristic tolb = n_c·(2u + u²), with u = 2^-8 and n_c = 10L + 3. n_c counts the BF16 GEMMs on a step's longest dependency chain:

The fail bits are 1 (non-finite), 2 (rho >= tolb), 4 (rel1 >= tolb) and 8 (|dloss| >= tolb·loss). At L 8: u=2^-8; nc=10*8+3; nc*(2u+u^2) -> 42579/65536 = 0.6497039794921875 (Wolfram). The bound is loose: it catches gross failures, such as non-finite values or a wrong layout. No mutant shows what it catches, and it is not a precision claim.

4.4 Training (decisive)

BF16 is adopted for training only if a pre-registered gtrainb run from the rung-7 start checkpoint reaches a chip geval held-out loss at step 2000 within +0.5% of the f32 rung-7 value. The rung-7 value is E 2000 = 1756935 µnats, so the bound is 1765719. Wolfram: Floor[1756935*1.005] -> 1765719. Step time is compared with rung 7's 0.2390 s/step. The pre-registration fixes the exact procedure.

4.5 f32 regressions

On the BF16 binary, the f32 commands must reproduce the rung-7 gate receipts exactly:

5. Mutants

Each mutant is a build flag (--mutant X). Each must fail at least one gate on the chip.

MutantConstantDefectExpected to fail
ugb.om OMUTU 0the reference skips the bf16 roundinggbfrag (exit 50); gbcmp reported only
lgk.om OMUTL 0A rows of lanes g and g ^ 1 swapped in the LDS layoutgbfrag, gbcmp
ogk.om OMUTO 0one K tile fewer than the tile countgbfrag (k ≥ 64 cases, long-K cases), gbcmp
vgk.om OMUTV 0F2FP rounds toward zero instead of to nearest evengbfrag, gbcmp
ngb.om OMUTN 0host overwrites C's padding word (0, n) with 0.0 after each short case (no kernel change)gbfrag (padding check only, GFS 26)

For mutant u, gbcmp is reported only, because the RNE-vs-exact difference per sample can fall within the f32 accumulation bound when Σ|a·b| is large. Mutant o cannot change a GEMM with a single K tile (k = 32): the K loop is a do-while and runs once regardless.

6. Host evidence

Chip gates 4.1-4.5 ran in two pre-registered windows, each EXERCISED on one GB10 (non-quiet), before the padding check existed:

7. Adoption

Drake approved adopting BF16 for training on 2026-11-03, after bf-t1 met the 4.4 rule. From then on, long training runs use gtrainb. The rest of the contract does not change:

What adoption gives up: a gtrainb step no longer matches the f64 CPU step bitwise. For BF16 runs, gbfrag and gbcmp check the kernels against the bf16 numerics instead, and gbcmp2 is the heuristic step check of 4.3. A binary used for gtrainb runs must pass 4.1-4.5 on the chip first.

Adoption is not a quality claim. 4.4 compares step 2000 only. The first long gtrainb run carries its own pre-registration and compares its final value with the f32 run on the same schedule.

BF16 inference with sensitive operations retained in f32

The opt-in gserveb and gsampb commands use BF16 tensor-core operands for the attention-output projection and the two feed-forward projections. Accumulation and epilogues remain f32. QKV projection, attention scores and value reduction, normalization and final logits stay f32. This is a mixed BF16/f32 inference path, not an all-BF16 model or checkpoint conversion.

They take the same arguments as gserve and gsample. Existing commands, training, evaluation and checkpoint formats retain their behavior. gdbench mode 7 executes this path; mode 8 compares it with the existing f32 forward on the same contexts. Mode 8 retains the existing 0.25-nat maximum logit difference and high-margin token-divergence rule. Modes 3 and 4 retain the original all-eligible-GEMM BF16 experiment, including its known failed accuracy result. No failed threshold was relaxed to admit the new path.

The external tests/omegallm/bf16-inference.py gate runs within an authorized Spark window. It checks both numerical and execution evidence: four prompts per supplied checkpoint, 250 steps each including context sliding; exact f32 and legacy-mode regressions; three BF16 projection dispatches per layer; CLI repeatability; and a compiled no-BF16 mutant that must lose those dispatches. The supplied baseline, candidate, source, compiler, checkpoints and tokenizer are hashed before and after the run. Its output is an acceptance record for those inputs, not a universal numerical error bound or a timing claim.

The existing serving referee accepts VERB=gserveb and compares responses with gsampb, so protocol and sampler parity exercise the same precision path. Source alone is not an adoption claim: preserve the actual gate receipts and independent review before installing this command.

The GB10 run is retained in bf16-inference-20261113. The receipt records the numerical, execution and serving check results. It does not establish a speedup.