Skip to content

[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
simplexai-labs:mainfrom
drakarah:feat/qwen4-reserve-direct-ple
Open

drakarah wants to merge 1 commit into
simplexai-labs:mainfrom
drakarah:feat/qwen4-reserve-direct-ple

Conversation

@drakarah

@drakarah drakarah commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

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 on main, and the VRAM reserve is computed as on main.

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's patches/ 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-direct in main.cpp's usage and parser.
  • Qwen4::load_geometry(): with --ple-direct, opens a PleReader on 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 into h_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 of ram_tight_'s file total. Qwen4 returns the table's bytes only while the reader is open.
  • Metal: the reader, its include and its calls are behind #if !defined(STRATA_GPU_METAL) (Metal's strata-poly does not link ple_reader.cpp). Metal keeps the map.
  • docs/models/qwen4.md: the option, and why it is not the default.
  • Kept out: making it the default (that would need measurements on 16–32 GB PCs and Windows drives), the reserve's sizes themselves.

Validation

Revision 8f1703c7e on 7cef9524a. 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:

  • Builds: CUDA 13.4 (strata-poly, sm_89); HIP on Windows 11, ROCm 7.2 SDK (pip _rocm_sdk_devel), gfx1010 (RX 5700 XT), target strata-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), preset hip-compile (gfx1100, gfx1201), target strata-poly.
  • Default path: main and this branch without --ple-direct, experts held still (STRATA_FREEZE_EXPERTS=1 --expert-swaps 0), the same 300 tokens (57be2e24).
  • With --ple-direct --vram-reserve-mib 512 (the reserve held equal), the same 300 tokens as the map (57be2e24).
  • Reserve and cache (on the earlier revision 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:

  • none observed.

Not run:

Limits

🤖 Generated with Claude Code

https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW

@VecSzn

VecSzn commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

Thanks @drakarah! We merged #462, #463, #468, #470, #486, #487, and #488 into main for poly.11. For #464, please rebase cleanly onto main without the patches/ files from #440, and keep any change to default ple_direct / VRAM-reserve behavior opt-in (or backed by multi-RAM-tier measurements on 16–32 GB systems).

…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
drakarah force-pushed the feat/qwen4-reserve-direct-ple branch from 04ab263 to 8f1703c Compare December 6, 2026 09:29
@drakarah drakarah changed the title [Engine] qwen4: the VRAM reserve does not count the PLE table the Direct reader reads from disk [Engine] qwen4: opt-in --ple-direct: the PLE table's rows from disk, and the VRAM reserve does not count them Dec 6, 2026
@drakarah

drakarah commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! Rebased onto main (7cef9524a) without #440's commits or its patches/ files: one commit, 8f1703c7e.

  • The Direct reader is now opt-in (--ple-direct, off by default). Without it the table is mapped and the VRAM reserve is computed exactly as on main; the reserve only leaves the table out while the reader is open.
  • Default path: main and this branch, frozen experts, the same 300 tokens; with --ple-direct and the reserve held equal, the same tokens too.
  • Builds: CUDA 13.4; HIP on Windows (ROCm 7.2, gfx1010); the CI's Linux image (rocm/dev-ubuntu-24.04:7.2.4-complete, hip-compile, gfx1100/gfx1201) built [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. Metal: not built here (no Mac); the reader, its include and its calls are behind #if !defined(STRATA_GPU_METAL), since Metal's strata-poly does not link ple_reader.cpp.

Could you add run-backends so the backend jobs (including Metal) run? I can't set labels here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants