Skip to content

flashnext cuda: opt-in 128-row NVFP4 expert prompt items - #4500

Open
ashhart wants to merge 11 commits into
mainfrom
lead/flashnext-fact-rows-128
Open

ashhart wants to merge 11 commits into
mainfrom
lead/flashnext-fact-rows-128

Conversation

@ashhart

@ashhart ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

What this changes

Flash Next's routed NVFP4 expert prompt kernels split each expert's tokens into 64-row items, so an expert with more tokens in a 2,048- or 8,192-row chunk re-reads (and re-decodes) its weights per item. With TF_FLASHNEXT_FACT_ROWS=128, prompt items are 128 rows (WM=2, RT=4) sharing the staged weight tile across both M-warps; every (row, expert) output keeps the same FACT=true arithmetic. Decode (under 64 rows) is untouched. Default 64. GLM's prefill has the same change in #4493.

Checks

  • Host, lean, CUDA test runner compile and check-release-paths; contract cells compare wide vs current outputs byte for byte (skewed routing, experts over 64 and 128 tokens, empty experts).

Still to run

One GB10: the kernel contract, then pp 8K and 32K A-B-B-A with the following decode tokens compared.

@ashhart
ashhart force-pushed the lead/flashnext-fact-rows-128 branch 2 times, most recently from ddebf83 to 12ca23e Compare November 26, 2026 22:01
@ashhart
ashhart force-pushed the lead/flashnext-fact-rows-128 branch 2 times, most recently from 74ae9d9 to bbad06e Compare November 28, 2026 06:58
@ashhart ashhart added kind:perf Classified by Synthena as performance improvement synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 3, 2026
@ashhart

ashhart commented Dec 3, 2026

Copy link
Copy Markdown
Owner Author

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

Adds an opt-in TF_FLASHNEXT_FACT_ROWS=128 mode that runs NVFP4 expert prompt items at 128 rows (WM=2) so staged weight tiles are shared across two M-warps, with new fact128 kernels, contract records, tests, and docs. Decode and the default 64-row path are unchanged.

  • Failing CI check(s): zig.
  • 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

Findings:

  • [BLOCKER] zig/src/cuda/experts_fact.zig: The FACT128 down entry uses wn=4 (per experts_fact128.zig's wn array) but the kernel is instantiated as TF_NVFP4_FACT128(tf_nvfp4_fact128_down_f32, 1, 0, 4) with launch_bounds(2432)=256 threads, while the legacy down entry used wn=8 (512 threads). The grid math items*((nb+wn-1)/wn) with wn=4 doubles the CTA count per item versus the 8-warp down form, and the contract record for tf_nvfp4_fact128_down_f32 declares dynamic=41984 while the swiglu record declares 51200; if promptSmemWM(parts=1, wm=2, wn=4) does not equal 41984 the launch will fail or silently mis-stage shared memory. Suggested fix: Verify promptSmemWM(1, 2, 4) == 41984 and promptSmemWM(2, 2, 4) == 51200 against the staged layout, and confirm the down kernel's WN=4 instantiation covers all nb column blocks with the same per-CTA column coverage as the WN=8 form; otherwise correct the wn array or the template instantiation.
  • [BLOCKER] zig/src/core/contract/nvfp4_fact128_pending.zig: The contract records hardcode dynamic shared sizes (51200 and 41984) and threads=256, but the test asserts checkCuda returns exactly 5 on every served SM with usage=registry.none; these are unmeasured compiler-resource placeholders, so the contract gate cannot actually pass until real per-SM measurements are supplied, and any mismatch between the hardcoded dynamic values and promptSmemWM's computed launch size would fail at launch time on device. Suggested fix: Compute the dynamic shared size from promptSmemWM at record-construction time (or assert equality with the launch config in a host test) so the registered value cannot drift from the actual launch, and keep the pending measurement gate as-is until the GB10 run supplies real numbers.
  • [WARNING] zig/tests/cuda/nvfp4_fact_tests.zig: The FP64 bound check is skipped for the new 2048/3072/8192-row chunk fixtures, so the large-chunk FACT128 runs are only byte-compared against the decode form (which is itself a GPU kernel) and never independently FP64-bounded at those sizes; a systematic error shared by both wide forms would pass silently. Suggested fix: Either FP64-bound a sampled subset of rows at the large chunk sizes (e.g. every 64th row) or state in the report that chunks 2048+ are byte-equality only; the current report string says 'FP64-bounded through 300 rows' which is accurate but weakens the gate for the new sizes.
  • [WARNING] zig/src/families/flashnext/cuda_nvfp4_tile.zig: When fact_rows==128 the threshold is hardcoded to 64 rather than derived from the fact_rows value, so a future fact_rows=256 or other value would silently fall into the legacy branch (n < fact_rows -> 16, else promptTile 64) instead of widening; the env rule text also only documents 128 as the wide value. Suggested fix: Either restrict the env validation to only {0, 64, 128} (the test suggests 32 is also accepted) or derive the threshold from fact_rows/2 so the branch stays consistent with the configured value.
  • Synthena

@ashhart ashhart added synthena:needs-device Initial diff review passed; waiting for device and slowdown check before READY and removed synthena:needs-receipt Speed PR awaiting verified perf_receipt.py hash run labels Dec 5, 2026
…test

experts_fact.zig's launch takes its threads, shared bytes and grid from shape() and grid(). A host test (test-moetile-host) checks promptSmemWM(1, 2, 4) = 41984 and promptSmemWM(2, 2, 4) = 51200 against Prompt4<M, 4, WM, WN>'s staging as nvfp4_experts.cu declares it, and that decoding every block of items * ceil(nb / wn) the way prompt_body does covers each item's column groups exactly once at wn 4 and 8 (the grid math was right; nothing changed in it).
…ared bytes

A host test (test-moetile-host) finds both pending FACT128 records and requires their threads and dynamic shared bytes to equal what runFact128 launches (Nvfp4Experts.factShape). The records stay pending until their compiler measurements are supplied.
…nd 8192 chunks

The bit-equality checks already cover every row of every chunk; the FP64 bound covered rows through 300 only. It now also samples every 64th row of the large chunks.
Any other row count, the old thresholds among them, is refused at startup by name; the env test checks the three values and refuses 1, 32, 63, 65, 96, 127, 129 and 256. The default (64) is unchanged.
@ashhart
ashhart force-pushed the lead/flashnext-fact-rows-128 branch from bbad06e to 5992d40 Compare December 5, 2026 10:18

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.

1 participant