Repository navigation
[Engine] qwen4: read the PLE n-gram table row by row from disk through the Direct reader - #440
Inex0rablePwz wants to merge 2 commits into
Conversation
…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.
…r fix, with install docs A patches/ bundle with the two porting efforts kept as apply-able files and exact install docs (English + Russian): - patches/qwen4exp-full-port/: the standalone arch=qwen4exp port of Qwen4-35B-A3B to strata-poly (its format-patch, based on 4106d1a), the port's architecture docs (README, TENSOR-MAP, PLE, tensor layout), and the validation harness verify/ - the llama.cpp reference + dump-layers comparison script, the tokenizer, the float CPU reference and its tensor-dump tool - with the expected artifacts of the 2026-12-04 run (main + the Direct-reader PLE of PR simplexai-labs#440 matched llama.cpp byte for byte, 1249/1249 chars). - patches/qwen35-clover/: the Clover fix as it stands against current main: ssm_a was already fixed upstream; this adds per-layer detection of the block-of-guesses tensors, so --clover-masks disables itself on clover_moe files without ssm_conv1d.weight_right instead of throwing. Apply-checked and build-verified on df2c3ff. The 21 MB metadata.json key dump and the ~400 MB CPU-reference .f32 dumps are not in the tree: both are regenerable, the docs say how.
|
Test report: Direct PLE reader (this PR) on Radeon RX 9060 XT, 16 GB VRAM (gfx1200), PCIe 5.0 x16; Ryzen 7 7500X3D (6c/12t), 32 GB DDR5, 2 TB NVMe SSD (PCIe 3.0); Windows 10, ROCm 10.0. Model: Qwen4-35B-A3B GGUF UD-IQ3_XXS, MTP draft active, Method: server-reported timings, temp 0, distinct prompts per run, medians of 3 runs (5 for the decode test), compared against the mmap baseline build on the same machine. Workload: 512-token generation on a short prompt, plus prefill tests at ~3.8k, ~20k and ~50k token prompts with a 64-token output cap.
Host RAM usage dropped ~5 GB with the Direct reader. Likely cause: the ~100 MB row cache covers short runs, but at 1.5k–20k-token prompts the working set exceeds it and PLE reads become per-step SSD waits that scale with prompt length. Limits:
Disclosure: this report was written entirely by an AI coding assistant working on the author's machine; the benchmark numbers come from the author's own runs. |
…, as Inkling 2's do In a prompt read of several calls, moe_rows() copies each call's row tables (about 100 KB) to the card with cudaMemcpyAsync on the main stream. The layer's experts outside VRAM are copied ahead of the routing on the up stream, and a GeForce card has one copy engine for uploads, so the tables' copy waited behind those uploads and the layer's multiplications, the cached experts' too, waited behind the tables. Inkling 2 has the tables read by a kernel from pinned memory instead (kernel_tables_, f0ab63a); Qwen4 now does the same. The same tables reach the same buffers. STRATA_QWEN4_KERNEL_TABLES=0 keeps the copies. CUDA only, as for Inkling 2. RTX 4060 Laptop 8 GB (PCIe 4.0 x8), UD-IQ4_XS, --kv q8_0, 2,048-token prompt: 1,039.8 +- 34.4 tokens/s against 1,023.9 +- 45.6 with =0 (4 runs each, this branch); on top of PR #440 990.6 +- 5.5 against 974.3 +- 6.4 (3 runs). The same tokens in every run. It matters more with --stage-ring and the next layer's experts copied ahead (separate change), where the tables otherwise wait behind a whole layer's uploads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
…call copies the next layer's experts A prompt read on a card that holds few of the experts copies a layer's experts outside VRAM ahead of the routing (moe_rows()), into the staging buffer, which is at most one layer wide; with --stage-ring its two halves take turns. The next layer's copy goes out only when the host reaches that layer, after waiting for this layer's router, so on an RTX 4060 Laptop with Qwen4-35B-A3B UD-IQ4_XS the upload copy engine was idle for 11-12 ms of every 38-47 ms layer of a 2,048-token prompt, and neither the kernels (60%) nor the copies (45%) kept the card busy. --stage-next 1 (STRATA_POLY_STAGE_NEXT=1), with --stage-ring 1, in a read of one or two calls through the layers in turn (not read_groups(), and not with three or more calls, whose packs' rows come from pinned memory through the same copy engine) and on an architecture whose call row tables go to the card by a kernel (kernel_tables_; a copy of them would wait behind the next layer's experts): - widen_stage() maps two layers' experts for the read instead of one (Options::stage_next, stage_wide1_ the one- layer width it falls back to when two do not fit, as with a frozen cache), so a layer's experts are one round in one half; - moe_rows()'s card() plans the next MoE layer's rounds (plan_ahead() does not depend on the routing) and copies each into the half this call's round two before it leaves, or at once when that half is free; the next layer's call finds them (ring_next_mine) and copies nothing; - the call's end waits for the halves it used, not the next layer's; anything that drops the ring's halves drops the next layer's copy too (drop_ring_next(), which lets the upload stream finish first). Off by default; nothing changes without it. RTX 4060 Laptop 8 GB (PCIe 4.0 x8), CUDA 13.4, Qwen4-35B-A3B UD-IQ4_XS on this branch plus PR #440 and the Qwen4 row-table kernel (separate change), --kv q8_0, 2,048-token prompt, 2 runs each: 1,224.8 / 1,225.2 tokens/s against 1,039.7 / 1,040.4 with --stage-ring 1 alone (main and PR #440 without either setting: 948.6 +- 9.6, 3 runs); the copies now run back to back. A 6,000-token prompt 1,136.9 / 1,125.1 against 1,124.9 / 1,114.4 (inactive there by design). Inkling 2 Mini UD-Q4_K_XL (read_groups(), so inactive), 2,047 tokens: 674.8 / 674.8 against 664.7 / 669.9. The same tokens in every pair. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018j62UGHq9crCFFy7fHrCcW
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 existingbegin_stepprefetch slot, dequantized from pinned raw bytes into theh_ple_emb_staging the kernels already consume.--ple-mmapasks 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 Linux CUDA (RTX 3080 Ti) with
unsloth/Qwen4-35B-A3B-GGUFUD-Q5_K_M: a 256-token greedy run is byte-identical to llama.cpp's reference output (1249/1249 chars); PLE table: 4272 rows asked, 2880 row-cache hits, 1392 SSD reads (5,799,936 B), 41.5 ms total collect wait across load + prefill + 256 tokens; clean build for the CUDA target; the Flash Next serve (strata --serve, GPU1) and its config hash unaffected by the test windows.