Repository navigation
[Engine] qwen4: with --ple-direct, read PLE rows ahead: a decode window's while its guesses are drafted, a prompt's while its first layers run - #465
Open
drakarah wants to merge 2 commits into
Conversation
This was referenced Dec 5, 2026
Closed
Collaborator
|
Thanks @drakarah! Please rebase |
…and the VRAM reserve does not count them --ple-direct (off by default, CUDA and HIP) reads the PLE n-gram table's rows straight from disk through strata::ngram::PleReader, the Direct reader the Flash Next engine uses for its own PLE, in place of the host map of shard 2: unbuffered reads, a 1M-row (~100 MB) row cache, the SSD keep-alive, one issue a step over its whole row set, collected in begin_step()'s PLE slot and dequantized from pinned raw rows into h_ple_emb_. The reader is PR simplexai-labs#440's (closed); here it is opt-in, since it read prompts about 3.4 times slower than the map on a Windows PC with a PCIe 3.0 SSD (PR simplexai-labs#440's report). A file the reader cannot open falls back to the map. Not on Metal: there the map is kept (the reader is not compiled in), as its gathers need no copy. With the reader open the table needs no page cache, so fill_expert_cache() no longer counts it among the files whose page cache its tight-RAM test keeps room for (Engine::direct_file_bytes(), default 0; Qwen4 returns the table's bytes only while the reader is open). Before, a 30 GB PC with UD-IQ4_XS (20.5 + 11.5 GB of files) got the doubled reserve. Without --ple-direct nothing changes: the table is mapped and direct_file_bytes() is 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
…ow's while its guesses are drafted, a prompt's while its first layers run With the opt-in Direct PLE reader (--ple-direct) each verify window waited for its tokens' n-gram rows (16 a token) before its first layer: prepare_ple() issued them in begin_step() and blocked in collect(). Now: - decode: the window's tokens are known one by one while the MTP block drafts them, so draft_step() asks the reader for each token's rows as soon as the token is known (ple_read_ahead()); the window's own read in prepare_ple() first waits for them (ple_drain_ahead()) and then takes them from the row cache. The last guess is read with the window. - prompt: read() hands an architecture all of a read's tokens before the first call (Engine::read_begins(), one sequence, no co-reads). Qwen4 hashes them as prepare_ple() does and asks for their rows in chunks of 1,024 tokens, up to 4,096 tokens ahead of the call being read (ple_prompt_issue()); each call waits for the chunks that start before its end (ple_prompt_drain()) and asks for the next ones. The same rows and sums; only when the reads happen changes. STRATA_QWEN4_PLE_AHEAD=0 turns both off. Without --ple-direct, and on Metal (no reader there), nothing changes. RTX 4060 Laptop 8 GB, i9-12900H, RS1D0TSSD710, UD-IQ4_XS, --kv q8_0, with the reader: decode, 33-token prompt, 500 tokens, 6 interleaved runs, 86.05 +- 1.00 tokens/s against 82.88 +- 2.86 off, the reader's collect wait 68 against 203 ms a run; frozen experts, 2,048-token prompt 1,031.1 against 987.2 tokens/s, 6,000 tokens 1,138.7 against 1,088.7, the same tokens. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
drakarah
force-pushed
the
feat/qwen4-ple-read-ahead
branch
from
December 6, 2026 09:29
e7f5931 to
eeadc98
Compare
Contributor
Author
|
Thanks! Rebased cleanly: one commit,
Could you add |
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.
Problem and result
With the opt-in Direct PLE reader (
--ple-direct, PR #464; PR #440 made it the default and was closed), every decode step of Qwen4-35B-A3B first reads its tokens' n-gram rows from the SSD (16 rows a token) and blocks incollect()before the card starts the step (prepare_ple()frombegin_step()). On an RTX 4060 Laptop with UD-IQ4_XS that wait was about 200 ms over a 500-token answer, roughly 5% of the decode time, and it sits on the critical path of every verify window.Prompts wait too: on a card that holds few experts a prompt read goes through the layers in turn, so every call's rows were read at layer 1 with the card idle (about 150-230 ms of a 2,048-token prompt in an Nsight Systems trace).
The window's tokens are known one at a time while the MTP block drafts them. Now
draft_step()asks the reader for each token's rows as soon as it is known; the reads land in the reader's row cache, and the window's own read finds them there. Measured on the laptop below, 6 interleaved runs each, 500 tokens after a 33-token prompt: 86.05 ± 1.00 tokens/s against 82.88 ± 2.86 with it off (+3.8%), and the reader's collect wait 68 ms against 203 ms a run. The SSD reads are the same in number (4,208 against 4,264 in the frozen runs); only their timing moves.For prompts,
read()now hands the architecture all of a read's tokens before its first call (Engine::read_begins()), and Qwen4 asks the reader for their rows in chunks of 1,024 tokens, up to 4,096 ahead of the call being read. Frozen experts, same tokens: 2,048 tokens 1,031.1 against 987.2 tokens/s (collect wait 148.8 against 259.9 ms), 6,000 tokens 1,138.7 against 1,088.7 (205.1 against 488.2 ms).Related discussion
PR #464 (the opt-in Direct PLE reader, which this branch is on), PR #440 (closed). PR #466 (the reader's read depth) was closed:
STRATA_IO_THREADS=64already gives it, anddocs/models/qwen4.mdnow says so. No issue.Approach
Qwen4::ple_read_ahead(token, pos), called at the top ofdraft_step(): the token atpos_ + i(the window's first token, then the guesses that the following draft steps take as input), hashed exactly asprepare_ple()hashes it (the two tokens before it from the earlier window tokens read ahead, then from the ring), and the 16 rows issued to the reader into a small landing buffer (kPleAhead= 8 tokens).ple_drain_ahead():prepare_ple()collects those tickets before it issues the window's own read, which then copies the rows out of the row cache. The destructor drains them before the reader closes.--ple-directand a single sequence (rows_of_null); without the flag (the default, the table mapped), on Metal and in batched steps nothing changes. On Metal the reader and this read-ahead are compiled out (#if !defined(STRATA_GPU_METAL)): Metal'sstrata-polydoes not linkple_reader.cpp. The window's last guess is still read with the window.Engine::read_begins(tokens, n)(virtual, empty), called byread()after it binds the sequence, without co-reads.Qwen4::read_begins()copies the tokens,ple_prompt_issue()hashes them asprepare_ple()does and issues one ticket a 1,024-token chunk into its own landing buffer, andprepare_ple()collects the chunks that start before its call's end (ple_prompt_drain()), issues the next ones and then reads as before.STRATA_QWEN4_PLE_AHEAD=0turns both off (registered as a rollback switch, on only with--ple-direct; its entry added tomain's register anddocs/SETTINGS.md).docs/models/qwen4.md: the read-ahead, its numbers andSTRATA_IO_THREADS=64.STRATA_IO_THREADS).Validation
Revision
eeadc9897(one commit, the two earlier ones squashed) on PR #464's8f1703c7e, onmain7cef9524a, without PR #440's commits. The speed numbers are from the earlier revisions62b988400ande7f5931a0(the same read-ahead code, on PR #440's reader then on by default). RTX 4060 Laptop GPU 8 GB (sm_89, PCIe 4.0 x8), i9-12900H, 30 GB RAM, Linux, CUDA 13.4; Qwen4-35B-A3B UD-IQ4_XS from the pinned commit742bc191(SHA-256 checked),--kv q8_0 --max-context 8192, default MTP.Passed:
STRATA_FREEZE_EXPERTS=1 --expert-swaps 0(the cache split held still), 300 tokens are identical with it on, with=0, and with the build without this commit (57be2e249523).=0(+3.1%), collect wait 67.8 against 180.8 ms.c50e2dbf,512f5519).python3 tools/settings_register.py --checkandpython3 -m unittest tools.test_settings_register: OK.eeadc9897: CUDA 13.4 (strata-poly, sm_89); HIP with ROCm 7.2.4 (rocm/dev-ubuntu-24.04:7.2.4-complete, the CI's image), presethip-compile(gfx1100, gfx1201), targetstrata-poly; HIP on Windows 11, ROCm 7.2 SDK (pip_rocm_sdk_devel), gfx1010 (RX 5700 XT), targetstrata-poly.eeadc9897:mainand this branch without--ple-direct, frozen experts, the same 300 tokens (57be2e24); with--ple-direct, read-ahead on and withSTRATA_QWEN4_PLE_AHEAD=0: the same (57be2e24).Failed:
Not run:
--no-draft(n-gram lookup guesses), batched serving.Limits
STRATA_IO_THREADS=64as well it went from 260 to 72 ms.🤖 Generated with Claude Code
https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW