Repository navigation
perf: opt-in wider Flash Next prompt chunks (TENSORFOLD_PREFILL_ROWS), default unchanged - #40
devopsfortunato wants to merge 2 commits into
Conversation
|
Thanks @MovieMaker93, great find: most of that prefill time really was spent on work whose results were never used. 0.3.5's CUDA engine reworks the same Flash Next prefill path, about 9x faster than 0.3.4.1 on one Spark, so we're comparing your six changes against it now. Anything that adds speed on top lands in 0.3.5.1 as a commit authored by you, and we'll post the numbers here. |
|
@ashhart Pushed one more commit (7c80822): launch settings only, for the long-prompt path and the prefill experts, bit-identical (checked kernel by kernel and on the model; new test included). Prefill is a bit faster on long prompts, one Spark, 131,072-token capacity:
Through the server, time to first token against the release: 7.7k tokens 53.6 s → 7.65 s, 32.8k 232 s → 32.8 s, 120k 977 s → 124 s. |
…rom 8k tokens, same bits Prefill rows never depend on their chunk, so a wider chunk changes speed and memory only. MLX checkpoints now prefill in 8,192-row chunks; EXL3 packs keep 2,048 (their n-gram staging is sized for it). The engine passes the chosen rows to the startup estimate (gdn_geometry / indexed_stream_geometry) and to its prompt buffers. One Spark, 131,072-token cache, a fresh process each, 8,192-row chunks against 2,048: 8k tokens 2,236 -> 2,552 tok/s, 32k 2,010 -> 2,532, 65k 2,084 -> 2,495, 120k 1,939 -> 2,299; about unchanged up to 4k. Peak allocation grows about 2.4 GiB. Checked on the model: the whole state after 6k-, 24k- and 120k-token prompts and 48 drafted tokens after the 24k prompt (greedy and sampled) equal the 2,048-row path's, and teacher-forced NLL through both the prefill and the decode path is identical on every token of five 6,000-token documents. 16,384-row chunks were no faster; 128-pair expert tiles and multi-group dense matmul stages (same bits) were slower.
7c80822 to
cbb2288
Compare
|
Rebased on v0.3.6.1. Wider prefill chunks are now opt-in ( |
…; default back to 2,048 Measured again with prompts of new text, a fresh process each, release and branch runs alternated. At a 131,072-token cache on a Spark the 8,192-row buffers' 2.4 GiB comes out of the page cache that holds the n-gram tables, and new-text prompts up to about 16k tokens got slower (606 tokens 0.39-0.44 -> 0.48-0.71 s, 8,192 tokens 3.74-3.81 -> 4.11-4.32 s, about 10x the major page faults); the previous commit's numbers reused cached text. With a 32,768-token cache the tables stay cached: 4k- to 24k-token prompts 8-18% faster, short prompts unchanged. So the default is the release's 2,048 again (the same startup estimate and per-token NLL as the release), and TENSORFOLD_PREFILL_ROWS (256 to 16,384; MLX checkpoints, EXL3 packs keep 2,048) opts in to wider chunks. The startup estimate and the prompt buffers read the same value (geometry.indexed_prefill_rows).
From #40, which made Flash Next prefill on CUDA about 7x faster than v0.3.4.1, byte-exact. There, prompts prefilled through the decode kernels in 64-row chunks at 128-145 tok/s on one DGX Spark, and most of that time was work whose results were never used: - expert kernels: a member tile with no rows returns before reading its expert, and member tiles are the fastest grid axis, so one expert's tiles share its weights in L2 - attention: partials and grid sized for the 2,051 keys a QSA row can read instead of the capacity; programs past a row's keys or complete blocks return - prefill computes the head only on the prompt's last chunk - 1,024-row prefill chunks; above 64 rows the distinct experts are grouped by a stable sort - member-list widths above 16 rows rounded up to a power of two, and the prefill kernels compiled at start Against v0.3.4.1 on one Spark at a 131,072-token capacity: 8k prompts 142 -> 1,008 tok/s, 32k 132 -> 993, 120k ~123 -> 914; through the server, a 7.7k-token prompt's first token after 7.9 s instead of 53.6 s. 0.3.5 reworked this path: 2,048-row prompt chunks, shared CUDA expert and matmul prefill kernels that launch only populated member tiles, attention partials capped at the keys a row reads, and expert grouping on the device. This commit keeps the change that still lands on it: the head runs on the final chunk alone. Its test checks that any chunking of a prompt past the sparse attention budget gives the one-chunk prefill's first token and state bit for bit. The start-up compile is ported separately for the current prompt kernels.
|
Thank you, @MovieMaker93. Running the head on the final chunk only shipped in 0.3.6.2 under your name (96c0b0e4). We also |
TL;DR: nothing changes by default.
TENSORFOLD_PREFILL_ROWS=8192is an opt-in that makes prompts from 4k tokens prefill 8-18% faster when the n-gram tables fit in RAM (e.g. a Spark with a 32k context), with short prompts unchanged and the same bits. At a 131k context it makes short prompts slower, so keep the default there.Rebased on v0.3.6.1.
What this changes
TENSORFOLD_PREFILL_ROWSsets how many prompt rows Flash Next prefills per chunk on MLX checkpoints (256 to 16,384).--parallel), so the two cannot disagree.A row's bits never depend on its chunk, so the setting changes speed and memory only.
Why opt-in and not a new default
Wider chunks run the same kernels on more rows at once, but 8,192-row buffers take 2.4 GiB more. On a Spark that memory comes out of the page cache holding Flash Next's ~31 GB n-gram tables. When the tables still fit, it is a pure win; when they do not, prompts of new text read n-gram rows from disk while they are staged, and short prompts get slower.
Results
One DGX Spark, MLX 4-bit checkpoint. A fresh process each, release and branch alternated twice, every prompt new text; prompt to first token, in one process.
32,768-token cache (the tables stay cached): recommended
131,072-token cache (the tables no longer fit): keep the default
Major page faults for a 606-token prompt at 131k: 48-161 (default) vs 557-1,566 (8,192 rows). When the prompt's n-gram rows are already cached (repeated text), 8,192 rows are 14-26% faster at 131k too (8k 2,236 -> 2,552 tok/s, 120k 1,939 -> 2,299).
Memory: 8,192 rows add 2.8 GiB to the startup estimate and 2.4 GiB to the peak allocation.
Checks
test_glm_nonfit_refuses_before_weight_loadfails the same way on the unmodified release). New test:test_indexed_prefill_rows_default_override_and_budget.Usage