Skip to content

EXL3 Flash Next: deep prefill (3/8) - #1443

Open
BlivionIaG wants to merge 53 commits into
ashhart:mainfrom
BlivionIaG:pr/exl3-s3-deep-prefill
Open

BlivionIaG wants to merge 53 commits into
ashhart:mainfrom
BlivionIaG:pr/exl3-s3-deep-prefill

Conversation

@BlivionIaG

@BlivionIaG BlivionIaG commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Current head: 407211da3c, merged through #1442 f8bb280b12 with main baed910096 and moving the EXL3 notes back to Unreleased. The exact-head TP1 prefill checks below passed; earlier TP2, speed and kernel-contract measurements were not repeated on this head. An earlier Linux Zig CI job was canceled during zig build test-kernel-contract after about an hour, matching its then-60-minute job limit; it was not a passing result.

Current-head tools/pr_check.py --base upstream/main --pr 1443: 0 errors, 0 warnings, 0 new lean findings.

Exact-head TP1 prefill gate

On 407211da3c, all 45 resume cuts and all 15 mixed deep/shallow segmentation cases matched fresh or serial execution in logits bytes and 24 greedy tokens. Settings and scope. TP2, server-cache resume and independent model-fidelity gates remain separate.

What this changes

Segmented deep EXL3 prefill with TP prefill partials in float64, and prompt-state restore at any row (the snapshot grid is gone).

Checks before the release merge

  • Head f654c5b60d. The device results below ran on 40e3a6ceb16e; this head differs from it by the merges of main at 0591c4e85d, c34ff562ca, a3aecd8d0f and 484437b6ac (cuda_batch_moe.zig: this branch's writeback and main's sumSlots both kept) and the pin fixture gradient-serving.tsv. The device cells were not repeated on this head.
  • python3 tools/pr_check.py --base <main> --pr 1443: exit 0, 0 errors, 0 warnings; lean 339 vs 341 on main, 0 new. zig fmt --check zig: clean.
  • Host tests: test-cuda-host, test-exl3-cuda-host, test-flashnext-exl3-host, test-exl3-prompt-host, compile-flashnext-host, test-flashnext-memory-host, test-qwen-serving-host, test-lane-api-host and test-lanes-see passed on an earlier integrated EXL3 Flash Next: draft lane guard for offloaded experts (8/8) #1446 head on Darwin arm64; the full list was not rerun on this head.
  • Linux x86_64 CUDA cross-build exited 0 on an earlier integrated EXL3 Flash Next: draft lane guard for offloaded experts (8/8) #1446 head (build only).
  • CI: see the checks on this PR.

Device results on 40e3a6ceb16e

Two 16 GB sm_120 GPUs, Linux x86_64, checkpoint above. One run per cell unless stated.

