Repository navigation
perf: Flash Next reads a prompt chunk's n-gram rows on 16 threads (same bytes) - #73
Closed
devopsfortunato wants to merge 1 commit into
Closed
devopsfortunato wants to merge 1 commit into
devopsfortunato wants to merge 1 commit into
Conversation
…me bytes HostTable.gather copied a prompt's n-gram rows with one fancy index per file, so rows whose pages were not in the page cache were read from disk one page fault at a time. On a DGX Spark with a 131,072-token cache the ~31 GB tables barely fit in the page cache, and how much of them the start-up prefetch leaves cached varies from start to start. A gather of 1,024 rows or more (a prompt chunk of 64 tokens or more) now copies on up to 16 threads, 512 rows or more each. numpy's fancy indexing releases the GIL, so the page faults overlap: staging costs about 0.07 ms a fault instead of 0.25 ms. Decode steps keep the single-threaded copy. The bytes are the same. One Spark, 131,072-token cache, default 2,048-row chunks, a fresh process each with the n-gram files dropped from the page cache before it (the start-up prefetch refills what fits), release and branch alternated, every prompt new text: 606 tokens 0.37-0.55 -> 0.36-0.42 s, 1,118 tokens 0.56-0.73 -> 0.55-0.59 s, 4,186 tokens 1.95-2.31 -> 1.92-1.97 s, 8,192 tokens 3.65-4.29 -> 3.60-3.70 s, 32,768 tokens 15.1-16.5 -> 15.1-15.2 s, 120,000 tokens 65.4-65.7 -> 64.7-65.3 s. Decode unchanged. Checked: the threaded copy is byte-identical to the single-threaded one (new test, and 1,000 to 131,072 random rows of the real table); teacher-forced NLL through the prompt and the decode path identical to the release on all 119,980 values; 55 replayed benchmark replies byte-identical; drafted vs serial 9/9; needles 9/9.
This was referenced Sep 28, 2026
Closed
Owner
|
Thank you, @MovieMaker93. The threaded n-gram reads are in 0.3.6.3 under your name (2c984cf1). We added tests for |
5 tasks done
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.
TL;DR: faster prompts with the default settings, no setting to change, same bits. Flash Next on CUDA now reads a prompt's n-gram rows on 16 threads instead of one. On a DGX Spark with a 131,072-token cache, short and mid-size prompts get up to ~25% faster when part of the n-gram tables is not in the page cache, and stay the same when all of it is; decode is unchanged. Independent of #40.
The problem
HostTable.gathercopied a prompt's n-gram rows with one fancy index per file. Rows whose pages are not in the page cache are then read from disk one page fault at a time, while the prompt is staged. On a Spark with a 131,072-token cache the ~31 GB n-gram tables barely fit in the page cache, and how much of them stays cached after the start-up prefetch varies from start to start (29-32 GB here), so a prompt of new text often pays hundreds to thousands of page faults.The change
A gather of 1,024 rows or more (a prompt chunk of 64 tokens or more) copies its rows on up to 16 threads, at least 512 rows each. numpy's fancy indexing releases the GIL, so the page faults overlap: staging costs about 0.07 ms per page fault instead of 0.25 ms. Decode steps (a few rows) keep the single-threaded copy. The copied bytes are the same.
Results
One DGX Spark, MLX 4-bit checkpoint, 131,072-token cache, default 2,048-row chunks. A fresh process each, with the n-gram files dropped from the page cache before it (the engine's start-up prefetch refills what fits), release and branch alternated four times, every prompt new text; prompt to first token:
The best cases are the same (a release start that happened to cache every table page); the slow starts go away.
Through the server, back to back in one session (median of 3):
Checks
test_a_prompt_chunks_gather_on_threads_gives_the_same_bytes(1, 2 and 16 threads), and 1,000 to 131,072 random rows of the real table.tests/test_ple_ssd.py,tests/test_ngram_read_ahead.py: 54 passed (4 Metal-only skipped). CUDA Flash Next suite passed (test_glm_nonfit_refuses_before_weight_loadfails the same way on the unmodified release).