Repository navigation
[Engine] qwen4: opt-in --ple-direct: the PLE table's rows from disk, and the VRAM reserve does not count them - #464
Open
drakarah wants to merge 1 commit into
Conversation
Collaborator
|
Thanks @drakarah! We merged |
…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
drakarah
force-pushed
the
feat/qwen4-reserve-direct-ple
branch
from
December 6, 2026 09:29
04ab263 to
8f1703c
Compare
Contributor
Author
|
Thanks! Rebased onto
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
PR #440 read Qwen4's PLE n-gram table row by row from disk through the Direct reader (
strata::ngram::PleReader, the one the Flash Next engine uses) instead of mapping shard 2, and made that the default. It was closed. Its own test report found prompts read about 3.4 times slower than with the map on a Windows PC with a PCIe 3.0 SSD.This PR brings that reader in as an opt-in,
--ple-direct. Without the flag nothing changes: the table is mapped as onmain, and the VRAM reserve is computed as onmain.With the flag, the table needs no page cache. Before this change it was still counted among the model's files when
fill_expert_cache()checked for tight RAM (ram_tight_), so a 30 GB PC with UD-IQ4_XS (20.5 + 11.5 GB of files) got the doubled reserve: 512 MiB instead of 256. With the reader open,Engine::direct_file_bytes()leaves those bytes out. On the laptop below the card then held 2,599 of 10,496 routed experts instead of 2,443 (+6.4%). Decode was 83.64 ± 3.52 tokens/s against 82.98 ± 0.81 (6 runs), within the run-to-run spread, so I claim the larger cache, not a speed-up.Rebased onto
main(7cef9524a) without PR #440's commits: the reader's code is in this PR's commit, made opt-in. PR #440'spatches/files are not in it.Related discussion
PR #440 (closed: the reader as the default). The PLE read-ahead in PR #465 builds on this.
Approach
Options::ple_direct(false) and--ple-directinmain.cpp's usage and parser.Qwen4::load_geometry(): with--ple-direct, opens aPleReaderon shard 2's table (256 reads in flight, a 1M-row cache, unbuffered reads, the Flash Next serve's keep-alive). If it does not open, it logs that and maps the table as before.prepare_ple(): with the reader, issues one read for the step's whole row set and collects it into pinned raw rows (h_ple_raw_), then dequantizes from there intoh_ple_emb_as before. The destructor prints the reader's counters.Engine::direct_file_bytes()(virtual, 0): file bytes read with no page cache.fill_expert_cache()leaves them out ofram_tight_'s file total.Qwen4returns the table's bytes only while the reader is open.#if !defined(STRATA_GPU_METAL)(Metal'sstrata-polydoes not linkple_reader.cpp). Metal keeps the map.docs/models/qwen4.md: the option, and why it is not the default.Validation
Revision
8f1703c7eon7cef9524a. RTX 4060 Laptop GPU 8 GB, i9-12900H, 30 GB RAM, Linux, CUDA 13.4; Qwen4-35B-A3B UD-IQ4_XS,--kv q8_0 --max-context 8192.Passed:
strata-poly, sm_89); HIP on Windows 11, ROCm 7.2 SDK (pip_rocm_sdk_devel), gfx1010 (RX 5700 XT), targetstrata-poly. The CI's Linux HIP image built PR [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's commit, which has this one under it: ROCm 7.2.4 (rocm/dev-ubuntu-24.04:7.2.4-complete, the CI's image), presethip-compile(gfx1100, gfx1201), targetstrata-poly.mainand this branch without--ple-direct, experts held still (STRATA_FREEZE_EXPERTS=1 --expert-swaps 0), the same 300 tokens (57be2e24).--ple-direct --vram-reserve-mib 512(the reserve held equal), the same 300 tokens as the map (57be2e24).04ab263ed, the same code with the reader then on by default): 2,599 experts in VRAM (4.2 GiB) and 227 MiB free after the first answer, against 2,443 (3.9 GiB) and 483 MiB. Decode, 6 interleaved runs, 33-token prompt, 500 tokens: 83.64 ± 3.52 against 82.98 ± 0.81 tokens/s. 6,000-token prompt: 1,091.8 / 1,081.1 against 1,089.4 / 1,081.8 tokens/s, the same tokens.Failed:
Not run:
Limits
--ple-directa prompt's rows come from the SSD while it is read (PR [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 reads them ahead).🤖 Generated with Claude Code
https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW