Skip to content

[Engine] qwen4: the Direct PLE reader reads 64 rows at once on Linux - #466

Closed
drakarah wants to merge 2 commits into
simplexai-labs:mainfrom
drakarah:feat/qwen4-ple-io-depth
Closed

drakarah wants to merge 2 commits into
simplexai-labs:mainfrom
drakarah:feat/qwen4-ple-io-depth

Conversation

@drakarah

@drakarah drakarah commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Problem and result

On Linux DirectFile issues reads from a pool of threads, each doing one blocking O_DIRECT pread, so the pool size is the queue depth: 16 by default (io_threads(16)), sized for the Flash Next decode's 16 n-gram rows a token. Qwen4's PLE needs 16 rows a token too, which is 16,384 rows for a 1,024-token prompt call, and with PR #440 those were read 16 at a time while the card waited at the PLE layer. With STRATA_IO_THREADS set by hand, 64 read a 2,048-token prompt 3.5% faster on my laptop and 128 no faster than 64.

Now DirectFile::open() and PleReader::open() take an optional thread count, and Qwen4 opens its table with 64. On the laptop below: 2,048 tokens 1,029.3 / 1,022.9 tokens/s against 989.2 / 989.9 (the reader's collect wait 194 against 268 ms), 6,000 tokens 1,125.0 / 1,124.9 against 1,086.5 / 1,086.3 (317 against 493 ms). Decode is unchanged.

Related discussion

PR #440 (the Direct PLE reader). No issue.

Approach

  • DirectFile::open(path, err, threads = 0): on Linux and macOS the pool is io_threads(threads > 0 ? threads : 16), so STRATA_IO_THREADS still overrides it and the clamp to 1..64 stays; on Windows, whose threads only submit overlapped reads, the parameter is ignored.
  • PleReader::open(..., read_threads = 0) passes it on.
  • Qwen4: 64 for its PLE table.
  • Kept out: the default for other callers (the Flash Next engine's PLE and engram readers), Windows.

Validation

Revision 76e2adafb. RTX 4060 Laptop GPU 8 GB, i9-12900H, 30 GB RAM, NVMe RS1D0TSSD710, Linux, CUDA 13.4; Qwen4-35B-A3B UD-IQ4_XS (pinned 742bc191), --kv q8_0 --max-context 8192.

Passed:

  • Prompts with frozen experts (STRATA_FREEZE_EXPERTS=1 --expert-swaps 0), 2 runs each, numbers above; the same tokens in every pair (c50e2dbf, 512f5519).
  • Decode, 6 interleaved runs, 400 tokens after a 33-token prompt: 82.03 ± 3.00 against 82.27 ± 2.84 tokens/s (an earlier 4-run set read 80.59 ± 2.25 against 82.13 ± 1.53, also within the spread).
  • strata-poly builds; the Flash Next strata target builds with the changed direct_file.cpp and ple_reader.cpp (see Not run if it did not finish).

Failed:

  • none observed.

Not run:

  • Windows and macOS runs; HIP.
  • Other SSDs: the right depth depends on the drive, and a SATA SSD may gain nothing.
  • Reproduction by anyone else; the whole test suite.

Limits

  • One drive. Up to 64 more idle threads in the process, which wait on a condition variable when there is nothing to read.
  • With the prompt read-ahead (separate PR) the two gains overlap: together they took the 2,048-token prompt from 987 to 1,059 tokens/s.

🤖 Generated with Claude Code

VecSzn and others added 2 commits December 4, 2026 16:46
…h the Direct reader

The strata-poly Qwen4 mapped shard 2's 11-22 GB PLE table whole into host RAM.  Its rows
now come straight off the disk through strata::ngram::PleReader - the same Direct reader the
Flash Next engine runs for its own n-gram PLE: unbuffered O_DIRECT reads, a 1M-row (~100 MB)
row cache, the keep-alive that keeps the SSD awake, issued once per step over the step's
whole row set and reaped in the existing begin_step prefetch slot, dequantized from pinned
raw bytes into the h_ple_emb_ staging the kernels already consume.  --ple-mmap asks for the
old whole-file map; a file whose table the reader cannot open (or Metal, whose unified-memory
gathers read the map with no copy) falls back to it.  The destructor reports the reader's
rows-asked/cache-hits/SSD-reads/collect-wait snapshot, as Flash Next reports its own.

Verified on a Linux CUDA box with Qwen4-35B-A3B UD-Q5_K_M: a 256-token greedy run is
byte-identical to llama.cpp's reference output (1249/1249 chars), 4272 rows asked, 2880 row
cache hits, 1392 SSD reads, 41.5 ms total collect wait across load + prefill + 256 tokens;
builds clean for the CUDA target.
On Linux DirectFile issues its reads from a pool of threads, each doing one blocking O_DIRECT pread, so the pool
size is the queue depth: 16 by default, sized for the Flash Next decode's 16 rows a token.  A Qwen4 prompt call
asks for 16 rows a token too, 16,384 for a 1,024-token call, and they were read 16 at a time while the card waited
at the PLE layer.  DirectFile::open() and PleReader::open() take an optional thread count now (0: the default as
before; STRATA_IO_THREADS still overrides it, and Windows, whose threads only submit overlapped reads, ignores it),
and Qwen4 opens its table with 64.  Everything else keeps its 16.

RTX 4060 Laptop 8 GB, RS1D0TSSD710 NVMe, UD-IQ4_XS, --kv q8_0, frozen experts, 2 runs each: 2,048 tokens 1,029.3 /
1,022.9 tokens/s against 989.2 / 989.9 (the reader's collect wait 194 against 268 ms), 6,000 tokens 1,125.0 /
1,124.9 against 1,086.5 / 1,086.3 (317 against 493 ms), the same tokens.  Decode unchanged: 82.03 +- 3.00 against
82.27 +- 2.84 tokens/s (6 interleaved runs, 400 tokens).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
@VecSzn

VecSzn commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the PR! We are closing this because it modifies 4 shared upstream strata core files (direct_file., ple_reader.), largely overlaps with #465, and STRATA_IO_THREADS=64 is already available.

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