Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
349 lines
26 KiB
Markdown
349 lines
26 KiB
Markdown
# Prefill throughput of the Original serve stack (port)
|
|
|
|
Branch `claude/prefill-throughput`. Measurements on the RTX 5090 server (job queue `holder2`, jobs 700-702) with
|
|
the long-context smoke `original_serve_long_context_streamed_kv_smoke` (`LELEKA_ORIGINAL_SERVE_LONG_TOKENS=8000,16000`,
|
|
greedy, 16 new tokens, INT8 KV, resident window 20480, ceiling 65536, budget 30 GiB, model IQ3_S + KAR L2 + MTP pack
|
|
as in job 312). Expert tier "on" = `EXPERT_SLOTS=2048 EXPERT_PER_LAYER=yes EXPERT_PROFILE=baseline/profile.bin
|
|
PCIE_FRAC=0.55`. One process per configuration, one pass per prompt (n = 1: indicative, not a charter A/B).
|
|
|
|
## Profile
|
|
|
|
`LELEKA_BRINGUP_TRACE=1` prints one `PREFILL-PROFILE` line per published chunk (`qwen_forward/prefill_profile.rs`):
|
|
host wall time per stage, nested `moe.*` and `inject` spans included in their parents, `other` = outside every
|
|
top-level span. `LELEKA_PREFILL_PROFILE_SYNC=1` drains the device at every span end (GPU attribution); on this
|
|
workload it changed no stage by more than a few percent, i.e. the stages below are host-bound or synchronous.
|
|
|
|
Before (job 700, `cffbf88`, 2048-token chunk, steady state, ms per chunk):
|
|
|
|
| stage | ms | what |
|
|
| --- | --- | --- |
|
|
| validate | 4,450 | per-row session validation: quadratic in the chunk, and every row re-ran the dense-source checks |
|
|
| moe.ring | 850 | expert DMA ring + grouped MMQ (registered bank, PCIe-bound: ~34 GB of experts per chunk) |
|
|
| moe.spans | 650 | host finite rescan of every routed expert's bytes (~1.4 MB each, one thread) every chunk |
|
|
| gdn / qsa | 220 / 85 | mixers incl. GR injection |
|
|
| input / init | 50 / 50 | per-token KAR/PLE input staging / row upload |
|
|
| reads, inject, prepare, finish | 65, 32, 18, 10 | |
|
|
| total | ~6,500 | 315 tok/s |
|
|
|
|
## Fixes
|
|
|
|
1. `19fac1b` row validation once per set (linear), same checks and order.
|
|
2. `5416f4e` a routed expert's bank bytes are admitted finite once per bank (bit per layer/expert in the MoE cache).
|
|
3. `ae283e6` pageable (file-mapped, laptop) banks: prefill.cpp's `Stager` in the copy ring (helper threads copy
|
|
into page-locked buffers, check the block scales there, the launching thread DMAs); registered banks unchanged.
|
|
|
|
## Results (RTX 5090)
|
|
|
|
| build | chunk | tier | 8000 tok/s | 16000 tok/s |
|
|
| --- | --- | --- | --- | --- |
|
|
| before `cffbf88` | 2048 | off | 307 | 311 |
|
|
| before `cffbf88` | 2048 | on | 306 | 310 |
|
|
| after `5416f4e` | 2048 | off | 1,145 | 1,435 |
|
|
| after `5416f4e` | 2048 | on | 1,174 | 1,463 |
|
|
| after `5416f4e` | 8192 | off | 1,922 | 2,887 |
|
|
| after `5416f4e` | 8192 | on (lends 1,891 slots) | 1,883 | 2,828 |
|
|
|
|
Greedy output ids at chunk 2048 are identical before and after (both prompts, tier off and on). The first chunk of a
|
|
process still pays the one-time finite admission (~0.7-0.85 s).
|
|
|
|
After (8192-token chunk, ms): moe.ring 1,110, gdn 585, qsa 254, input 184, init 210, attn+ffn reads 229, inject 125,
|
|
moe.spans 36, prepare 47, finish 36.
|
|
|
|
Chunk size and greedy output (jobs 702/703, tier off, 16 greedy tokens; every configuration is deterministic over
|
|
two passes on one stack): 8000, 10000 and 12000 tokens answer identically at chunks 2048 and 8192; 16000 tokens
|
|
answers identically at 2048, 4096 and 6144 (1,430 / 1,569 / 1,982 tok/s) but differently at 8192 (an immediate
|
|
`</think>` answer instead of a thinking turn). Whether that is chunk-order rounding at a decision boundary or a
|
|
large-chunk defect is open: compare final-row logits at 6144 vs 8192 (and the Original at 8192) before making 8192
|
|
the default. The default stays 2048; `LELEKA_ORIGINAL_SERVE_CAPACITY` / `prefill_capacity` select larger chunks.
|
|
The Original's `--prefill auto` reaches 8192 only when it can lend expert-cache slots (profile + borrow), and
|
|
otherwise keeps 2048, so the port's default matches it without the tier.
|
|
|
|
## Laptop (RTX 3080 laptop, WSL2, mapped experts, VRAM tier auto + profile, KAR file, 3 prompts of 78-88 tokens)
|
|
|
|
Same harness as docs/laptop-profile.md (`scripts/laptop/port_bench.sh`, 16 new tokens, 2 passes), one process per
|
|
arm, W first (cold page cache after a WSL restart), then Y. Greedy outputs identical.
|
|
|
|
| arm | prefill tok/s pass 0 / pass 1 | TTFT s pass 0 / pass 1 |
|
|
| --- | --- | --- |
|
|
| W `3e05437` (integration head) | 0.7, 1.4, 3.1 / 1.6, 1.9, 2.3 | 120, 59, 26 / 56, 44, 35 |
|
|
| Y `ae283e6` (all fixes + stager) | 5.6, 4.5, 6.4 / 9.0, 9.4, 9.4 | 17, 19, 13 / 10.5, 9.5, 8.9 |
|
|
|
|
Y's profile (pass 1, ~80 tokens): moe.ring 5.5-7.0 s (expert bytes over PCIe from the page cache), gdn 1.33 s,
|
|
qsa 0.33 s, everything else < 0.2 s. The Original's paired row in docs/laptop-profile.md: 12.4 tok/s, TTFT 7.2 s.
|
|
|
|
## Remaining gap (RTX 5090, 8192-token chunks: 2,830-2,930 tok/s vs the Original's 5,400-5,900)
|
|
|
|
- moe.ring 1.1 s: the expert DMA (~34 GB per chunk) runs layer by layer and drains before the next mixer; the
|
|
Original's `stream_all` (prefill.cpp 1159-1286, driver `run_stream_all_forward` exists, unused by the runtime)
|
|
keeps the copy stream busy across layers.
|
|
- gdn 0.58 s, qsa 0.25 s, GR reads/injects 0.35 s per 8192 tokens. GDN costs 1.3 s even on an 80-token laptop
|
|
prompt, so most of it does not scale with the chunk; the chunk owner checks and stages each layer's recurrent state
|
|
from host values (`GdnChunkDevice::new`), the likely cause (not yet measured separately).
|
|
- input 0.18 s (per-token KAR gather with device round trips) and init 0.21 s (host row staging) per 8192 tokens.
|
|
|
|
## Follow-up (jobs 704-708, laptop runs E/F/G)
|
|
|
|
### Chunk 8192 on the 16,000-token prompt: rounding, not a defect
|
|
|
|
`LELEKA_TRACE_LOGPROBS=5` / `LELEKA_TRACE_RESIDUAL` (jobs 704, 706). The answers differ at the third generated
|
|
token (position 16001): chunk 6144 gives `198` (logprob -0.568) over `271` (-0.836); chunk 8192 gives `271`
|
|
(-0.578) over `198` (-0.824): a 0.25-nat near tie. The final residual of the last prompt row differs between ANY
|
|
two chunk sizes by about the same amount: relative L2 2048/4096 0.168, 2048/6144 0.194, 4096/6144 0.179,
|
|
2048/8192 0.203, 6144/8192 0.185 (cos 0.982-0.988); 8000 tokens at 2048 vs 8192: 0.137. 8192 is not an outlier,
|
|
so this is chunk-order rounding accumulated over 16,000 tokens and 48 layers. Proposal: take the Original's
|
|
`--prefill auto` ladder as the default when the expert tier lends slots (8192 on the 5090), 2048 otherwise (the
|
|
Original's own fallback without a profile/borrow). Not changed in this branch (it changes answers at decision
|
|
boundaries like this one; a deliberate default change).
|
|
|
|
### Where an 8192-token chunk's time goes (job 705, `LELEKA_PREFILL_PROFILE_SYNC` per-command timing)
|
|
|
|
- Expert DMA: `LELEKA_PREFILL_DIAG_SKIP_EXPERT_DMA=1` (EXPERIMENTAL, wrong outputs) cuts moe.ring from 1,105 to
|
|
330 ms: ~0.77 s of the chunk is the per-layer expert stream (34 GB at ~45 GB/s; the Original's probe: 49.9 GB/s),
|
|
not MMQ. Without it the chunk would run at ~3,970 tok/s.
|
|
- GDN (540-600 ms): recurrence kernel 148-155 ms, QKV/Z/Out GEMMs 145-155 ms, weight dequantization 29 ms (fixed
|
|
per chunk), state staging (state_in/state_out) 80-115 ms; the finite-guard reuse (`f6b4822`) measured no gain.
|
|
- input 184 ms (KAR PLE gather, ~19 us/token with device round trips), init 198 ms (row staging).
|
|
|
|
### Expert stream overlap
|
|
|
|
`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`). 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`)
|
|
|
|
The page cache dominates there: the same Y binary went from TTFT 8.6-9.4 s (after the WSL restart) to 4.1-4.7 s
|
|
(warm, later runs). Paired runs Y/E and Y/G show no difference beyond that noise; outputs identical. Per-command
|
|
profile of an 80-token prompt (Esync): GDN 1.29 s per prompt, of which the per-layer weight dequantization is
|
|
0.80 s (QKV 10 ms, Z 4.7 ms, Out 7.4 ms per layer: the Original's one-thread-per-32-values kernel, ~6 GB/s on this
|
|
GPU) and state staging 0.26 s. With the conversation cache on by default (`--prompt-cache 6`), a chat prompt is
|
|
read as two batched chunks (to the last turn token, then the short tail): the tail chunk costs ~2.8 s of fixed
|
|
per-chunk work on the laptop, where the Original reads tails of <= 64 tokens with verify windows.
|
|
|
|
### Laptop, paired with the Original (same session, `~/LAPTOP_GPU.lock`, Original first)
|
|
|
|
docs/laptop-profile.md row-2 arguments for the Original (`--expert-cache auto --prefill auto --spec 4
|
|
--spec-min-p 0.5 --mtp --kv int8 --prompt-cache 0 --resident-experts` (falls back to mmap) + KAR PLE L2, 16 new
|
|
tokens, 2 passes); the port `e9b8a5e` with the VRAM tier auto + profile and the conversation cache off.
|
|
**Greedy outputs identical between the two engines on all three prompts (16 tokens).**
|
|
|
|
| engine | prefill tok/s pass 0 | pass 1 | TTFT s pass 0 | pass 1 |
|
|
| --- | --- | --- | --- | --- |
|
|
| Original | 2.9, 4.3, 7.7 | 7.0, 12.6, 16.4 | 32.2, 19.6, 10.2 | 13.8, 6.7, 4.9 |
|
|
| port `e9b8a5e` | 4.5, 8.6, 11.9 | 13.4, 15.2, 15.3 | 20.4, 10.4, 7.0 | 7.4, 5.9, 5.6 |
|
|
|
|
(The page cache dominates both: the earlier docs/laptop-profile.md run had the Original at 12.4 and the port at
|
|
3.1 tok/s; n = 6, indicative only.)
|
|
|
|
## Compute-stage kernels (branch `claude/prefill-kernels`)
|
|
|
|
Goal: the non-DMA compute of the batched prefill (input, init, GDN, QSA, GR reads and injections). Everything below is
|
|
exact: every change keeps the arithmetic expression of the kernel it replaces, and each is behind a switch so the same
|
|
binary measures old against new.
|
|
|
|
| change | switch (default on) | what it replaces |
|
|
| --- | --- | --- |
|
|
| chunk-wide KAR PLE + embedding staging | `LELEKA_PREFILL_STAGED_INPUT=0` | per token: 16-row scatter, 16-row decode, synchronous readback, host assembly and upload of the 10240-float residual row |
|
|
| guards folded into the producers | `LELEKA_PREFILL_FUSED_SCANS=0` | GR read/inject and GDN chain: a second pass over every 335 MB tensor just to scan it |
|
|
| element-parallel dequantization (GDN, QSA) | `LELEKA_PREFILL_FAST_DEQUANT=0` | one thread per 32 values, ~6 GB/s on the laptop |
|
|
| GDN chunk starts from the mirror's device state | `LELEKA_PREFILL_GDN_MIRROR=0` | canonical host state converted and uploaded for every layer of every chunk |
|
|
| two-barrier GDN recurrence (EXPERIMENTAL, off) | `LELEKA_PREFILL_FAST_REC=1` | `gdn_rec_cols_pipe_kernel` |
|
|
|
|
Input staging: the rows of a chunk (16 per token) are resolved against the cache map on the host, the packets of the
|
|
misses are read in parallel (`pread`, up to 32 threads), and one kernel decodes all of them straight into the arena's
|
|
PleEmbedding span; each distinct token's embedding row is decoded once, uploaded once, and broadcast to the four
|
|
residual streams by a kernel. `KarPleCache::stage_batch` evicts least recently used rows the chunk does not touch
|
|
(pure `lookup_rows`/`assign_slots`, unit tested with a tiny capacity). A non-finite value, bad slot or partition is
|
|
refused by the device flags with the same error class as the host path.
|
|
|
|
New sealed asset `crates/cuda-driver/src/prefill_stage.cu` (precise recipe, nvcc 13.2.86; `extra-seal-plan.json`
|
|
group `prefill-stage`, sm_86 companion in `ptx-sm86/`). Kernels: `leleka_prefill_ple_scatter`, `_ple_decode`,
|
|
`_embed_broadcast`, `_gr_norm_rs`, `_gr_mix_r`, `_gr_write_norm_rs`, `_gr_write`, `_dequant_{q8_0,q4_k,q5_k,q6_k,iq4_nl,iq4_xs}`,
|
|
`_gdn_conv_tiled`, `_gdn_l2`, `_gdn_out_norm`, `_gdn_rec`.
|
|
|
|
### Quality gates
|
|
|
|
- Model-free GPU probes (`LELEKA_PREFILL_STAGE_GPU=yes`, RTX 3080 laptop; the same tests run on the 5090 in job 960):
|
|
`staged_input_equals_the_per_token_kernels_bit_for_bit` (512,000 PLE values and the broadcast rows),
|
|
`gr_fused_guards_equal_the_separate_guard_kernels_bit_for_bit` (outputs and flag words, clean and with a non-finite R
|
|
word, gate word and an overflowing product), `gdn_stage_kernels_equal_the_originals_bit_for_bit` (all six dequantized
|
|
formats, convolution, L2 norm, output norm and their status words) and `gdn_recurrence_equals_the_original_bit_for_bit`
|
|
(t = 1, 7, 200, 1500 and an overflowing state): every comparison is identical bit for bit, maximum difference 0.
|
|
- `LELEKA_TRACE_PREFILL_R=1` prints an FNV-1a hash of the bits of every row of the chunk's final residual R (all four
|
|
streams, after 48 layers). On the laptop (prompts of 300, 1,200 and 2,600 tokens, chunks 299 / 1,199 / 2,048 / 551) the hash of every
|
|
chunk is identical between the all-switches-off arm and the default arm, and the 16 greedy output ids of the three
|
|
prompts are identical.
|
|
|
|
### RTX 5090 (job 961, one binary, tier off, greedy, 16 new tokens; `B` = the four switches off, `N` = defaults)
|
|
|
|
Greedy output ids of all 16 runs of `N` and `B` equal job 0708's (2048-token chunks: 8000 `271,248068,271,248069,...`,
|
|
16000 `271,248068,198,760,...`; 8192-token chunks: both prompts `271,248068,271,248069,...`). `LELEKA_TRACE_PREFILL_R=1`
|
|
(cap 8192): the FNV-1a hash of every row of the final residual R of each chunk is identical between `N` and `B`
|
|
(7999 rows `11c898a92de08a9b`; 8192 rows `7ea88178bf76c5a1`; 7807 rows `8a27594e2b566315`).
|
|
|
|
Prefill tok/s, two interleaved repetitions (`B` reproduces job 0708: 2,970 vs 2,941 at 16,000 tokens / 8192):
|
|
|
|
| chunk | tokens | B rep1 / rep2 | N rep1 / rep2 | gain |
|
|
| --- | --- | --- | --- | --- |
|
|
| 2048 | 8,000 | 1,096 / 1,168 | 1,298 / 1,300 | +15% |
|
|
| 2048 | 16,000 | 1,468 / 1,456 | 1,651 / 1,651 | +13% |
|
|
| 8192 | 8,000 (first prompt of the process) | 1,935 / 1,879 | 1,994 / 2,186 | +6%..+16% |
|
|
| 8192 | 16,000 | 2,971 / 2,969 | 3,735 / 3,715 | +25% |
|
|
|
|
Per 8192-token chunk (job 961 rep1, first chunk of the 8,000-token prompt; ms, host spans, expert DMA still not
|
|
overlapped): total 2,713 -> 2,158; input 178 -> 3; init 169 -> 1.5; attn_read 115 -> 68; ffn_read 114 -> 67; inject 125 -> 75;
|
|
gdn 548 -> 471 (compute 428 -> 365; state_in 38 -> 40, state_out 32 -> 34); qsa 253 -> 241; moe 1,303 -> 1,279 (ring 1,114
|
|
unchanged). The 16,000-token prompt's 7,807-token chunk: 2,671 -> 2,125.
|
|
|
|
Where the rest goes (job 961 `PROFILE_SYNC` arm, one chunk, ms): GDN cuBLAS GEMMs 152 (QKV 68, Z 43, Out 41; ~220 TFLOP/s,
|
|
at the hardware limit), recurrence 155, convolution 17, output norm 16, L2 6, dequantization 9 (was 29), GDN host row/state
|
|
bookkeeping ~75; QSA attention 113 (already tensor-core `mma`), index/norm/rope 38, Q projection 33, Out projection 17, KV
|
|
append 14; GR reads: mix 47, GEMMs 70; injection (write + next norm) 55. What is left outside the expert ring (~1.04 s) is
|
|
bandwidth-, tensor-core- or latency-bound; the per-stage host drains remain (claude/prefill-overlap).
|
|
|
|
### Laptop (RTX 3080, WSL2, mapped experts, VRAM tier auto + profile, KAR file; `~/LAPTOP_GPU.lock`)
|
|
|
|
Prompts of 300 / 1,200 / 2,600 tokens (the first 2,600 ids of job 0708's 8,000-token prompt), chunk 2,048, 16 greedy tokens,
|
|
`LELEKA_LAPTOP_PROMPT_CACHE=0`; ABAB of the all-switches-off arm and the defaults, two passes per process. Greedy outputs
|
|
of all runs are identical, and with `LELEKA_TRACE_PREFILL_R=1` the hash of the final residual of every chunk (299, 1,199, 2,048,
|
|
551 rows) is identical between the arms. Sum over the four chunks of the warm pass, mean of the two processes (ms):
|
|
|
|
| stage | switches off | defaults |
|
|
| --- | --- | --- |
|
|
| input + init | 588 | 9 |
|
|
| attn_read + ffn_read | 553 | 416 |
|
|
| inject | 288 | 211 |
|
|
| gdn (compute 1,192 -> 865; state_in 353 -> 288; state_out 331 -> 324) | 2,016 | 1,586 |
|
|
| qsa | 654 | 569 |
|
|
| moe.ring (expert bytes over PCIe/page cache: unchanged) | 19,204 | 19,650 |
|
|
|
|
The GDN weight dequantization, 0.80 s of a short prompt's GDN on this card, is now 36 ms per 2,048-token chunk
|
|
(`gdn#3/#5/#20`); end-to-end prefill tok/s moves by 0-5% because the expert DMA from the page cache is 85% of the time.
|
|
The remaining laptop-only costs are `input.ple` (random 20-byte reads of the 55 GB KAR file that is not in the page cache:
|
|
~0.5-1 s per prompt, 32 reader threads) and the 3 MB state download (`gdn.state_out`, WSL pageable copy).
|
|
|
|
Expert tier ON (job 962: `EXPERT_SLOTS=2048` per layer, profile, `PCIE_FRAC=0.55`; same binary, `B` = switches off). All greedy ids
|
|
equal job 0708's reference of the same chunking:
|
|
|
|
| chunk | tokens | B | N | gain |
|
|
| --- | --- | --- | --- | --- |
|
|
| 2048 | 8,000 / 16,000 | 1,178 / 1,477 | 1,316 / 1,685 | +12% / +14% |
|
|
| 8192 | 8,000 (rep1 / rep2) | 1,639 / 1,886 | 1,959 / 2,123 | +20% / +13% |
|
|
| 8192 | 16,000 (rep1 / rep2) | 2,897 / 2,902 | 3,606 / 3,627 | +24% / +25% |
|
|
|
|
`LELEKA_PREFILL_FAST_REC=1` (two-barrier recurrence), bit-identical on the 5090 probe (0.81 -> 0.71 ms at 1,500 tokens, one layer), measured
|
|
3,756 / 3,662 tok/s at 16,000 tokens (tier off / on) against 3,735 / 3,606 for the default: within noise at chunk level, so it stays
|
|
EXPERIMENTAL and off. Defaults of the other four switches are on. What remains: the expert DMA (claude/prefill-overlap), the GDN
|
|
recurrence (155 ms, a 128-step FMA chain per token that cannot be reordered without changing bits), cuBLAS GEMMs at the tensor-core
|
|
limit, per-layer host drains.
|
|
|
|
## Expert stream overlap (branch `claude/prefill-overlap`, jobs 950-968, RTX 5090)
|
|
|
|
Goal: hide the expert DMA of an 8192-token chunk (24,576 experts = 50.3 GB, i.e. every expert of all 48 layers at
|
|
2.05 MB; a 16,000-token prompt moves it twice) under the mixers. The per-layer ring paid it layer by layer (moe.ring
|
|
~1,110 ms of a 2,140 ms chunk after the prefill-kernels merge, 3,780 tok/s on 16,000 tokens).
|
|
|
|
### What blocked the overlap (and what was removed)
|
|
|
|
1. Every compute producer drained with `cuCtxSynchronize`, which also waits for the copy stream. All of them go through
|
|
`ffi::Api::synchronize`; while a chunk's expert stream runs (`compute_drain`, background stream registered by
|
|
`begin_prompt_stream`) it now waits for the legacy default stream and every registered compute stream except the
|
|
copy stream (all four stream creators register: Blas, Original schedule, owned copy, swap). Outside a chunk stream
|
|
it is the unchanged context-wide drain. The ring's own layer drain no longer syncs the copy stream either.
|
|
2. `cuMemFree` synchronizes the whole device (per-layer GDN/QSA/PLE scratch, 6 MB per GDN layer): frees are queued
|
|
on the `Context` while the stream runs and executed when it ends (or past `LELEKA_PREFILL_DEFER_FREE_MIB`, 512);
|
|
the ring's per-layer status buffer is pooled.
|
|
3. **The host-to-device copy engine is a FIFO.** Any other transfer of the compute path (synchronous H2D uploads,
|
|
D2H status readbacks) waits for all expert copies queued before it: model-free probe, job 955
|
|
(`scripts/h2d_copy_engine_probe.cu`): a 327 KB `cudaMemcpy` waits 0.13 ms behind 2 queued experts, 0.42 ms behind 8,
|
|
1.6 ms behind 32, 5.7 ms behind 128+ (= outstanding bytes / 36 GB/s); memsets, kernels and D2D copies do not queue.
|
|
With a deep queue the waits only moved from the ring into `moe.finish` (372 ms) and `inject` (650 ms) (job 953:
|
|
`PREFILL-SITE`/`PREFILL-STALL` call-site histograms). Fixes: an issuer thread (the Original's D-5) keeps only
|
|
`LELEKA_PREFILL_DEPTH` (default 2) entries outstanding on the copy stream, event-query paced, the compute thread
|
|
only waits until an entry is enqueued before ordering its stream after it; all-zero uploads become device memsets
|
|
while the stream runs (`LELEKA_PREFILL_ZERO_MEMSET=0` disables); the routed slot table (327 KB, non-zero) is
|
|
uploaded before the ring instead of after it.
|
|
4. Not done (open, see below): ~1,100 small blocking H2D/D2H calls per chunk remain (status readbacks, shared-layer
|
|
weight uploads, GDN state staging, QSA tables); each costs up to the queue depth in latency and keeps the depth at 2.
|
|
|
|
The stream copies *every* expert of every layer (prefill.cpp `stream_all`), while the per-layer ring copies only the
|
|
routed ones: at 2,048 rows only ~60% of the experts are routed, so the stream is 20% slower there (jobs 961/962:
|
|
1,330 vs 1,670 tok/s) and nearly free at 8,192 (~100% routed). It therefore starts at 4,096 rows
|
|
(`STRATA_PREFILL_STREAM_MIN`); `LELEKA_PREFILL_STREAM=0` restores the per-layer ring everywhere.
|
|
|
|
### Results (paired passes alternating inside one process, same binary and prompts, greedy 16 tokens)
|
|
|
|
| config | prompt | per-layer ring | expert stream | notes |
|
|
| --- | --- | --- | --- | --- |
|
|
| chunk 8192, tier off, depth 16 (job 960) | 8,000 | 3,764-3,784 | 4,367-4,406 | +16% |
|
|
| chunk 8192, tier off, depth 16 (job 960) | 16,000 | 3,780 | 4,275-4,358 | +13% |
|
|
| chunk 8192, tier off, depth sweep (job 958) | 16,000 | 3,795-3,799 | 2: 4,805-4,811; 4: 4,163-4,181; 8: 4,227-4,293; 16: 4,300-4,350; 32: 4,199 | depth 2 best |
|
|
| chunk 8192, tier off, depth 2, 12 passes (job 963) | 16,000 | - | 4,789-4,851 | +27% |
|
|
| chunk 8192, tier on (job 962, depth 16) | 8,000 / 16,000 | 3,573 / 3,625-3,686 | 4,499-4,528 / 4,631-4,654 | +26% |
|
|
| chunk 2048 (jobs 961/962, stream forced) | 8,000 / 16,000 | 1,670-1,718 / 1,659-1,711 | 1,325-1,380 / 1,324-1,384 | -20%: off below 4096 rows |
|
|
|
|
Greedy ids: identical between the two modes on every paired pass (8000 and 16000, chunk 8192 and 2048, tier off and
|
|
on) and equal to job 0708's ids for the same chunking. With the tier on the 16000-token answer at chunk 8192 is a
|
|
near-tie that the unmodified head already flips between passes (one OFF pass of job 962 answered `271,248069` instead
|
|
of `198`); the stream's passes all gave `198`. Race hunt (job 963): 36 consecutive full 16,000-token prefills
|
|
(12 plain, 12 with pseudo-random host delays between the copy enqueues `LELEKA_PREFILL_STREAM_JITTER`, 12 with the
|
|
same jitter at depth 1): identical ids, no `CudaExecution`. `compute-sanitizer` racecheck/synccheck only see
|
|
shared-memory hazards inside a kernel, which this change does not touch; the cross-stream ordering is by events
|
|
(`copied`/`used` per ring slot), and the repeated runs under jitter are the evidence.
|
|
|
|
### Copy rate, bytes per chunk, tier
|
|
|
|
Every 8192-row chunk streams 24,576 entries x 3 copies of 682 KB = 50.3 GB (job 950+ `PREFILL-COPY`: per-entry event
|
|
timing 35.5-36.5 GB/s, independent of queue depth and of concurrent kernels; `cudaHostAlloc` memory in the model-free
|
|
probe 40.3-40.9 GB/s for 3x682 KB, 1x2 MB, depth 4-64, 1-2 streams; the registered bank is ~12% slower). With the stream
|
|
the DMA is busy ~77% of the chunk (stream window 1.6-1.8 s for a 1.42 s copy floor at 35.5 GB/s). The VRAM expert tier
|
|
(2048 slots per layer, 1891 lent) removes only ~0.6% of the entries at chunk 8192 (24,419 vs 24,576) and 4.7% at 2048
|
|
(23,415): prefill with the tier streams essentially the same bytes. Chunk sizes above 8192 are not possible: the prompt
|
|
arena, GEMM and MMQ shape checks are capped at 8192 rows (30+ sites, 81920-row MMQ layouts); bytes per token fall 4x
|
|
from 2048 to 8192 as the per-chunk traffic is constant.
|
|
|
|
### Late chunks (180,000-token prompt, job 915/957)
|
|
|
|
Per-chunk time grows from 2,120 ms (position 0) to 2,480 ms (position 172k) on the unmodified head, of which QSA
|
|
250 -> 537 ms and moe.ring 1,117 -> 1,200 ms; GDN is flat. Per-command profile (job 957, 8 -> 90k -> 164k):
|
|
`qsa index+norm+rope run` 49 -> 167 -> 269 ms (the indexer scores every earlier block: ~1.4 ms per 1k positions per
|
|
chunk), `kv append` 15 -> 36 -> 54 ms, `attend` flat 124 ms, proj Q/out flat. The indexer is the stage that grows with
|
|
position; its kernels were not touched here.
|
|
|
|
### Final defaults and the 180k prompt (jobs 965-968)
|
|
|
|
- Queue depth (job 965, 16,000 tokens @8192, same process): depth 1 3,343; **2 4,805-4,821**; 3 4,238-4,310 tok/s
|
|
(per-layer ring 3,790); depth 2 is the default. The stream runs one expert (2 MB) ahead of its consumer, so the
|
|
copy engine is never idle for long but any other transfer waits at most ~2 MB / 36 GB/s.
|
|
- Shipped defaults vs `LELEKA_PREFILL_STREAM=0`, separate processes (job 966, second and third pass): chunk 8192
|
|
8,000 tokens 4,851 / 4,844 vs 3,760 / 3,766 tok/s, 16,000 tokens 4,820 / 4,816 vs 3,796 / 3,778; chunk 2048
|
|
identical (1,670 vs 1,671 / 1,656 vs 1,655: the stream is off below 4096 rows). All greedy ids equal.
|
|
- Chunk 4096 (job 967): stream = ring (2,598-2,601 vs 2,583-2,584 for 8,000 tokens; 2,593-2,598 vs 2,598 for 16,000),
|
|
ids equal: copying every expert costs what the overlap saves.
|
|
- 180,000 tokens, tier on, chunk 8192 (job 968, passes alternating in one process): stream 40.9 s / 39.9 s
|
|
(4,397 / 4,508 tok/s) vs ring 51.0 s (3,532 tok/s) = +25..28%; identical ids. Per chunk (position 8k / 82k / 164k):
|
|
stream 1,680 / 1,773 / 1,905 ms (qsa 272 / 398 / 530, moe.ring 539 / 582 / 581, gdn 464, inject 85) vs ring
|
|
2,080 / 2,320 / 2,473 ms (moe.ring 1,057 / 1,169 / 1,186). The unmodified Original needs 39.4 s for the same prompt.
|
|
What still grows with position is the QSA indexer (above) and, slightly, the ring.
|
|
|
|
### Merged copy path
|
|
|
|
`claude/ledger`'s page-aligned expert supersets (+12% on the ring: DMA 36 -> 47 GB/s) are merged into the stream:
|
|
stream entries carry the 4 KiB-aligned supersets, their slot offsets and the offsets of the exact pieces, and the
|
|
gather reads the exact pieces there (`LELEKA_PREFILL_ALIGNED_COPY=0` turns both paths off). The schedule agent's
|
|
deferred guard status (`LELEKA_PREFILL_DEFER_GUARDS=1`, experimental, default off; +1.6% in its A/B) is merged.
|
|
Open: runs of consecutive experts per role in one copy / `cuMemcpyBatchAsync` (50-51 GB/s in the roofline probes), the
|
|
~1,100 remaining blocking small copies per chunk, QSA indexer growth with position.
|