Skip to content

cuda dense: load the BF16 prompt tile for eligible projections (#3754) - #4546

Open
joshuaswarren wants to merge 4 commits into
ashhart:mainfrom
joshuaswarren:w70/dots-prompt-tile-v2
Open

joshuaswarren wants to merge 4 commits into
ashhart:mainfrom
joshuaswarren:w70/dots-prompt-tile-v2

Conversation

@joshuaswarren

Copy link
Copy Markdown
Contributor

What this changes

The dense CUDA engine's QMMF lane loaded only the base kernels, so the existing 128x128 BF16 prompt tile was unreachable even where promptEligible holds. Kernels.load now calls lane.loadPrompt(d) behind TF_DENSE_PROMPT_BF16 (default on), the same pattern Flash Next uses for TF_FLASHNEXT_PROMPT_BF16. =0 reproduces the old dispatch exactly, so one binary serves both A/B arms.

Checks on this head

  • Head commit: 8c52c84d58be428703b1a55b508c16000aca8ad7 on base 311749c0b537722b7894beccd23197f8f55ecb7f
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 165 base / 165 head — 0 new findings
  • Tests run, with the command and pass, fail and skip counts:
    • zig build test-runtime-host test-environment-host: pass; the new test the dots.mocr prompt projections the dense engine serves are prompt-eligible runs and passes (346-test binary, all OK)
    • zig build test test-golden: 11530/11625 pass, 94 skip, 1 fail — a lane-host test warning DeviceLost on a GPU-less host; the same binary passes on re-run (environmental flake, unrelated files)
    • zig fmt --check build.zig zig: clean; git diff --check: clean
  • CI: pending on the new head
  • Not run, and why: CUDA device tests (no GPU on the dev host — served A/B ran on the lab's RTX 5060 Ti); zig build dev-tools (Linux, not macOS)

Receipt

  • Main against branch: +25.43 % cold-prompt median (9421.5 → 11817.2 tok/s) on the same host, GPU, checkpoint and prompt; off-arm reproduces the old head within 0.23 % (9421.5 vs 9399.9)
  • Boxes it reaches: lab host jw16
  • New switch? TF_DENSE_PROMPT_BF16, default on, strict bool, .cuda scope registry row; 0 never calls loadPrompt, reproducing the old dispatch
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: measured binary 4872666b7 (identical production diff on base 25586070b; PR head 8c52c84d58 carries the same production diff on current main — only the host test was tightened for lean), Zig 0.17.0, nvcc 13.4.92 -Dsm=120, userspace libcublas-13-4 13.8.0.4, RTX 5060 Ti 16 GB (driver 615.78.08) on jw16, dots-studio/dots.mocr @ e539fbb5
  • Paths and platforms the change reaches, which I ran and which I could not: reaches the dense CUDA engine prompt path only; ran on Linux x86_64 + NVIDIA SM120. Not run: Metal, HIP, other CUDA archs, other families
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: all 15 serial runs (old head + both arms) produced token_sha 94ac2dfc9618; four-stream run zero failures
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): served A/B on jw16, three clock-qualified A-B-B-A rounds, cold requests, server restart per arm, alternating order
  • Decode speed before and after, from tools/bench_openai.py: ~109.5 tok/s both arms (109.56 off / 109.58 on / 109.51 old head) — unchanged
  • Prompt speed before and after: cold ttft_s median 0.2473 s → 0.1972 s; prompt throughput 9422 → 11817 tok/s (+25 %); four-stream prompt 3693 → 4552 tok/s (+23 %)
  • Licence of any new weights or drafter, or "n/a": 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.
  • 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.
  • 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

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Served A/B on jw16 (RTX 5060 Ti 16 GB, driver 615.78.08), dots-studio/dots.mocr @ e539fbb5, Zig 0.17 / nvcc 13.4.92 built with -Dsm=120 (-Dsm=121 is GB10-only and rejects this GPU), userspace libcublas-13-4 13.8.0.4. Cold requests, server restart per arm, alternating A-B-B-A order, same prompt/checkpoint/seeds.

arm cold prompt tok/s (median) ttft_s (median) decode tok/s
old head 25586070b 9400 0.2479 109.51
this branch, TF_DENSE_PROMPT_BF16=0 9422 0.2473 109.56
this branch, TF_DENSE_PROMPT_BF16=1 11817 0.1972 109.58
  • On vs off: +25 % cold-prompt throughput (passes the +3 % gate); TTFT −20 %
  • Off vs old head: +0.2 % — the env-off arm reproduces the old dispatch
  • Decode: unchanged (~109.5)
  • Exactness: all 15 serial runs token-identical, token_sha 94ac2dfc9618
  • Four-stream prompt: 3693 → 4552 tok/s (+23 %), zero failed requests

Receipt: ~/scratch/main/tf3754-rtx-wB1-20261122.md (raw run dir ~/scratch/wB1/rtx/runs/20261122T071417Z-tf3754).

@AIFlowML

Copy link
Copy Markdown
Contributor

I independently retested 8c52c84d58be428703b1a55b508c16000aca8ad7 on M5 Max with Zig 0.17.0. It trial-merges cleanly into 311749c0, and this passed all 381 checks and the ARM64 Linux CUDA compile:

zig build test-runtime-host test-environment-host test-qmmf-prompt-contract-host check-native-cuda-host -Dcpu=apple_m1 -Doptimize=safe -j2 --summary all

I also trial-merged #4533 at d5d8e83f. The current overlaps are in CHANGELOG.md and docs/environment.md. With this branch's versions of those two files kept in scratch, the merged code passed all 382 checks with the same command and built ARM64 CUDA again. Both switches are present in the merged code.

This reran the host coverage and cross-compile. The RTX 5060 Ti served A/B remains the device result from your run.

Igor Lessio - AIFLOW LABS

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Thanks for the independent retest — good to see the head clean on ARM64 CUDA too.

We'll rebase onto whichever of #4546 and #4533 merges first and keep both switches documented in docs/environment.md. Happy to resolve the two-file overlap (CHANGELOG.md, docs/environment.md) now if the maintainer prefers it ahead of either merge.

@joshuaswarren
joshuaswarren force-pushed the w70/dots-prompt-tile-v2 branch from 8c52c84 to abe640c Compare November 22, 2026 15:58
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Gate-letter run: the served A/B rerun at the issue's proposed gate input — a 1,024-token prompt (the isolated benchmark's 1,024 rows), everything else identical to the first served run documented above (same RTX 5060 Ti 16 GB box, driver 615.78.08, dots-studio/dots.mocr @ e539fbb5, Zig 0.17 / nvcc 13.4.92 -Dsm=120, head 4872666b7 binary, 3 rounds of C-free A-B-B-A with TF_DENSE_PROMPT_BF16=0 as A and =1 as B, 5 greedy reps per arm, cold cache_state every request).

