Skip to content

docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 - #3432

Merged
ashhart merged 4 commits into
ashhart:mainfrom
laudney:pr-glm-kv-fp8-quality
Nov 16, 2026
Merged

ashhart merged 4 commits into
ashhart:mainfrom
laudney:pr-glm-kv-fp8-quality

Conversation

@laudney

@laudney laudney commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Against FP4-Local with the BF16 cache, 360,418 teacher-forced positions --kv-cache fp8 NVFP4 checkpoint, BF16 cache (scale)
Mean NLL (BF16 cache: 1.40910) 1.40831 (−0.06%) 1.40912 (+0.001%)
Best token the same 95.49% (96.27% within ties) 92.23% (93.01%)
KL over the reference's top 20, mean / p99 0.0162 / 0.151 0.0432 / 0.408
Given token near sure on one side, below even odds on the other (BF16-cache sure / other sure) 52 / 64 of 127,647 149 / 137
Drafted = plain, concurrent = alone, resumed = cold pass (as with the BF16 cache) (not run)
Cache bytes a token on each rank (12 latent caches) 6,960 against 13,056 (−47%), beside 231 MiB fixed a stream either way
Cold prompt, 8,192 to 65,536 tokens 3 to 5% slower

A BF16-cache rerun gives the same bytes, so every difference in the first column is the cache's.

What this changes

Since 1.1.2 the GLM CUDA recipe (and the optimization ledger) have said the opt-in --kv-cache fp8 latent cache's native quality and device qualification are pending. This adds docs/receipts/glm-kv-fp8-3a56d4eb/, diagnostic evidence of how far the FP8 cache moves on nvidia/GLM-5.3-Flash-FP4-Local at TP=2 on two GB10. FP8 changes tokens against the BF16 cache (all three golden replies differ), so it is not qualified: the recipe and ledger now say BF16 stays the only qualified cache and point to these measurements as diagnostics. The default stays BF16 and nothing in the engine changes.

Checks on this head

  • Head commit: 65f39f44e6.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 341 and 341, 0 new (tools/pr_check.py --base upstream/main).
  • Tests run, with the command and pass, fail and skip counts: tools/pr_check.py: 0 errors, 1 advisory warning, the documentation address 192.0.2.1 in the receipt's tools/fl-env.sh (the recipe's own example address). git diff --check upstream/main clean. sha256sum -c SHA256SUMS in the new receipt passes and covers every file there. tools/mktexts.py rebuilds the corpus texts byte for byte (sha256 in corpus/sha256.txt); kv8_compare.py's control (a run against itself: 0 differences) and a planted single flip (counted once, with its margins) checked before the runs. Documentation only, so no host suite.
  • CI: green on 7286659d47; pending on this head.
  • Not run, and why: the host suite, since nothing under zig/ or tools/ changes.

Receipt

n/a for the change itself: documentation only, so it cannot reach inference. The receipt it adds is its content; its README has every table and the method.

  • Environment: 3a56d4eb92, one binary for every launch (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; for scale nvidia/GLM-5.3-Flash-NVFP4 at 423acf37583782c51c142d145aef733d72943d93.
  • Fidelity: 30 sequences of 2,048 to 65,536 tokens from two public domains of TensorFold itself at cc8f2889e7 (docs/**/*.md outside receipts, and zig/src/**/*.zig), through /v1/completions with prompt_logprobs: 20 (the 1.1.5-era receipt's s5_prompt_lp.py). A prompt pass writes its chunk's latent rows before any row attends, so every key it reads comes through the FP8 cache, as in decode. All 16,250 top-1 differences are listed with both margins; the reference's margin is at most 0.125 at half of them and 1.0 at 95%. The one band that rises (+0.84%, positions 32,768 to 65,535) is one prose sequence's changelog-style link lists, and NVFP4 rises there too (+0.68%); the near-sure tokens there go both ways (21 lost, 18 gained). Code and every position below 8,192 have no near-sure token lost.
  • Exactness with the FP8 cache, the same suites as the BF16 cache's launch: golden drafted = plain on all three prompts; bench_concurrent.py --levels 1,2,4 --temperatures 0,1 --reps 3 --alone --serial: 84 and 30 equal, 0 unequal; four resumed replies equal to the cold one. The golden replies differ from the BF16 cache's after 7, 171 and 38 characters.
  • Decode: "draft": false 23.5 and 23.6 tok/s against 23.9 and 23.9; cold prompts 5.99, 23.59 and 47.27 s at 8,192, 32,768 and 65,536 tokens against 5.69, 22.88 and 45.84.
  • Not measured: a BF16-weights reference, other checkpoints with the FP8 cache, TP=1 or TP=3, other GPUs, Metal, explicit FP8 pages (glm cuda: support explicitly paged FP8 KV #3064) and FP8 with host KV (refused).
  • Licence of any new weights or drafter: n/a.

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)
  • 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.

@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Why the FP8 cache is not faster here. A smaller cache would suggest faster prompts and decode, but on this model it cannot be, for three reasons.

  1. The FP8 kernels do no FP8 math. tf_glm_chunks_{16,32}_fp8 convert each key tile back to BF16 in shared memory and then run the BF16 tensor-core math unchanged (zig/kernels/cuda/glm_glue_attn.cuh, common/mla.cuh load_kv). The BF16 path copies its tiles with cp16 (async, overlapped with the previous tile's math). The FP8 path reads its codes a byte at a time and converts and scales them in step, so it adds work and removes none. The write path also takes each 512-wide row's maximum before it quantizes.
  2. Decode reads little of the cache. Only 11 of the 45 layers are DSA layers (34 are KDA, a fixed state), and the indexer gives each row at most 512 pools of 4 tokens (about 2,051 keys), at any context length. So one decode token reads at most about 11 × 2,051 × 1 KiB ≈ 23 MB of latent rows, against more than 2 GB of weights on each rank. Even halved, the cache bytes could save about 0.5% at best, and about 0.05% at the few hundred tokens of the decode rows. The conversion costs more: 23.5 tok/s against 23.9.
  3. Prompts are compute-bound. The tensor-core work is the same, and each query tile converts its key tiles again: hence 3 to 5% slower cold prompts.

What the FP8 cache gives is capacity: about 32% fewer bytes a token, so longer windows or more streams fit. That is all this receipt claims. A follow-up pull request will load the codes in wider units (and asynchronously) to shrink the 3 to 5%, with replies byte for byte unchanged. It cannot make FP8 faster than BF16 here.

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney. The receipt is useful, and its hashes and summary tables check out. It also shows that the FP8 cache changes all three golden replies against the BF16 cache.

We cannot mark a token-changing mode qualified, including an opt-in. Please keep these results as diagnostic evidence and remove the qualification claim from the recipe and ledger; equality within the FP8 mode does not establish equality with the BF16 baseline. The required CI is also still pending at 7286659d47.

  • Synthena (Ash's Agent)

@laudney laudney changed the title docs: GLM FP8 latent cache quality on FP4-Local at TP=2 on two GB10 docs: GLM FP8 latent cache diagnostics on FP4-Local at TP=2 on two GB10 Nov 15, 2026
@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks. Head is now ab075cb2a8, one new commit on top (no force-push):

  • The recipe and the optimization ledger no longer call the FP8 cache qualified. They say it changes tokens against the BF16 cache, so BF16 stays the only qualified cache, and they point to the receipt as diagnostic evidence of how far FP8 moves.
  • The receipt's scope says the same; no number, run or file changes (its SHA256SUMS line for README.md is updated).
  • Title and description updated to match. CI was green on 7286659d47; it runs again on this head.

@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up to the speed comment above: #3454 makes the FP8 chunk kernels prefetch their codes in 8-byte loads, byte-identical rows, cold prompts 4.4 to 4.6% faster from 8k up and 4-stream decode 2 to 4.5% faster. It is independent of this PR; whichever lands second updates the recipe's "cold prompts 3 to 5% slower".

@ashhart

ashhart commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Thanks @laudney for the quick turnaround, and for keeping the push to one new commit so it's easy to follow.

Our earlier asks, at ab075cb2a8:

  • "Please keep these results as diagnostic evidence and remove the qualification claim from the recipe and ledger": met. docs/recipes/glm-5.3-flash-cuda.md:50-55 and docs/optimization-ledger.md:330-334 now say FP8 changes tokens, isn't qualified, and BF16 stays the only qualified cache. The receipt's Scope (docs/receipts/glm-kv-fp8-3a56d4eb/README.md:11-13) says the same.
  • "The required CI is also still pending at 7286659d47": open at the new head. You report it green at 7286659d47, but it is pending at ab075cb2a8.

I checked the receipt's numbers against its data. SHA256SUMS passes. lp/cmp-fp8.json and lp/cmp-nvfp4.json give every fidelity figure in the recipe, the ledger and the README, including the flip margins (8,195, 13,969 and 15,384 of 16,250). tools/summarize.py reproduces the speed, exactness and memory tables. The write-before-attend claim holds at zig/src/families/glm/cuda_dsa_block.zig:170.

Must fix:

  1. "A token's cache about a third smaller" counts the fixed per-stream state as cache. The 8,850 bytes is sp-fp8's "1.08 GiB each at a 131072-token window" divided by 131,072. That 1.08 GiB includes the state each stream holds regardless of length, which the BF16 launch lists separately: sp-bf16/server-rank0.log:28 says "1028 pages of 512 rows (6.40 GiB) … 231 MiB fixed each". The 13,056 it's compared against is the page bytes alone.
    • In the code, a token costs 12 caches × (512 + 4 latent bytes + 64 index bytes) = 6,960 bytes with FP8, against 12 × (1,024 + 64) = 13,056 with BF16, so about 47% less. The row sizes come from zig/src/families/glm/cuda_latent.zig:52, the caches from zig/src/families/glm/cuda_state.zig:111-112, and the recipe's own :82 uses the same 13,056.
    • The logs agree: (1.08 GiB − 231 MiB) / 131,072 ≈ 7,000 bytes, and ex-fp8's 0.49 GiB at 40,960 tokens gives the same rate.
    • The −32% only holds at a 131,072-token window and would change with any other window size.
    • Please restate it at docs/recipes/glm-5.3-flash-cuda.md:55, docs/optimization-ledger.md:332 and the receipt's README.md:99 (and the PR description). Either give the per-token cache (6,960 against 13,056 bytes, plus 231 MiB fixed a stream either way) or give whole-stream figures at a stated window (1.08 GiB against about 1.82 GiB at 131,072 tokens).

Optional:

Once item 1 is in and CI is green at the new head, this has no device check left: it changes docs only, and the receipt's numbers check out against its own data.

  • Synthena (Ash's Agent)

@laudney

laudney commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@ashhart Thanks, you are right. Head is now 65f39f44e6, one new commit on top (no force-push):

  • The 8,850 divided the whole stream's 1.08 GiB, the fixed 231 MiB included, by the window. The recipe (:55), the ledger (:332) and the receipt (README.md:99-101) now give the cache's own bytes: 6,960 a token on each rank against 13,056 (−47%), from cacheBytes and the 12 latent caches, with the 231 MiB fixed a stream stated beside it. The receipt also gives the whole-stream figure at its window (about 1.82 GiB against 1.08 GiB at 131,072 tokens) and the startup-line check ((1.08 GiB − 231 MiB) / 131,072 ≈ 7,000).
  • The PR description's table row matches. SHA256SUMS updated for README.md; it passes.
  • "Cold prompts 3 to 5% slower": agreed, whichever of this and glm cuda: the FP8 latent cache's chunk kernels prefetch their codes in 8-byte loads #3454 lands second updates it.

CI pending at this head.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

@laudney, the qualification claim is gone from the recipe and the ledger, the receipt's scope says the same,
and the bytes figure now states 6,960 against 13,056 a token with the 231 MiB fixed per-stream state named
separately - the way our review required. The numbers check out against the receipt's own data, and the
diagnostics it adds are the useful kind: they show how far the FP8 cache moves, which is what makes the
unqualified state honest.

Nothing to change from us. Once this and the prefetch work have both landed, the recipe's "cold prompts 3 to
5% slower" line is stale and whichever of you lands second updates it - as you both already plan.

No device run is needed for this one: it changes documentation and reaches no inference, and the measurements
behind the rows came from the GB10 pair your receipt documents.

  • Synthena (Ash's Agent)

laudney and others added 4 commits November 16, 2026 14:02
Since 1.1.2 the recipe has said the opt-in --kv-cache fp8 cache's
native quality and device qualification are pending. This receipt
measures both on FP4-Local at main 3a56d4e on two GB10: over
360,418 teacher-forced positions the FP8 cache keeps the mean NLL
within 0.06% of the BF16 cache with a top-20 KL of 0.016, a third of
the 0.043 between NVIDIA's NVFP4 and FP4-Local, a BF16 rerun gives
the same bytes, and drafted, concurrent and resumed replies stay
token-equal. The recipe and ledger lines now cite it; the default
stays BF16.
The FP8 latent cache changes all three golden replies against the
BF16 cache, and a token-changing mode cannot be qualified, even as an
opt-in, so the recipe, the optimization ledger and the receipt's scope
now call the measurements diagnostic evidence of how far FP8 moves and
say BF16 stays the only qualified cache; no number or file changes.
The "about a third smaller" figure divided a whole stream's 1.08 GiB,
231 MiB of fixed per-stream state included, by the window and set it
against the BF16 page bytes alone; the recipe, the ledger and the
receipt now give the cache's own 6,960 bytes a token on each rank
against 13,056 (-47%), from cacheBytes and the 12 latent caches, with
the fixed 231 MiB a stream stated beside it.
@ashhart
ashhart force-pushed the pr-glm-kv-fp8-quality branch from 65f39f4 to 4940985 Compare November 16, 2026 14:02
@ashhart
ashhart merged commit 6bc82ac into ashhart:main Nov 16, 2026
2 of 11 checks passed
@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thank you @laudney. 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.

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