Cell Result
Deep prefill against the batched pass fast-equal, fast-resume (45 kept states bit-equal), fast-mixed and the TP prefill cells pass at TP=1 and TP=2; TP=2 deep equals TP=1 deep, bit for bit
REDUCED_BRANCH, TWO_CHUNK change neither tokens nor speed
Prompt time, deep against batched 3001 tokens 5.9 s against 37.7 s at TP=1 and 3.4 s against 20.9 s at TP=2; 12001 tokens 17.6 s at TP=1 and 11.8 s at TP=2
First token, cold 6144-token prompt, deep prefill off against on 76 to 81 s against 7.8 s repeated (14.5 s for the first request after start); token hashes identical in every request; decode unchanged at 1 and 4 streams
kernel-contract exl3 flashnext (filtered) 96/96 kernels pass gates 1-4, 43/43 controls red, 137 limit problems (the same set as #1441)

Not run or open

  • Main against this head (main refuses this checkpoint).

Receipt

  • Boxes it reaches: deep prefill and prompt-state restore, TP prefill.
  • New switch: none.
  • Environment: Zig 0.17.0. Host checks on Darwin arm64. Device runs on Linux x86_64 with two 16 GB sm_120 GPUs. Checkpoint turboderp/Qwen3.8-Flash-Next-exl3 at 69e33439ae950f17bcbe95c98f117d80f759ab6d.
  • Kernel contract: This PR adds or changes kernels: flashnext_exl3_prefill.cu (+425), exl3_candidate.cu (+114), contract_tppf_controls.cuh (+275, new), contract_controls.cu (+3). The filtered contract above covers them.
  • Model fidelity, measured on an older head and not repeated: native against an independent reference, 70/72 top tokens; the two differences are teacher-forced ids 16 (step 11) and 17, native margins 0.25 and 0.5 against reference 0.125 and 0.25. No tie waiver and no perfect-equivalence claim.
  • Licence of new weights or drafter: n/a (Qwen Community License 1.0 on the checkpoint; no weights distributed, no new drafter).

Profile setting check

The final head has one TF_FLASHNEXT_PROFILE registration in zig/src/platform/environment.zig, the same entry as main. The EXL3 prefill and main paths read that shared setting; this slice adds no second registration, environment-table doc line or valid-case test.

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. The subsequent Linux Zig CI run passed; device results and failures are listed above. The new tests were not run against the parent.
  • Comments and docstrings are one line. No measurements or history in the source. Lean check (one-line comments within 120 columns): 0 new problems. I scanned every added comment line in the stack for measured results and history wording; the hits are worked examples and limits, not recorded results.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines. Scanned every added line in the stack diff and every commit message for host and user names, addresses, local paths, AI trailers and tool names: none. No binary files are added. Receipts are not in the repository.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. No direct demonstration. The concurrent and drafted device cells run through the lane rounds.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Resumed equals fresh: 45 kept states bit-equal; token hashes identical across the first-token runs. Concurrent equals solo and drafted equals "draft": false were not run for this PR on its own.
  • No precision traded for speed. If the bits change, the description says which sums change and why. TP prefill partials are summed in float64 with one rounding to float32 at the finish, so the TP=2 sum equals the TP=1 sum; shown bit for bit on device (TP=2 deep equals TP=1 deep).
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. Prompt processing is faster (cells above); decode is unchanged at 1 and 4 streams. Main refuses this checkpoint (n/a).

@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s3-deep-prefill branch 3 times, most recently from a23cd77 to 0b8304d Compare October 27, 2026 10:51
@ashhart

ashhart commented Oct 27, 2026

Copy link
Copy Markdown
Owner

The prefill speedup is impressive: the 16k-token prompt goes from 56 s to 10.5 s. The blocker is arithmetic.

The deep path is on by default for segments of 512 rows or more (exl3/prefill/cuda_exl3_prefill_state.zig:22,28;
cuda_exl3_prefill.zig:211-212). It runs dense projections of 64 rows or more on #806's candidate tiles
(cuda_exl3_prefill_tiles.zig:10-14) and experts on the new 64-member tiles, while decode and shorter segments use
Linear.matmul and runSlots. The docs prompt's hash moving from 1882ea29ebf6 to e6834625432c shows the
arithmetic changed.

Keeping cache states on the step grid (snap_grid) is a careful way to make resumes match fresh runs. Even so, a
prompt's tokens now depend on the step size and on whether the deep buffers could be reserved. When they can't, at
startup (cuda_exl3_prefill.zig:79) or at request time (:267), the batched pass takes over. Prompt rows also no
longer match serial decode, which is our oracle.

To land:

  • The prompt kernels need to produce the decode kernels' bytes for every row, whatever the chunk or segment length.
    Main's NVFP4 Flash Next prompt tiles do this; see the coverage section of docs/kernel-contract.md.
  • Register tf_exl3pf_gu and tf_exl3pf_down with replaces against the decode kernels, so the contract checks the
    bytes.
  • Add a test that shows the same tokens with deep prefill on and off, and at two step sizes.

Once prompt rows match decode, the grid is no longer needed for exactness.

The ring, overlap and prefetch work can stay as it is.

@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s3-deep-prefill branch 4 times, most recently from 3011ec2 to 8f85bfb Compare October 27, 2026 17:56
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s3-deep-prefill branch from 8f85bfb to 5207d74 Compare October 27, 2026 20:27
@BlivionIaG BlivionIaG changed the title EXL3 Flash Next: deep prefill (3/7) EXL3 Flash Next: deep prefill (3/8) Oct 27, 2026
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s3-deep-prefill branch 9 times, most recently from 4d106ad to 505a649 Compare October 29, 2026 13:04
@BlivionIaG
BlivionIaG force-pushed the pr/exl3-s3-deep-prefill branch 7 times, most recently from 6ff3191 to e3788fc Compare November 2, 2026 17:08
@ashhart
ashhart force-pushed the pr/exl3-s3-deep-prefill branch from 33946ec to c428f4c Compare November 22, 2026 05:46
@AIFlowML

Copy link
Copy Markdown
Contributor

Rechecked c428f4cd2e736f0a67a1be0bb40a2e7222023432 in a clean trial merge into 34af03a12. The CUDA 13.4 prompt-2 registry entry is present, and the EXL3, contract and native CUDA compile targets passed. Three environment assertions still fail on the revised branch.

zig build test-environment-host test-flashnext-exl3-host test-gradient-serving test-kernel-contract check-native-cuda-host -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all completed on M5 Max after I removed the duplicate TENSORFOLD_MEMORY_RESERVE_GIB rule and aligned the three raw-parser fixtures with main. The environment suite passed all 35 checks. zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dcpu=baseline -Doptimize=ReleaseSafe -j2 --summary all also compiled the CUDA test runner in that scratch tree.

I also confirmed the earlier scratch-row finding on Linux x86-64 with Zig 0.17.0 ReleaseSafe: the current arithmetic panics in an isolated n=1023 test, while BlivionIaG's bounded calculation from e633d2d90 returns 512. Applying that calculation here, with the registry cleanup, passed all 147 EXL3 host checks and the native CUDA compile. This is host arithmetic and compile evidence. The drafted restore workloads on the GB10s remain separate.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Thanks @BlivionIaG. The four runtime/offload fixes noted on #1442 also apply here: honor host placement for disk-resumed snapshots, count routed MTP trellises as device-resident when TF_FLASHNEXT_EXL3_MTP_RESIDENT=1, retain decoder placement history across MTP residency changes, and make both u32 pool round counters wrap at their 2^32 boundary with a regression.

The two shared serving gates also need nonzero failure exits. Include both golden comparisons in the serving gate's status; make that gate and the long-context needle gate fail by exit status whenever their required checks fail.

The TP prefill gate can separately pass a token mismatch: its non-exact comparison accepts a low reference margin, and the TP2-deep versus TP1-deep call selects that mode. Your FP64 change states that TP1 and TP2 give the same bits. Please pass true for that comparison in exl3_tpprefill_tests.zig, so the existing exact branch checks both logits bytes and every greedy token.

Finally, carry over the #1442 admission-test correction for chunk values 0, 16385 and 4k: centralized environment validation returns InvalidEnvironment, not BadChunk. The runtime refusal is already correct; only those three expectations are stale. Add focused host regressions, rerun the real-rank TP1/TP2 comparison, and preserve the earlier TP/MTP fixes in the rebase.

  • Synthena

@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner

Synthena Initial Review — Performance receipt required (kind:perf)

Diff exceeds GitHub's 20,000-line diff API limit (+31606/-538 across 100 files); escalated for manual maintainer review or splitting.

  • Branch currently has merge conflicts against base.
  • Failing CI check(s): zig, zig-b, zig-windows.
  • Performance claim detected without a verified tf-receipt-v1 receipt.

Performance PRs require a verifiable benchmark receipt before running project CI hardware. See CONTRIBUTING.md (Performance PRs: verifiable benchmark receipt) and attach the output of:

python3 tools/perf_receipt.py run --base-bin /path/to/base-tf --head-bin /path/to/head-tf --model /path/to/model.tfold --out receipt.json
  • Synthena

…pping

- `now` and `round_no` are u32 stamps that order lines and swaps; a long-running server wrapped them into an overflow trap
- test: from maxInt they step to 0 then 1 (trapped with integer overflow before)
…P_HOST puts kept states

- the disk view allocates through snap.blank, which honors the host placement instead of always taking device memory
- test: with TF_FLASHNEXT_SNAP_HOST=1 a read-back state sits on the host (it sat on the device before)
…loader keeps

- headOptions reads TF_FLASHNEXT_EXL3_MTP_RESIDENT once; headBytes and the loader's mtp. roots both use it
- test: a synthetic pack with the switch set counts the head's routed bytes (they were missing before)
… history

- a profile written with or without MTP counts keeps the decoder counts; only MTP starts cold, and the fingerprint marks the head
- test: prepare/finish across a residency change keep decoder counts (they were discarded before)
- the serve gate's status includes the golden check and exits 1 on failure; the long-context client exits 1 on a missed needle
- tests/test_exl3_gates.py fails on the old scripts (2 failures) and passes now
…ather

- drop the duplicate TENSORFOLD_MEMORY_RESERVE_GIB rule; the EXL3 consumer applies its own 0.5 GiB floor
- legacy fixtures: an untrimmed reserve and a zero CHUNK_SOLO follow main; a refused TF_FLASHNEXT_CHUNK ends in InvalidEnvironment
- the pooled-gather order test reads cuda_batch_gather.zig, where Gather.main moved
…margins

- compare always requires identical last-row logits bytes and greedy ids; the top-1 margin tolerance is gone
@BlivionIaG

Copy link
Copy Markdown
Contributor Author

Pushed 7233cd50f9 (fast-forward from c428f4cd2e).

  • TP prefill gate (e03138cbdd): compare in exl3_tpprefill_tests.zig now always requires identical last-row logits bytes and identical greedy ids, including for "tp=2 deep vs tp=1 deep". The margin tolerance and the exact parameter are removed. This is a device test, so here it is only compile-checked. It was not run on a GPU.
  • Admission chunk expectations (a82efee92e): for TF_FLASHNEXT_CHUNK values 0, 16385 and 4k, the test now expects error.InvalidEnvironment (the table refuses them at startup), as EXL3 Flash Next: expert-parallel TP=2 (same tokens as TP=1) and MTP drafts (2/8) #1442 already does. On c428f4cd2e the test failed with expected error.BadChunk, found error.InvalidEnvironment.
  • Environment table and moved gather (same commit): dropped the branch's duplicate TENSORFOLD_MEMORY_RESERVE_GIB row, and aligned the untrimmed-reserve and zero CHUNK_SOLO fixtures with main. The pooled-gather order test now reads cuda_batch_gather.zig, where Gather.main moved. Both were failing on the head.
  • Carried from EXL3 Flash Next: expert-parallel TP=2 (same tokens as TP=1) and MTP drafts (2/8) #1442, same changes and tests: pool counter wrap (591f20203c), disk-resumed placement (88fffba0a9), MTP resident admission (a80c6b1d05), placement history across MTP residency (aac93d34dd), gate exit codes and tools/tests/test_exl3_gates.py (d0d0c6fda8), contract set errdefer (7233cd50f9).

Commands run on macOS arm64 with Zig 0.17.0:

  • Before, on c428f4cd2e, zig build test-cuda-host: 731/736 tests passed, 5 failed (3 environment, the chunk admission test, the gather order test)
  • After, zig build test-flashnext-exl3-host test-environment-host test-cuda-host: 474/474 steps succeeded, exit 0
  • zig build check-native-cuda-host -Dtarget=aarch64-linux-gnu -Dcpu=baseline: 9/9 steps
  • zig build compile-cuda-tests -Dtarget=aarch64-linux-gnu -Dcpu=baseline: 10/10 steps
  • python3 -m unittest tools/tests/test_exl3_gates.py: OK
  • pr_check --base upstream/main --pr 1443: 0 errors, lean 165 vs 165. One warning: no Unreleased bullet.

Not done: no CUDA device here. The exact TP2-vs-TP1 deep prefill gate still needs a run on two GPUs.

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

kind:perf Classified by Synthena as performance improvement synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants