perf(prefill): the chunk expert stream is EXPERIMENTAL and off by default

Job 0708 (same binary, LELEKA_PREFILL_STREAM A/B): with next-MoE copies
queued under the GDN batches the ring fell 1,108 -> 776 ms per 8192-token
chunk but the GDN windows grew by about as much (2,676 vs 2,730 ms per
chunk), and 2048-token chunks got slower (1,755 vs 1,410 ms). The
per-layer copy ring is the default again; LELEKA_PREFILL_STREAM=1 enables
the stream for experiments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-17 00:03:18 +02:00
co-authored by Claude Opus 5.5
parent 52e0911652
commit 499faec1ae
2 changed files with 18 additions and 5 deletions
@@ -9,13 +9,16 @@ use leleka_cuda_driver::{GdnNativeFormat, NativeBatchWorkspace,
use leleka_model_format::qwen4exp::ResidentExpertBankSpan;
use crate::qwen_forward::prefill_profile::{self as prof, Stage as PStage};
/// prefill.cpp `stream_all` order (`begin_prompt_stream`): on for chunks of at least `STRATA_PREFILL_STREAM_MIN`
/// rows (1024) over a registered bank; `LELEKA_PREFILL_STREAM=0` keeps the per-layer copy ring.
/// EXPERIMENTAL, off by default: prefill.cpp `stream_all` order (`begin_prompt_stream`) with next-MoE copies
/// queued under the GDN kernel batches, for chunks of at least `STRATA_PREFILL_STREAM_MIN` rows (1024) over a
/// registered bank, with `LELEKA_PREFILL_STREAM=1`. Measured (job 0708): the copies moved out of the ring into
/// the GDN windows instead of overlapping them (8192-token chunks 2,676 vs 2,730 ms, 2048-token chunks 1,755 vs
/// 1,410 ms), so the per-layer copy ring stays the default.
/// `LELEKA_PREFILL_PCIE_GBPS` (default 45) sizes the copies queued under a GDN layer's kernels.
fn prompt_stream_settings() -> Option<(usize, f64)> {
static SETTINGS: std::sync::OnceLock<Option<(usize, f64)>> = std::sync::OnceLock::new();
*SETTINGS.get_or_init(|| {
if std::env::var("LELEKA_PREFILL_STREAM").is_ok_and(|v| v == "0") {
if !std::env::var("LELEKA_PREFILL_STREAM").is_ok_and(|v| v == "1") {
return None;
}
let number = |name: &str, default: usize| std::env::var(name).ok().and_then(|v| v.trim().parse().ok()).unwrap_or(default);
+12 -2
View File
@@ -109,8 +109,18 @@ boundaries like this one; a deliberate default change).
`80627bc` ran the Original's `stream_all` with its own issuer thread: slower (job 707: 1,083 vs 1,413 tok/s at
2048, 2,419 vs 2,624 at 8192) because every stage of the port's compute path drains with cuCtxSynchronize, which
also waits for whatever the issuer has queued. `e9b8a5e` drives the same stream from the calling thread and queues
the next MoE's copies only under the GDN prompt producer's sync-free kernel batch (`prefetch_point`). Results:
job 0708 (below).
the next MoE's copies only under the GDN prompt producer's sync-free kernel batch (`prefetch_point`). Job 0708
(same binary, A/B with the switch): at 8192-token chunks moe.ring fell 1,108 -> 776 ms but the GDN windows grew
537-578 -> 825-850 ms (chunk 2,676 vs 2,730 ms, 2,992 vs 2,941 tok/s on 16,000 tokens: within noise); at 2048 the
chunk got slower (1,755 vs 1,410 ms). The copies moved out of the ring into the GDN windows instead of overlapping
them. The stream is therefore EXPERIMENTAL and off (`LELEKA_PREFILL_STREAM=1` enables it). Real overlap needs the
compute path's drains scoped to its own streams (cuStreamSynchronize of the producers' streams instead of
cuCtxSynchronize) and the per-stage finite-status readbacks deferred; both are driver-wide changes.
Final RTX 5090 numbers (job 0708, stream off, tier off, greedy ids equal to every earlier build of the same
chunking): 16,000 tokens at chunk 8192 2,941 tok/s (5.44 s), 8,000 tokens 1,878 tok/s (first prompt of the process,
includes the one-time expert finite admission ~0.8 s); chunk 2048 ~1,430-1,450 tok/s steady. One-pass row staging
(`84983ab`): init.upload 179-189 -> 131-141 ms per 8192 chunk.
### Laptop (RTX 3080, same harness, cache off for pairing: `LELEKA_LAPTOP_PROMPT_CACHE=0`)