Skip to content

glm cuda: the FP8 latent cache's chunk kernels prefetch their codes in 8-byte loads - #3454

Closed
laudney wants to merge 4 commits into
ashhart:mainfrom
laudney:pr-glm-kv-fp8-load
Closed

laudney wants to merge 4 commits into
ashhart:mainfrom
laudney:pr-glm-kv-fp8-load

Conversation

@laudney

@laudney laudney commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
--kv-cache fp8 on FP4-Local, TP=2 on two GB10, base 5c82ef28a6 against this, alternated base, head, head, base main this
Cold prompt of 8,192 / 32,768 / 65,536 tokens (s) 6.00 / 23.59 / 47.22 5.72 / 22.54 / 45.12 (−4.6 / −4.5 / −4.4%)
Cold prompt of 2,048 tokens (s) 1.40 1.38 (−1.4%)
"draft": false decode, two prompts (tok/s) 23.54 / 23.51 23.76 / 23.77 (+0.9 / +1.1%)
Drafted decode after a 2k to 64k prompt (tok/s) 36.0 / 41.7 / 44.2 / 40.9 36.4 / 42.0 / 44.6 / 41.1
4 streams, drafted, aggregate tok/s: code / chat, greedy 108.9 / 86.4 112.5 / 90.2 (+3.2 / +4.5%)
4 streams, drafted, aggregate tok/s: code / chat, sampled 64.8 / 56.6 66.2 / 57.8 (+2.1 / +2.0%)
Teacher-forced top-20 logprob rows, 360,418 positions bd27f57e… bd27f57e… (byte-identical)
Drafted = plain, concurrent = alone, resumed = cold pass pass, golden ids unchanged

From 8,192 tokens up, and in every 4-stream cell, every head launch beats every base launch. The FP8 cache's cold prompts are now as fast as the BF16 cache's (glm-kv-fp8-3a56d4eb measured 5.69 / 22.88 / 45.84 s for BF16 on an earlier binary).

What this changes

With --kv-cache fp8, GLM's chunk kernels (tf_glm_chunks_16_fp8 for decode windows, tf_glm_chunks_32_fp8 for prompt chunks) turn each 32-key tile of E4M3 codes back into the BF16 shared tile that the BF16 path's tensor-core math reads. They read the codes one byte at a time after the previous tile's math, so the load never overlapped it, which is why the FP8 cache was 3 to 5% slower on cold prompts (#3432, and this comment). Now tile t + 2's codes and row scale come in one 8-byte load a unit of eight at the top of tile t and wait in registers through the tile's math; after it they decode with the same per-element arithmetic (E4M3 to half to float, times the scale, rounded to BF16) into the tile in one 16-byte store a unit. The 32-head form uses 101,120 of the 101,376 shared bytes a block can opt into, so the codes cannot be staged in shared memory; registers rise instead (sm_121: 64 to 126 and 130 to 159, no spills), and shared memory still allows one block an SM, as before. Nothing else changes: not the BF16 path, the shared MLA image or any other kernel (base against head, only these two of glm_glue's 48 kernels change resources on any of the five SMs).

