Repository navigation
perf(flash next cuda): read a prompt pass's n-gram rows before waiting on the previous step's copies - #201
Closed
mcclanahanaman wants to merge 1 commit into
Closed
perf(flash next cuda): read a prompt pass's n-gram rows before waiting on the previous step's copies#201mcclanahanaman wants to merge 1 commit into
mcclanahanaman wants to merge 1 commit into
Conversation
…g on the previous step's copies stage() waited on the pinned staging buffers (the event the previous step records once its copies out of them have run) and only then gathered the pass's n-gram rows from the memory-mapped table. The GPU therefore idled through the gather after every prompt pass, and longer once the kernel had evicted table pages: an NVFP4 table is mapped and never locked (NVFP4Table.lock returns False; other tables lock only when the startup budget has room), and the memory gate counts its pages as reclaimable. The rows are now gathered first and copied into the pinned buffers after the wait, so the table's page faults overlap the previous step's GPU work. The same rows reach the same buffers in the same order: prompts, decode and kept states keep their bits. EXL3 packs keep their order (stage_ple reads into the pinned buffers directly). TF_FLASH_STAGE_AHEAD=0 restores the old order. Jetson AGX Thor, 0.6.0 with this change, local-inference-lab Qwen3.8-Flash-Next-NVFP4 rev 7c4f1bc1, --kv-dtype int8 --parallel 4, the same prompts in one process with the switch on and off (tok/s, cold prefill): natural text 32k with the n-gram table dropped from the page cache 857 vs 773 (+10.8%); warm 868 vs 862; synthetic 8k / 32k / 128k 923 / 890 / 792 vs 903 / 889 / 789; head logits identical on every prompt; greedy decode 66.57 vs 66.55 tok/s with the same ids. tests/cuda/test_flashnext_nvfp4_loader.py: 26 passed, among them a new check that both orders stage the same rows and give the same tokens and streams. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01PRwDEapgChAWSk1ncJ62Yk
Closed
Owner
|
Thank you, @mcclanahanaman. Gathering a prompt pass's n-gram rows before waiting on the previous copies is in TensorFold 0.6.4, exactly as your commit and under your name: https://github.com/ashhart/TensorFold/releases/tag/v0.6.4 On a DGX Spark the combined Flash Next stack (#202, #201, #254, #248, #268) matched one-token decoding in 12 of 12 cells, with prompt speed at parity. Thank you for the careful work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch:
perf/flash-next-stage-ahead(one commit, da6caed, onv0.6.0, c464617)TL;DR: Flash Next's
stage()waited for the previous step's copies out of the pinned staging buffers, and only then gathered the pass's n-gram (PLE) rows from the memory-mapped table. The GPU idled through that gather after every prompt pass, and longer when table pages had been evicted. The rows are now gathered before the wait and copied into the buffers after it, so the gather overlaps the previous step's GPU work. The same rows reach the same buffers, so prompts, decode and kept states keep their bits.The problem
stage()calledb.staged.synchronize()first. That event is recorded after the previous step's copies out of the pinned buffers. Only then did it gather each layer's n-gram rows (p.table.gather(ids)) and copy them in.NVFP4Table.lock()returnsFalse), and the memory gate counts its pages as reclaimable.The change
stage()collects the pass's lookups (layer, row ids, first staging row) and gathers the rows for all layers before the wait.stage_ple_rowstakes the already-gathered rows (got=). Without them it gathers them itself, as before.stage_plereads into the pinned buffers directly.TF_FLASH_STAGE_AHEAD=0restores the old order.Measurements
Jetson AGX Thor, one container session (
up-u2). Upstream 0.6.0 plus this commit,local-inference-lab/Qwen3.8-Flash-Next-NVFP4rev7c4f1bc1,--kv-dtype int8 --parallel 4. The engine reads the switch at eachstage(), so both orders run in one process on the same prompts. Cold prefill wall time, every request counted:TF_FLASH_STAGE_AHEAD=0(before)The decode row is in-process greedy decode with MTP drafts, not a served-request metric. The first decode with stage-ahead on was 58.11 tok/s. The median drops it. The other five runs are 66.50-66.59 tok/s with the same ids.
The prefill cells are single runs; a gain under about 1% is within run-to-run noise.
The cold row drops the table's pages before the prompt. The log records
madvise(MADV_DONTNEED)(madvise_rc0) and resident pages falling to about 0. That is what a long-running server sees once other memory has pushed the table out.Tests
tests/cuda/test_flashnext_nvfp4_loader.py::test_stage_reads_the_ngram_rows_ahead_with_the_same_bits. With the switch on and off, a prompt in passes of 16 and then 5 rows gives the same first token, staged rows, streams and decoded tokens.up-u1):test_flashnext_nvfp4_loader.py26 passed (including the new test);test_flashnext_forward.pyplustest_flashnext_multi.py79 passed, 2 failed. The measurement session (up-u2) did not re-run those full files.test_flashnext_multi.py::test_packed_passes_keep_each_prompt_one_token_early[bf16]and[int8]. In the measurement session, the same two tests with 0.6.0'sforward.pyfailed the same assertion: stream 4's output is[2033, 2685, 530, 0]andserial_decodecontinues[2033, 2685, 530, 0, 979, ...].The commit also applies cleanly to the 0.6.1 branch (
pr-141-0.6.1):git cherry-pickmergesforward.pyand the loader test without conflicts. It was not tested there.AI disclosure: an AI coding agent (Claude Code) wrote this change and ran the measurements on my Jetson AGX Thor. I approved posting it; I have not reviewed the code line by line.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PRwDEapgChAWSk1ncJ62Yk