Skip to content

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

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

BlivionIaG wants to merge 45 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
BlivionIaG and others added 28 commits November 22, 2026 05:43
Use the family offload attachment before the shared one-layer oracle forwards, retaining its existing FP64 gates and layer ownership.
Migrate the shared real-weight layer oracle to the MTP-aware signature introduced by this slice.
Real sm_120 checkpoint proof on 2806f61: all 45 cold/resumed states equal fresh logits bytes and24greedy IDs at512/1024/2048 steps. Remove the option, environment rule, loaded-grid override, helper and obsolete grid-only tests. Preserve other families static cache grids.
…to f32 at the finish

tf_exl3pf_tp_combine stores each rank's block value in double (the shared
fn_exl3_leaf_value_f64 of the decode kernels), the all-gather carries the
doubles, and tf_exl3pf_tp_finish merges them in double and rounds once to
float. A lone rank goes through the same finish, so TP1 and TP2 give the same
bits. The prefill scratch holds the doubles (rows x 2560 x 8 a partial).

The CPU leaf oracle and the TP prefill contract (fixtures, controls, host
gates) follow: partials and the finish's inputs are f64 words, two new
controls (f32 partials in the combine and in the finish), and regressions for
the cancelling products an f32 tree or an f32 transit rounds away. The
combine and finish's f32 nvcc receipts are dropped until the f64 kernels are
measured.
The two-rank EXL3 exchange keeps each rank's subtree partials as 8-byte doubles: the gather buffer, per-rank offsets and the finish's stride count doubles, the all-gather is a typed FP64 NCCL copy (no rounding or reduction), and the root output stays f32. Adds the family collective's gatherF64 and bit-exact transport and partition regressions.
Leaves and the binary tree accumulate in double through one shared device
helper (fn_exl3_leaf_value_f64). fn_exl3_leaf_tree rounds once to float;
the new fn_exl3_leaf_partial stores the double value and fn_exl3_leaf_finish
merges double partials, so a rank split cannot reintroduce f32 roundings.
Host exl3_canon.subtree/finish are f64; the contract adds an f64 accumulator
kind, f64 partial/finish fixtures, f32-partial controls and the f32
cancellation regression (old tree 0, slot chain 1, exact 2). The reduction's
nvcc 13.4 receipts are pending until the f64 kernels are measured.
Admit window, MTP head and decode captures only when their pass has no host-planned expert pool; keep resident and rollback graphs available.
Recompute the actual merged-file pins for the 19 intentional ashhart#1441 serving source changes; no source or approved-list change.
@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

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.

3 participants