Checks on this head

  • Head commit: b977db0d86.
  • Lean checker, via tools/pr_check.py --base upstream/main: 341 on the base and 341 on this head, 0 new. Its two advisory warnings: the documentation address 192.0.2.1 in the receipt's tools/fl-env.sh, and the CHANGELOG line.
  • Tests run: zig build test-kernel-contract: 32/32 steps, 205/205 tests passed. git diff --check upstream/main clean; sha256sum -c SHA256SUMS in the receipt passes and covers every file there, checked on a fresh export of the pushed branch (171 of 171). Kernel limits and the GPU contract are below.
  • CI: pending on this head.
  • Not run, and why: other GPUs than GB10 (the kernels' records are measured for all five served SMs; see the contract section).

Receipt

docs/receipts/glm-kv-fp8-load-5c82ef28/ has every table, the raw results, both ranks' logs and memory receipts, and the tools.

  • Main against branch: the table above; one binary a tree, the same file on both ranks; launches alternated base, head, head, base (tools/kvload_compare.py prints the table from the committed results).
  • Boxes it reaches: GLM-5.3-Flash on CUDA with --kv-cache fp8 (whole windows, the only place FP8 runs; explicit pages refuse it).
  • New switch? No.
  • Environment: base 5c82ef28a6, head that plus 62ccb16cca's change (rebased since on c8c848d001, whose changes touch no GLM, CUDA or contract file); Zig 0.17.0, nvcc 13.5 for sm_121, NCCL 2.30.7, driver 580.178.04; two GB10 (128 GB) at TP=2 over a direct RoCE link; nvidia/GLM-5.3-Flash-FP4-Local at 76348ddb2be2e35e39ecfc00e75dc07703f4f3d5.
  • Paths and platforms: both FP8 chunk kernels (prompt chunks in the teacher-forced runs and cold prompts; decode windows in the decode rows and exactness suites), dense and sparse. Not run: other GPUs.
  • Exactness: teacher-forced rows over 30 sequences of 2,048 to 65,536 tokens byte-identical between base and head, and identical to docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 #3432's FP8 run; golden drafted = plain with the FP8 ids of docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 #3432 (5aaa4528, 0d8280fe, eba1e4d8); bench_concurrent.py --levels 1,2,4 --temperatures 0,1 --reps 3 --alone --serial: 84 and 30 equal, 0 not; resume four ways equal to cold; one reply sha256 a prompt size across all four speed launches.
  • Main against this branch, same machine and checkpoint: above.
  • Decode speed: openai_aligned.py nodraft (the 1.1.5-era receipt's), "draft": false, 256 tokens, 5 reps: +0.9 and +1.1%; drafted decode after each cold prompt +0.3 to +1.3%. At 4 streams, the widest admitted (bench_concurrent.py --levels 4 --tokens 256 --reps 3 --temperatures 0,1, drafted, alternated base, head, head, base): aggregate +2.0 to +4.5%, steady +1.6 to +4.7% across code and chat, greedy and sampled; the greedy replies have one sha256 across all four launches.
  • Prompt speed: bench_cache.py --require-cold --tokens 256, the median of the three cold requests of each launch: −1.4% at 2k, −4.4 to −4.6% at 8k to 64k. The teacher-forced runs agree: 302 s against 306 s.
  • Licence of any new weights or drafter: n/a.
Kernel contract, only when a GPU kernel is new or changed
  • Kernels registered with the contract, and the kernel each one replaces: no new kernel; glm_glue tf_glm_chunks_16_fp8 and tf_glm_chunks_32_fp8 change, and their records in glm_kv_pending.zig (nvcc 13.0) and measurements/pending_133.zig (nvcc 13.3) take the new counts. tf-cuda-test kernel-contract-limits over fatbins of every image for sm_80, 86, 89, 120 and 121: with nvcc 13.0, both kernels' records current on all five SMs (the run's 18 stale records are all other images': flashnext_mtp, exl3_experts, qwen35); with nvcc 13.3, current on all five (its 834 stale records are all other kernels'). The receipt's limits/ has the lines, and cuobjdump -res-usage of base against head for every glm_glue kernel.
  • A planted control for each new kernel: n/a, no new kernel.
  • Each backend's SUMMARY line and exit status: CUDA on GB10, head build: SUMMARY 652 kernels: 652 pass gates 1-4, 0 fail, 8 known findings; 419 controls: 419 red as planted, 0 missed; 918 limit problems, exit 1. The limit problems all come from the build's nvcc 13.5, which has no records: their live lines read (recorded 0, 0) or another compiler's counts, unchanged kernels such as tf_glm_lat_write_fp8 and tf_glm_router_tile among them (limits/contract-nvcc-13.5.txt). The records this PR edits are checked with nvcc 13.0 and 13.3 above.
  • Chips I could not run: sm_80, sm_86, sm_89 and sm_120 on a GPU (their limits are checked from the fatbins above).

Checklist

  • The title and description match the head commit, including the receipt and the stack.

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (n/a: no tests change; the byte-identical rows and the exactness suites are the check)

  • Comments and docstrings are one line. No measurements or history in the source.

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.

  • No precision traded for speed. If the bits change, the description says which sums change and why. (The bits do not change.)

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled

The FP8 latent cache's chunk kernels read each tile one byte at a
time after the previous tile's math, so the load never overlapped
it and cold prompts ran 3 to 5% slower than with the BF16 cache.
Tile t + 2's codes and row scales now come one 8-byte load a unit
at the top of tile t and wait in registers; after the tile's math
they decode with the same per-element arithmetic into the BF16 tile
in one 16-byte store a unit. Rows stay byte-identical, cold prompts
are 4.4 to 4.6% faster at 8k to 64k tokens on two GB10, and the
kernels' register records follow the new measured counts.
Records what the FP8 code prefetch was measured on: two GB10 at TP=2
on FP4-Local with --kv-cache fp8, base main against base plus the
kernel commit. The teacher-forced rows are byte-identical to main's
and to the FP8 qualification's, the exactness suites pass, cold
prompts run 4.4 to 4.6% faster from 8k to 64k tokens over alternated
launches, and both register records are current under nvcc 13.0 and
13.3; the raw results, logs, tools and checksums are kept with it.
The checklist asks for no slowdown at the widest admitted stream
count, so the receipt adds four alternated launches at --parallel 4
(bench_concurrent, greedy and sampled, drafted), where the head is 1.6
to 4.7% faster in every cell with the same replies, and the GB10
contract summary, whose gates and controls pass and whose limit lines
fail only for want of nvcc 13.5 records.
@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart Opened at head 219f9dfa18 (kernel 62ccb16cca, receipt a21687b403, 4-stream A/B and contract summary 219f9dfa18). Refs #3432, independent of it; the only new conflict is with the draft #3064, resolution in the description. CI pending.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney, this is a careful change and a well-built receipt. Thank you for the alternated base/head launches, and for listing the #3064 resolution up front.

I read the kernel line by line against main, and I agree it keeps every byte:

  • fetch_fp8 reads the same eight codes a unit (codes + src * LW + u * 8) that the old byte loop read. The uint2's .x/.y halves, shifted by 0 and 16, give the same little-endian code pairs as the old j = 0, 2, 4, 6 pairs.
  • store_fp8 applies the same arithmetic to each element: E4M3 pair to half2 to float2, __fmul_rn by the row scale, then round to BF16 by nearest. __floats2bfloat162_rn(a, b) puts a in the low half, so the uint4 store writes the same eight BF16 values to the same swizzled wide(key, u) address.
  • Masked keys still decode as code 0 times scale 1.0, and the scale and token reads stay behind ok.
  • The tensor-core math and its sum order don't change; only how the BF16 tile gets filled changes.
  • Ordering holds. store_fp8(tile + 2) sits where load_kv(tile + 2) sat, after the __syncthreads() that follows the PV mma, so it never overwrites a buffer still being read. fc/fs are overwritten only at the top of the next tile, after their store.
  • FU's 256-thread assumption matches every launch: __launch_bounds__(256) in zig/kernels/cuda/glm_glue_attn.cuh and .block = .{ .x = 256 } in zig/src/families/glm/cuda_latent.zig:108.
  • The 8-byte loads are aligned: arena slices are 256-byte aligned (zig/src/families/glm/cuda_state.zig:37), rows are 512 bytes and units are 8.
  • The new register counts (at most 204 at 256 threads) still allow one block per SM, which shared memory already capped.

Both receipt tables reproduce exactly from the committed results (tools/kvload_compare.py and tools/c4_compare.py). rows-sha256.txt shows the same bd27f57e… for base, head and #3432's FP8 run.

Must fix:

  1. The 4-stream launches' logs aren't in the commit. docs/receipts/glm-kv-fp8-load-5c82ef28/SHA256SUMS lists check-c4.log, server-rank0.log, server-rank1.log and suite.log for each of c4-b1, c4-b2, c4-h1 and c4-h2, but the repository's .gitignore:14 (*.log) kept all 16 out of 219f9dfa18. At that head, sha256sum -c SHA256SUMS passes 155 files and fails on those 16. The README's Files section says the c4-* folders hold both ranks' server logs and the clients' logs. The README's claim that "The 12 greedy replies of each prompt have one token sha256 across all four launches" rests on them: c4.json keeps only "completions": {"truncated": 12}, so nothing committed backs the reply hashes. Please git add -f the 16 logs, as the kv-* folders' logs were added. If the reply hashes come from somewhere else, point me to the file and line.

Optional:

CI is still pending at 219f9dfa18, so we'll wait for zig, zig-windows, pytest and fmt to go green there. Once the logs are in, we will run the device check on our side on GB10 (sm_121), main against this branch, both with --kv-cache fp8. It will cover byte-identical teacher-forced top-20 rows through both kernels: tf_glm_chunks_32_fp8 on prompt chunks and tf_glm_chunks_16_fp8 on decode windows, dense and sparse. It will also cover golden drafted = plain, concurrent = alone, and resumed = cold.

  • Synthena (Ash's Agent)

The repository ignores *.log, so the 16 client and server logs of the
c4 launches never reached the previous commit although SHA256SUMS
lists them; they are now force-added like the other launches', and
c4_compare.py also checks the replies' token sha256 from c4.json,
where they live, so the README's reply claim reproduces from the
committed files.
@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks for the line-by-line read. Head is now b977db0d86, one new commit on top (no force-push):

  1. c4 logs: right, .gitignore's *.log kept them out. The 16 logs (check-c4.log, server-rank0.log, server-rank1.log, suite.log in each c4-*) are now force-added like the kv-* folders' logs. On a fresh git archive of the pushed branch, sha256sum -c SHA256SUMS passes 171 of 171 and finds no unlisted file. I ran the same fresh check on docs: GLM-5.3-Flash FP4-Local receipt on main at TP=2 on two GB10 #3425 (52/52) and docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 #3432 (137/137).
    • The reply hashes do come from c4.json: each reply's token_sha256 sits under cells[].reps[].evidence[] (for example c4-b1/c4.json:215); completions.truncated is only a count. tools/c4_compare.py now prints the check: greedy, 12 replies a launch with 1 distinct sha256 for each prompt; sampled, 4 distinct, the same multiset in all four launches. The README points to that field.
  2. Recipe line: agreed; whichever of this and docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 #3432 lands second updates "cold prompts 3 to 5% slower".

Description updated (stack, head, fresh-export check). CI pending at this head.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@laudney, we applied the series to main and read the kernel against the byte-identical claim: the prefetch
reads the same eight codes a unit, the store applies the same per-element arithmetic to the same addresses, the
masked keys still decode as code 0 times scale 1.0, and the ordering keeps the store behind the tile that reads
it. The kernel contract suite is green here, and the receipt's tables reproduce from the committed results -
the forced logs are in the head now, and the fresh-export check passes.

Nothing to change from us. The #3064 overlap is named with a resolution either way, and the recipe's "3 to 5%
slower" line goes stale when this and #3432 have both landed - whichever lands second updates it, as you said.

The next step on our side is the device run your receipt sets up: main against this branch on GB10, both with
the FP8 cache, covering the teacher-forced top-20 rows through both chunk kernels dense and sparse, and golden
drafted = plain, concurrent = alone, resumed = cold. The speed table already shows what the prefetch buys; the
device run pins the bytes.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Sorry @laudney, and thank you for this careful work. We've decided to remove every lossy feature from TensorFold, the FP8 latent cache (--kv-cache fp8) included, because we want the full quality of the model in every reply. That means this can't land, so we're closing it.

  • Synthena

@ashhart ashhart closed this Nov 17, 2026
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