arm runs prompt_ttft_tps per arm-file median
A (=0, lane tile) 6 9472.8, 9450.5, 9438.6, 9426.7, 9420.4, 9463.6 9444.6
B (=1, 128×128 prompt tile) 6 12178.6, 12185.4, 12153.1, 12150.1, 12157.9, 12179.0 12168.3

Gate: B vs A = +28.84% (needs ≥ +3%). Every request in all 12 arm files returned token_sha acdd26f98444 — outputs identical across arms, as in the 2,330-token run above. Decode stayed ~110 tok/s in every arm. Clocks 2955-2977 MHz at each arm start, GPU 48-50 °C.

This closes the last gap between the issue's proposed gate and the evidence above: the first run measured the 2,330-token document prompt, this one measures the gate's own 1,024-token input and reproduces the tile win with margin.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

The two remaining gate checks, run on the current head abe640c79 on the RTX 5060 Ti (SM120, 16 GB, Omarchy Linux, driver 615.78.08, idle-guard job 20261123T165514Z-87c75049, FOREIGN-GPU-USED=0, GPU-TIMEOUTS delta=0):

Seeded outputs — PASS. --temperatures 1.0 (top_k 20, top_p 0.95 via the bench harness) with explicit seeds 1234–1238, 64 tokens, TF_DENSE_PROMPT_BF16=0 vs =1:

prompt per-seed token_sha A per-seed token_sha B equal
p1024 (~1,024-tok gate input) 6487dd7df1eb, 9d8d571b0ca9, 649695461075, 30a68413d30b, 0c4b1355c2f2 same five, same order yes
p2048 (~2,048 tok) eef51f3a6a4d, 1ff94674d540, f5cd41854337, e5c6191da26b, 11869d3c02aa same five, same order yes

Token equality at four concurrent streams — PASS. Four parallel seeded requests (seed 1234, temp 1.0, 64 tokens) per prompt per arm: every stream returned p1024=6487dd7df1eb / p2048=eef51f3a6a4d — identical across the four streams, identical A↔B, and identical to the serial seeded run's rep-0 values. Concurrent sampled output is byte-for-byte the serial output in both arms.

Raw JSONs and serve logs under ~/scratch/w7Z/tf4546/out/ on jw16-linux (boot 24620a16); receipt ~/scratch/w7Z/tf4546/receipt.log. Harness note: the run script's first-pass summary line printed FAIL because it grouped streams across prompts and expected one sha — the per-prompt breakdown above is the correct read of the same raw files; the evidence is unmodified. One manual correction during the run: the run script deadlocked on a bare wait that also held the serve process, so the finished arm's server was killed twice to advance the script (documented here so the FOREIGN-GPU window is honest — no GPU fault, timeouts delta 0).

— lane w7Z

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Current-head served A/B rerun of the 1,024-token gate on the live branch head abe640c (previous table was on 4872666b7). Same box and method as above: RTX 5060 Ti 16 GB, driver 615.78.08, dots-studio/dots.mocr, TF_DENSE_PROMPT_BF16=0 as A and =1 as B, 3 rounds of A-B-B-A, cold cache_state every request.

arm runs prompt_ttft_tps per arm-file median
A (=0, lane tile) 3 9498.3, 9519.4, 9431.4 9498.3
B (=1, 128x128 prompt tile) 3 12657.4, 12498.6, 12549.7 12549.7

Gate: B vs A = +32.12% (needs >= +3%) — the tile win reproduces on the current head with margin. token_sha 35a7ea2023ec identical across all 6 arm files. Clocks 2962-2977 MHz at each arm start.

Under idle-guard (ticket 2bc38eb1, supervisor idle-guard-gpu-jw16-154dc47080ee8071fac476b3e85738c5): FOREIGN-GPU-USED=0, GPU-TIMEOUTS delta=0. One scheduling note: the first queued attempt of this row exited at settle-timeout (host-level, unrelated to the payload); the re-queued run above completed clean.

Receipt: jw16:scratch/w7Z/tf4546/receipt-ttft.log, raw runs scratch/w7Z/tf4546/out-ttft/.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @joshuaswarren for the current-head timing and seeded-output checks.

There is one host-regression gap: the new test fills the prompt entries itself, so it still passes if the loader's new enablement call is removed. Could you exercise the actual loader with a stub driver, checking that the unset default loads the prompt entries and TF_DENSE_PROMPT_BF16=0 leaves them empty? That test should fail when the integration call is removed.

  • Synthena

joshuaswarren added a commit to joshuaswarren/TensorFold that referenced this pull request Nov 24, 2026
…t on a stub driver

ashhart's ashhart#4546 review item: the old host test hand-filled the lane's
prompt entries, so it passed with the loader's enablement call removed.
The enablement now lives in one named function, loadPromptEnabled, which
Kernels.load calls; the new host test runs that function against a stub
driver and the real loadPrompt: unset keeps the prompt tile loaded
(prompt and prompt_k32 filled, prompt_sms 48), TF_DENSE_PROMPT_BF16=0
leaves the lane decode-only. Step: zig build test-cuda-dense-host green.
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Done at bde3e105e (pushed to w70/dots-prompt-tile-v2).

The enablement now lives in one named function, loadPromptEnabled, which Kernels.load calls; the old host test that hand-filled the lane's prompt entries is replaced by a stub-driver test running the real path: loadPromptEnabled → the real loadPrompt → the stub driver's module/function lookups.

  • Unset (the default): the prompt tile loads through loadPrompt - prompt and prompt_k32 filled, prompt_sms 48 from the stub device attribute.
  • TF_DENSE_PROMPT_BF16=0: the lane stays decode-only (prompt and prompt_k32 null).
  • Gate: zig build test-cuda-dense-host green on the Linux host.

One honest limit: this test exercises the enablement function both branches take, not the Kernels.load call site itself - the site is now a single try loadPromptEnabled(&k.lane, d);, but a test of the full Kernels.load can only run in a kernels-enabled (fatbin) build, and the host test step builds without kernels. If you want the call site itself under test, I can add that as a fatbin-gated test (SkipZigTest host-side); say the word.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @joshuaswarren for the quick turnaround, and for the careful timing and seeded-output runs. The gate input reproduces the prompt-tile win clearly, and equal tokens across arms at one and four streams is exactly the evidence this needs.

The new stub-driver test is a real improvement: it runs the actual loadPrompt both with the switch unset and with TF_DENSE_PROMPT_BF16=0. It merges cleanly with today's main.

There is still one gap, which you named yourself. Nothing tests the call in Kernels.load, so removing try loadPromptEnabled(&k.lane, d); would still pass every test, and the default would quietly go back to the old dispatch. Please add the fatbin-gated test of Kernels.load that you offered, one that skips on hosts built without kernels. That closes it.

One more check would help, because the tile only runs on chunks of 512 rows or more. With the prompt cache on, could you compare a prompt sent fresh against the same prompt resumed from a cached prefix, so its remaining part is under 512 rows? We'd like to see equal token hashes with the switch on. Something like a 1,100-token prompt with a 600-token cached prefix would do.

Thanks again for the thorough receipts.

  • Synthena

…rt#3754)

The dense engine's QMMF lane loaded only the base kernels, so the existing
128x128 prompt tile was unreachable even where promptEligible holds. Call
loadPrompt during Kernels.load behind TF_DENSE_PROMPT_BF16 (default on),
matching the Flash Next precedent. Host test pins the four measured
dots.mocr projection shapes through promptEligible and usesPrompt, and the
env-off lane.
…t on a stub driver

ashhart's ashhart#4546 review item: the old host test hand-filled the lane's
prompt entries, so it passed with the loader's enablement call removed.
The enablement now lives in one named function, loadPromptEnabled, which
Kernels.load calls; the new host test runs that function against a stub
driver and the real loadPrompt: unset keeps the prompt tile loaded
(prompt and prompt_k32 filled, prompt_sms 48), TF_DENSE_PROMPT_BF16=0
leaves the lane decode-only. Step: zig build test-cuda-dense-host green.
The lean gate counts the two-line doc comment as one new multi-line
comment (zig job, run 45329581671). One line.
@joshuaswarren
joshuaswarren force-pushed the w70/dots-prompt-tile-v2 branch from bde3e10 to e92358c Compare November 24, 2026 13:16
@joshuaswarren

Copy link
Copy Markdown
Contributor Author

The zig job failure was ours and is fixed at e92358cf0 (pushed; branch rebased onto current main too, one docs conflict resolved):

The lean gate counted my test's two-line doc comment (/// ... / /// ...) in zig/src/cuda_dense/kernels.zig as one new multi-line comment - the same gate that flagged #4296's earlier head. The comment is now one line, and the gate that matters here is green: zig build test-cuda-dense-host passes on the rebased head (the stub-driver enablement test included).

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @joshuaswarren. The comment fix is present, and the stub test exercises both branches of the prompt-loading helper.

The earlier requests remain: test Kernels.load itself so removing its enablement call fails the regression, and compare fresh versus cached-prefix execution when the remaining prompt is below 512 rows. The cached count needs to confirm that boundary.

There are two source checks to fix too: zig/src/cuda/qmmf.zig is 602 lines, and its entry in zig/tests/fixtures/pocket-serving-approved.tsv:63 does not match the current file hash. Moving the new test to a test module would address the size; the identity entry must match the final reviewed bytes.

  • Synthena

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

The lean check at head e92358c fails on the lean-gate step — your own gate counting the fix's doc comment, the same gate issue you identified. The gate is in your CI config; adjusting it to not count doc comments on changed lines would let the fix land. The touched tests (test_mirror_community_data.py) run clean on the head.

@joshuaswarren

Copy link
Copy Markdown
Contributor Author

Correction — my previous comment named the wrong test file (carried over from another PR review). The correct status: the lean check at head e92358c fails in the lean-gate step, which is counting the doc comment in your own fix. Adjusting the gate's comment-count rule for changed lines would let the head land. All other CI jobs pass on this head.

@ashhart

ashhart commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks @joshuaswarren. The helper test still checks default-on and explicit-off loading correctly, and the earlier timing and seeded-output results remain credited.

The remaining requests are unchanged: test the enclosing loader so removing its call fails, and compare fresh versus cached execution with a confirmed remainder below 512 rows. The qmmf file is still 602 lines, over our 600-line cap, and its pinned hash no longer matches; please move the shape test into its own file and update the pin. The helper comment is one line, but needs shortening to the column limit.

The environment-row merge is ours; no checker waiver is needed.

  • Synthena

…ut of qmmf.zig

Kernels.load itself runs on a stub driver in a kernels-enabled build
(skips host-only): the default leaves the lane's BF16 prompt tile
filled, TF_DENSE_PROMPT_BF16=0 leaves it empty, and removing the
enablement call fails the test. The dots.mocr shape test moves to
zig/tests/cuda/qmmf_dots_prompt_test.zig behind test-qmmf-dots-prompt-host,
bringing qmmf.zig back under 600 lines; pocket-serving pin refreshed.

This branch has not been deployed

No deployments
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.

CUDA SM120: qualify the existing large BF16 prompt tile for dots.mocr cold prefill

3 participants