[PR #4937] [CLOSED] [Engine] Update: DFlash2 batched multi-slot drafting, co-draft body/head, and concurrent prefill fixes #5256

Closed
opened 2026-11-07 16:33:50 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4937
Author: @bsorensen110
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: pr/dflash2-batch-optimizations


📝 Commits (10+)

  • ee47d1d [Engine] DFlash2 batching 1/4: header-only slot, row-split, adaptive-depth and tap rules with CPU tests
  • fe5356b [Engine] DFlash2 batching 2/4: multi-slot drafter, batched co-draft head kernels and parity/bench checks
  • 0f3a807 [Engine] DFlash2 batching 3/4: verifier and prefill support (layer-split taps, wider batch rows, 16-column MMVQ constants)
  • cdcbd03 [Engine] DFlash2 batching 4/4: wire batched multi-slot drafting into generate (--batch-dflash2), docs and terminal tests
  • 0953d86 batch(hip,dflash2): multi-row QSA/GDN, batched KV/idx appends, async PLE gather & co-draft overlap
  • c224f4f Fix review findings (bench buffers, DF2_DEPTH=auto, suffix thresholds) and Metal build
  • b9a575e fix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission
  • 9ca84bd perf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admission
  • 1bf2243 perf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY)
  • 0efa111 perf(verify,dflash2): overlap DFlash2 context projections with target verify layers 37-47

📊 Changes

48 files changed (+6472 additions, -517 deletions)

View changed files

📝 CMakeLists.txt (+22 -1)
📝 docs/BATCHING.md (+43 -0)
➕ docs/WAVE6-BATCH-THROUGHPUT-RESULTS-2026-11-02.md (+116 -0)
➕ include/strata/core/batch_dflash2_depth.hpp (+87 -0)
➕ include/strata/core/batch_spec.hpp (+140 -0)
➕ include/strata/core/batch_spec_slots.hpp (+273 -0)
📝 include/strata/core/dflash2.hpp (+139 -10)
➕ include/strata/core/dflash2_slots.hpp (+123 -0)
➕ include/strata/core/dflash2_tap.hpp (+60 -0)
📝 include/strata/core/expert_cache.hpp (+6 -0)
📝 include/strata/core/verify.hpp (+24 -9)
📝 include/strata/kernels/dflash2.hpp (+38 -4)
📝 include/strata/kernels/elementwise.hpp (+4 -0)
📝 include/strata/kernels/native_mmvq.hpp (+13 -5)
📝 include/strata/kernels/native_moe.hpp (+3 -0)
📝 include/strata/kernels/verify_kernels.hpp (+3 -0)
📝 include/strata/prefill/prefill.hpp (+9 -0)
📝 include/strata/program/batch_groups.hpp (+4 -1)
📝 include/strata/program/batch_read.hpp (+22 -0)
📝 include/strata/spec/suffix_drafter.hpp (+7 -0)

...and 28 more files

📄 Description

Problem and result

Before this change, --draft dflash2 only served one CLI conversation on a single card: --serve with --batch could not share one DFlash2 drafter across concurrent slots, co-drafting multiple slots after a batch verify window ran serial per-slot body+head rounds and blocked on synchronous prefix commits, batch verify windows on HIP ran per-row QSA attention (--kv-resident), per-slot GDN recurrences, and per-row KV/indexer appends, --layer-split had no cross-stage tap handoff for prefill or verify windows, BGEN admission (max_new = 1) skipped the final prompt token (ids[n - 1]) tap and reset sl.sfx, and concurrent prompt prefill with --expert-cache-per-layer evicted 100% of resident experts in the highest-numbered layers (lend() tail slice on layer-major slots).

With this change (structured as focused, cherry-pickable commits in 9711061f..42864fcc):

  • Multi-slot batched DFlash2 (--serve --batch N --draft dflash2 / --batch-dflash2): one Dflash2Drafter instance serves up to kDf2MaxSlots = 8 concurrent batch slots, each with its own K/V ring (df2_ring_bytes, df2_slots_fit) and captured round graphs (include/strata/core/dflash2_slots.hpp, src/core/dflash2.cpp). Every active slot gets its anchor row in the verify window, and remaining rows up to --batch-draft-window (8 or 16) are divided among slots with a draft ready (include/strata/core/batch_spec.hpp, include/strata/core/batch_spec_slots.hpp).
  • Window-size defaults per topology (--batch-dflash2): on a single card, --batch-dflash2 defaults --batch-draft-window to 8 rows (W=8, depth=1 is fastest on one card: 42.46 ms/win, 167.8 rows/s, 140.0-143.8 tok/s HTTP wall at c=4 on gfx1201 vs 82.14 ms/win, 129.2 rows/s at W=16, depth=3). When --layer-split is active, --batch-dflash2 defaults --batch-draft-window to 16 rows where wide windows are compiled in (amortizing stage handoffs on multi-card gfx12 and NVIDIA Blackwell setups; Intel SYCL, Apple Silicon M-series, and older NVIDIA cards still need per-window-size benchmarking).
  • Batched co-draft body & head (STRATA_DF2_BATCHBODY, STRATA_DF2_BATCHHEAD, default on) + Layer-36 context projection overlap (Verifier::set_taps_ready):
    • When 2..4 slots co-draft after a verify window on a single GPU, STRATA_DF2_BATCHBODY (a8fccb1e) runs the context projections (fc.weight, hidden_norm, k_proj/v_proj) and all 5 DFlash2 transformer layers (qkv_proj, o_proj, gate+up, down_proj, conv_rms_quant) in one multi-column pass across total_b = 8 * n_items columns (gemm8_kernel<..., NCOLS, R> with R = 4 for ncols <= 16 and R = 2 for ncols <= 32), reading the ~435 MB of DFlash2 body weights once per window instead of n_items times (4.57 ms for 4 slots vs ~12 ms serial).
    • Verifier::set_taps_ready (900b60ce) fires on the host immediately after target Layer 36 (the final DFlash2 tap layer [1, 10, 19, 28, 36]) completes on the verify stream, launching Dflash2Drafter::precompute_batch_context (df2_rope_table, df2_quant_rows, fc.weight, hidden_norm, and 5x {k_proj, v_proj}) on df2.stream() concurrently with target verify Layers 37–47 + output head, cutting post-verify emit time to 3.76-3.88 ms/win at c=2 and 5.46 ms/win at c=4.
    • STRATA_DF2_BATCHHEAD packs the selected rows (df2_pack_head_rows), runs a single multi-column native Q6_K/Q8_1 head GEMM (native_mmvq_il_tune(4) + native_q8_1_interleave), and launches df2_select_multi on df2.stream() while overlapping ver.wait_commit (Verifier::set_commit_async(stages.empty())).
  • Batch admission (BGEN) bug fixes & device-to-device Dflash2Drafter::copy_slot (a6a4d7c4, 4c4ceef7):
    • Preserves the n - 1 prompt token tap (df2.feed_context) and initial speculative draft (admit_df2_draft, admit_df2_ready = true) when BGEN rewrites admission max_new = 1 (admit_max_new > 1), and preserves sl.sfx across sl = BSlot{}.
    • Replaces the synchronous D2H+H2D save_state / restore_state round-trip on BGEN admission with Dflash2Drafter::copy_slot (cudaMemcpy2D device-to-device on cs_), cutting slot admission move time to ~24 ms.
  • Concurrent prefill & --expert-cache-per-layer rank-major slot interleaving (c7cc3c4a, 42864fcc):
    • Re-indexes ExpertCache::configure_per_layer (c7cc3c4a) in rank-major order (slot = rank * n_layers + layer_idx) so lend() borrowing the contiguous tail [slots() - need_p, slots()) evicts the coldest-ranked experts evenly across all 48 layers (~7 experts/layer at 342 borrowed slots) instead of wiping out 100% of resident experts in layers 42–47.
    • Adds batch_prefill_chunk (STRATA_BATCH_PREFILL_CHUNK, default 2048 on single GPU when batch slots are decoding), scales batch_decode_share with active slots (0.5 at 1 slot, 0.75 at 2 slots, 1.0 at 3+ slots), and yields to piped_decode after every chunk including the final chunk when batch_on() is true (42864fcc).
  • Batched verify window & commit launch reductions (9711061f, src/core/verify.cpp, src/program/generate.cpp):
    • Default-enables STRATA_BATCH_ATTN_ROWS=1 and STRATA_BATCH_GDN_GROUPS=1 on HIP (STRATA_BATCH_ATTN_ROWS=0 / STRATA_BATCH_GDN_GROUPS=0 disable) and adds per-slot grouped qsa_kv_resolve between qsa_block_topk and qsa_decode_attn_batch_rows / qsa_decode_attn_slots so multi-row QSA batch attention remains active under --kv-resident.
    • Groups contiguous per-slot rows for kv_append_q8_steps / kv_append_q4_steps and native_qsa_indexer_append_steps in both Verifier::record_window and Verifier::capture_commit_batch.
    • Moves Layer-0 host PLE gather_batch (ple_rows_b_, ple_pending_b_) out of synchronous Verifier::stage_batch into Verifier::run_slot_rows immediately after cudaGraphLaunch + cudaStreamQuery(cs_), overlapping host PLE table gathers with GPU Layer 0 execution.
    • Skips the 4 per-layer PCIe-share kernel nodes (wait_flag_ge(m_flagB_), fetch_blobs, rebase_ptrs, grouped(p_ptr2)) when no layer uses a pinned PCIe complement (eff_pcie_mode = -1).
  • Adaptive batch draft depth (STRATA_BATCH_DF2_DEPTH=auto|1|2|3 and STRATA_BATCH_DF2_DEPTH_FLOOR) & n-gram suffix co-drafter (--batch-suffix-draft N).
  • Layer-split support (--layer-split with solo and batch DFlash2): portable mapped tap buffers (dflash2_stage_taps_active, dflash2_tap_slot_in_stage, dflash2_tap_row_offset) across stages.

Builds on and coordinates with open PRs #3869 ([Engine] --draft dflash2 when serving, on one card and on a layer split (opt-in)) and #3882 ([Engine] Port the DFlash2 drafter onto the serve solo stream), extending serve-mode DFlash2 with multi-slot batch drafting (--batch-dflash2), the batched co-draft body & head (STRATA_DF2_BATCHBODY, STRATA_DF2_BATCHHEAD), Layer-36 context projection overlap, BGEN admission bug fixes, rank-major --expert-cache-per-layer slot lending, and concurrent prefill chunk pacing (STRATA_BATCH_PREFILL_CHUNK).

Approach

  • Small, self-contained atomic commits (a6a4d7c4..42864fcc) so individual bug fixes and performance layers can be reviewed or cherry-picked independently:
    1. a6a4d7c4 fix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission
    2. 4c4ceef7 perf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admission
    3. a8fccb1e perf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY)
    4. 900b60ce perf(verify,dflash2): overlap DFlash2 context projections with target verify layers 37-47
    5. c7cc3c4a fix(expert-cache): interleave per-layer slots rank-major so prefill lend() borrows coldest experts evenly
    6. 42864fcc perf(batch,prefill): cap prefill chunk size and scale decode share when batch slots are active
  • Pure header helpers + standalone unit tests: sizing, slot fitting, window packing, adaptive depth EWMA, stage tap offset arithmetic, rank-major per-layer slot ordering, and concurrent prefill chunk/share pacing are covered by unit tests in tests/core/ and tests/program/ plus GPU kernel parity checks in dflash2_small_bench.

Validation

Passed:

  • Revision 42864fcc on origin/main (c62d5e3a15b40ea51c96aae9e8d36928965f53ab, Strata 0.2.9) on Linux 7.3.0-2-cachyos-server (AMD Radeon AI PRO R9700 gfx1201 32 GB VRAM, ROCm 10.2.0a20260914, 64 GB RAM):
  • cmake --build build-hip --target strata dflash2_small_bench dflash2_parity dflash2_slots_test dflash2_tap_test batch_spec_test batch_spec_slots_test batch_dflash2_depth_test suffix_drafter_test batch_groups_test expert_cache_per_layer_test batch_read_test -j8 -> all targets built cleanly.
  • ctest --test-dir build-hip --output-on-failure -R '^(dflash2_slots_test|dflash2_tap_test|batch_spec_test|batch_spec_slots_test|batch_dflash2_depth_test|suffix_drafter_test|batch_groups_test|expert_cache_per_layer_test|batch_read_test)$' -> 100% tests passed out of 9.
  • ./build-hip/dflash2_small_bench -> bitwise parity PASS across all multi-slot kernels (select_multi, pack_head_rows, conv_rms_quant_batch, rms_quant_batch, and df2_gemm for ncols = 16, 24, 32).
  • pytest tests/terminal/test_drafting.py -> 52 passed.
  • Live 2-slot (c=2), 4-slot (c=4), and concurrent prefill (c=2 + 3,200-token prompt) serving benchmarks on gfx1201 (swift-1.5-iq3_s, --serve --batch 4 --draft dflash2 --dflash-no-mtp --mtp-draft-vocab draft_vocab.bin --batch-draft-window 8 --batch-draft-depth 1, 256 greedy tokens/request):
    • c=2 (2 concurrent requests, 512 tokens/burst):
      • Baseline (serial co-draft, per-row batch QSA/GDN/KV): Cold R1 50.90 ms/win (125.1 rows/s, 105.4 tok/s HTTP wall = 52.7 tok/s/slot); Warm R2 43.46 ms/win (144.6 rows/s, 122.0 tok/s HTTP wall = 61.0 tok/s/slot).
      • Optimized (42864fcc): Cold R1 43.28 ms/win (emit 3.76 ms) (145.2 rows/s, 124.08 tok/s HTTP wall = 62.04 tok/s/slot); Warm R2 39.77 ms/win (emit 3.88 ms, -8.5%) (159.9 rows/s +10.6%, 132.96 tok/s HTTP wall = 66.48 tok/s/slot, +9.0%).
    • c=4 (4 concurrent requests, 1024 tokens/burst):
      • Baseline (serial co-draft, per-row batch QSA/GDN/KV): Cold R1 49.36 ms/win (run 39.32 + emit 9.54, 148.5 rows/s, 124.5 tok/s HTTP wall = 31.1 tok/s/slot); Warm R2 49.20 ms/win (run 38.90 + emit 9.58, 149.0 rows/s, 125.6 tok/s HTTP wall = 31.4 tok/s/slot).
      • Optimized (42864fcc): R1 42.46 ms/win (-14.0%, run 36.47 + emit 5.46) (167.8 rows/s +13.0%, 140.00 tok/s HTTP wall = 35.00 tok/s/slot, +12.5%); Warm R2 143.76 tok/s HTTP wall (35.94 tok/s/slot, +14.5%).
    • c=2 active decode + concurrent 3,200-token prompt prefill arrival (--expert-cache-per-layer):
      • Before (layer-major expert lending + un-chunked 8192 prefill): lend(8192) borrowed 1,367 slots (2.96 GiB), evicting 100% of resident experts in layers 42–47 for the entire prompt read and collapsing concurrent decode to ~8 tok/s/slot.
      • After (c7cc3c4a rank-major lending + 42864fcc STRATA_BATCH_PREFILL_CHUNK=2048): prefill chunks at 2048 tokens (borrowing only 342 slots = 0.74 GiB, ~7 coldest experts/layer evenly across all 48 layers), yields 1,069 ms to piped_decode (173 tokens decoded mid-prefill), and sustains 70.39 tok/s aggregate decode (35.20 tok/s/slot, ~4.4x faster) simultaneously with 1,532 tok/s prompt processing.

Failed:

  • none observed

Not run:

  • Multi-GPU physical --layer-split runtime execution across 2+ cards (host has a single gfx1201 GPU; layer-split tap addressing, stage boundaries, and batch-group selection are verified via dflash2_tap_test, batch_groups_test, split_rules_test, and stage_reserve_test).
  • CUDA, SYCL, and Apple Silicon M-series hardware builds and per-window-size (8 vs 16-row) runtime sweeps.

Limits

  • One Dflash2Drafter caps concurrent batch slots at kDf2MaxSlots = 8 (STRATA_DF2_BATCHBODY batches up to 4 active slots / 32 columns per launch and falls back to per-slot body graphs above 4 concurrent co-drafting slots); --batch > 8 with --draft dflash2 is clamped to 8 slots with a startup warning.
  • Layer-split with --batch + --draft dflash2 runs in 1 serial batch group (batch_groups::Serial::BatchDflash2), matching --batch-mtp.
  • Parked conversations do not serialize DFlash2 K/V rings into the conversation cache; a conversation resumed from the park cache re-primes its DFlash2 ring from its own committed rows.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4937 **Author:** [@bsorensen110](https://github.com/bsorensen110) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/dflash2-batch-optimizations` --- ### 📝 Commits (10+) - [`ee47d1d`](https://github.com/Niko1221/Strata/commit/ee47d1d610b221a512afe89ed9cdfdd65cfe7162) [Engine] DFlash2 batching 1/4: header-only slot, row-split, adaptive-depth and tap rules with CPU tests - [`fe5356b`](https://github.com/Niko1221/Strata/commit/fe5356b77f5655a2bae1c9580a8c7fa9c4b9bb82) [Engine] DFlash2 batching 2/4: multi-slot drafter, batched co-draft head kernels and parity/bench checks - [`0f3a807`](https://github.com/Niko1221/Strata/commit/0f3a8074251bb470692b3284ac1b73366c6cbeb7) [Engine] DFlash2 batching 3/4: verifier and prefill support (layer-split taps, wider batch rows, 16-column MMVQ constants) - [`cdcbd03`](https://github.com/Niko1221/Strata/commit/cdcbd030a8d8d8a0e844308e03f204ed1ae108b1) [Engine] DFlash2 batching 4/4: wire batched multi-slot drafting into generate (--batch-dflash2), docs and terminal tests - [`0953d86`](https://github.com/Niko1221/Strata/commit/0953d86b36d367ef118b66f38d2359d8e2ead9fd) batch(hip,dflash2): multi-row QSA/GDN, batched KV/idx appends, async PLE gather & co-draft overlap - [`c224f4f`](https://github.com/Niko1221/Strata/commit/c224f4fd891b04c22f13033595e7419f3dcb8874) Fix review findings (bench buffers, DF2_DEPTH=auto, suffix thresholds) and Metal build - [`b9a575e`](https://github.com/Niko1221/Strata/commit/b9a575e857856741e18ffa1d5e97aa306394ee1b) fix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission - [`9ca84bd`](https://github.com/Niko1221/Strata/commit/9ca84bdf9629cd41c69a33f96c8e09ff8eae8ccd) perf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admission - [`1bf2243`](https://github.com/Niko1221/Strata/commit/1bf22437fadf9e80d97dd0b664e2da1ed325b4e0) perf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY) - [`0efa111`](https://github.com/Niko1221/Strata/commit/0efa111b05d0bbe1697af35ca02109e49aaebaa3) perf(verify,dflash2): overlap DFlash2 context projections with target verify layers 37-47 ### 📊 Changes **48 files changed** (+6472 additions, -517 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+22 -1) 📝 `docs/BATCHING.md` (+43 -0) ➕ `docs/WAVE6-BATCH-THROUGHPUT-RESULTS-2026-11-02.md` (+116 -0) ➕ `include/strata/core/batch_dflash2_depth.hpp` (+87 -0) ➕ `include/strata/core/batch_spec.hpp` (+140 -0) ➕ `include/strata/core/batch_spec_slots.hpp` (+273 -0) 📝 `include/strata/core/dflash2.hpp` (+139 -10) ➕ `include/strata/core/dflash2_slots.hpp` (+123 -0) ➕ `include/strata/core/dflash2_tap.hpp` (+60 -0) 📝 `include/strata/core/expert_cache.hpp` (+6 -0) 📝 `include/strata/core/verify.hpp` (+24 -9) 📝 `include/strata/kernels/dflash2.hpp` (+38 -4) 📝 `include/strata/kernels/elementwise.hpp` (+4 -0) 📝 `include/strata/kernels/native_mmvq.hpp` (+13 -5) 📝 `include/strata/kernels/native_moe.hpp` (+3 -0) 📝 `include/strata/kernels/verify_kernels.hpp` (+3 -0) 📝 `include/strata/prefill/prefill.hpp` (+9 -0) 📝 `include/strata/program/batch_groups.hpp` (+4 -1) 📝 `include/strata/program/batch_read.hpp` (+22 -0) 📝 `include/strata/spec/suffix_drafter.hpp` (+7 -0) _...and 28 more files_ </details> ### 📄 Description ## Problem and result Before this change, `--draft dflash2` only served one CLI conversation on a single card: `--serve` with `--batch` could not share one DFlash2 drafter across concurrent slots, co-drafting multiple slots after a batch verify window ran serial per-slot body+head rounds and blocked on synchronous prefix commits, batch verify windows on HIP ran per-row QSA attention (`--kv-resident`), per-slot GDN recurrences, and per-row KV/indexer appends, `--layer-split` had no cross-stage tap handoff for prefill or verify windows, `BGEN` admission (`max_new = 1`) skipped the final prompt token (`ids[n - 1]`) tap and reset `sl.sfx`, and concurrent prompt prefill with `--expert-cache-per-layer` evicted 100% of resident experts in the highest-numbered layers (`lend()` tail slice on layer-major slots). With this change (structured as focused, cherry-pickable commits in `9711061f..42864fcc`): - **Multi-slot batched DFlash2 (`--serve --batch N --draft dflash2` / `--batch-dflash2`):** one `Dflash2Drafter` instance serves up to `kDf2MaxSlots = 8` concurrent batch slots, each with its own K/V ring (`df2_ring_bytes`, `df2_slots_fit`) and captured round graphs (`include/strata/core/dflash2_slots.hpp`, `src/core/dflash2.cpp`). Every active slot gets its anchor row in the verify window, and remaining rows up to `--batch-draft-window` (`8` or `16`) are divided among slots with a draft ready (`include/strata/core/batch_spec.hpp`, `include/strata/core/batch_spec_slots.hpp`). - **Window-size defaults per topology (`--batch-dflash2`):** on a single card, `--batch-dflash2` defaults `--batch-draft-window` to **8** rows (`W=8, depth=1` is fastest on one card: `42.46 ms/win`, `167.8 rows/s`, `140.0-143.8 tok/s` HTTP wall at `c=4` on `gfx1201` vs `82.14 ms/win`, `129.2 rows/s` at `W=16, depth=3`). When `--layer-split` is active, `--batch-dflash2` defaults `--batch-draft-window` to **16** rows where wide windows are compiled in (amortizing stage handoffs on multi-card `gfx12` and NVIDIA Blackwell setups; Intel SYCL, Apple Silicon M-series, and older NVIDIA cards still need per-window-size benchmarking). - **Batched co-draft body & head (`STRATA_DF2_BATCHBODY`, `STRATA_DF2_BATCHHEAD`, default on) + Layer-36 context projection overlap (`Verifier::set_taps_ready`):** - When 2..4 slots co-draft after a verify window on a single GPU, `STRATA_DF2_BATCHBODY` (`a8fccb1e`) runs the context projections (`fc.weight`, `hidden_norm`, `k_proj/v_proj`) and all 5 DFlash2 transformer layers (`qkv_proj`, `o_proj`, `gate+up`, `down_proj`, `conv_rms_quant`) in one multi-column pass across `total_b = 8 * n_items` columns (`gemm8_kernel<..., NCOLS, R>` with `R = 4` for `ncols <= 16` and `R = 2` for `ncols <= 32`), reading the `~435 MB` of DFlash2 body weights once per window instead of `n_items` times (`4.57 ms` for 4 slots vs `~12 ms` serial). - `Verifier::set_taps_ready` (`900b60ce`) fires on the host immediately after target Layer 36 (the final DFlash2 tap layer `[1, 10, 19, 28, 36]`) completes on the verify stream, launching `Dflash2Drafter::precompute_batch_context` (`df2_rope_table`, `df2_quant_rows`, `fc.weight`, `hidden_norm`, and 5x `{k_proj, v_proj}`) on `df2.stream()` concurrently with target verify Layers 37–47 + output head, cutting post-verify `emit` time to `3.76-3.88 ms/win` at `c=2` and `5.46 ms/win` at `c=4`. - `STRATA_DF2_BATCHHEAD` packs the selected rows (`df2_pack_head_rows`), runs a single multi-column native Q6_K/Q8_1 head GEMM (`native_mmvq_il_tune(4)` + `native_q8_1_interleave`), and launches `df2_select_multi` on `df2.stream()` while overlapping `ver.wait_commit` (`Verifier::set_commit_async(stages.empty())`). - **Batch admission (`BGEN`) bug fixes & device-to-device `Dflash2Drafter::copy_slot` (`a6a4d7c4`, `4c4ceef7`):** - Preserves the `n - 1` prompt token tap (`df2.feed_context`) and initial speculative draft (`admit_df2_draft`, `admit_df2_ready = true`) when `BGEN` rewrites admission `max_new = 1` (`admit_max_new > 1`), and preserves `sl.sfx` across `sl = BSlot{}`. - Replaces the synchronous D2H+H2D `save_state` / `restore_state` round-trip on `BGEN` admission with `Dflash2Drafter::copy_slot` (`cudaMemcpy2D` device-to-device on `cs_`), cutting slot admission move time to `~24 ms`. - **Concurrent prefill & `--expert-cache-per-layer` rank-major slot interleaving (`c7cc3c4a`, `42864fcc`):** - Re-indexes `ExpertCache::configure_per_layer` (`c7cc3c4a`) in rank-major order (`slot = rank * n_layers + layer_idx`) so `lend()` borrowing the contiguous tail `[slots() - need_p, slots())` evicts the coldest-ranked experts evenly across all 48 layers (`~7` experts/layer at `342` borrowed slots) instead of wiping out 100% of resident experts in layers 42–47. - Adds `batch_prefill_chunk` (`STRATA_BATCH_PREFILL_CHUNK`, default `2048` on single GPU when batch slots are decoding), scales `batch_decode_share` with active slots (`0.5` at 1 slot, `0.75` at 2 slots, `1.0` at `3+` slots), and yields to `piped_decode` after every chunk including the final chunk when `batch_on()` is true (`42864fcc`). - **Batched verify window & commit launch reductions (`9711061f`, `src/core/verify.cpp`, `src/program/generate.cpp`):** - Default-enables `STRATA_BATCH_ATTN_ROWS=1` and `STRATA_BATCH_GDN_GROUPS=1` on HIP (`STRATA_BATCH_ATTN_ROWS=0` / `STRATA_BATCH_GDN_GROUPS=0` disable) and adds per-slot grouped `qsa_kv_resolve` between `qsa_block_topk` and `qsa_decode_attn_batch_rows` / `qsa_decode_attn_slots` so multi-row QSA batch attention remains active under `--kv-resident`. - Groups contiguous per-slot rows for `kv_append_q8_steps` / `kv_append_q4_steps` and `native_qsa_indexer_append_steps` in both `Verifier::record_window` and `Verifier::capture_commit_batch`. - Moves Layer-0 host PLE `gather_batch` (`ple_rows_b_`, `ple_pending_b_`) out of synchronous `Verifier::stage_batch` into `Verifier::run_slot_rows` immediately after `cudaGraphLaunch` + `cudaStreamQuery(cs_)`, overlapping host PLE table gathers with GPU Layer 0 execution. - Skips the 4 per-layer PCIe-share kernel nodes (`wait_flag_ge(m_flagB_)`, `fetch_blobs`, `rebase_ptrs`, `grouped(p_ptr2)`) when no layer uses a pinned PCIe complement (`eff_pcie_mode = -1`). - **Adaptive batch draft depth (`STRATA_BATCH_DF2_DEPTH=auto|1|2|3` and `STRATA_BATCH_DF2_DEPTH_FLOOR`) & n-gram suffix co-drafter (`--batch-suffix-draft N`).** - **Layer-split support (`--layer-split` with solo and batch DFlash2):** portable mapped tap buffers (`dflash2_stage_taps_active`, `dflash2_tap_slot_in_stage`, `dflash2_tap_row_offset`) across stages. ## Related discussion Builds on and coordinates with open PRs #3869 (`[Engine] --draft dflash2 when serving, on one card and on a layer split (opt-in)`) and #3882 (`[Engine] Port the DFlash2 drafter onto the serve solo stream`), extending serve-mode DFlash2 with multi-slot batch drafting (`--batch-dflash2`), the batched co-draft body & head (`STRATA_DF2_BATCHBODY`, `STRATA_DF2_BATCHHEAD`), Layer-36 context projection overlap, `BGEN` admission bug fixes, rank-major `--expert-cache-per-layer` slot lending, and concurrent prefill chunk pacing (`STRATA_BATCH_PREFILL_CHUNK`). ## Approach - **Small, self-contained atomic commits (`a6a4d7c4..42864fcc`)** so individual bug fixes and performance layers can be reviewed or cherry-picked independently: 1. `a6a4d7c4` `fix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission` 2. `4c4ceef7` `perf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admission` 3. `a8fccb1e` `perf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY)` 4. `900b60ce` `perf(verify,dflash2): overlap DFlash2 context projections with target verify layers 37-47` 5. `c7cc3c4a` `fix(expert-cache): interleave per-layer slots rank-major so prefill lend() borrows coldest experts evenly` 6. `42864fcc` `perf(batch,prefill): cap prefill chunk size and scale decode share when batch slots are active` - **Pure header helpers + standalone unit tests:** sizing, slot fitting, window packing, adaptive depth EWMA, stage tap offset arithmetic, rank-major per-layer slot ordering, and concurrent prefill chunk/share pacing are covered by unit tests in `tests/core/` and `tests/program/` plus GPU kernel parity checks in `dflash2_small_bench`. ## Validation **Passed:** - Revision `42864fcc` on `origin/main` (`c62d5e3a15b40ea51c96aae9e8d36928965f53ab`, Strata `0.2.9`) on Linux `7.3.0-2-cachyos-server` (AMD Radeon AI PRO R9700 `gfx1201` 32 GB VRAM, ROCm `10.2.0a20260914`, 64 GB RAM): - `cmake --build build-hip --target strata dflash2_small_bench dflash2_parity dflash2_slots_test dflash2_tap_test batch_spec_test batch_spec_slots_test batch_dflash2_depth_test suffix_drafter_test batch_groups_test expert_cache_per_layer_test batch_read_test -j8` -> all targets built cleanly. - `ctest --test-dir build-hip --output-on-failure -R '^(dflash2_slots_test|dflash2_tap_test|batch_spec_test|batch_spec_slots_test|batch_dflash2_depth_test|suffix_drafter_test|batch_groups_test|expert_cache_per_layer_test|batch_read_test)$'` -> `100% tests passed out of 9`. - `./build-hip/dflash2_small_bench` -> bitwise parity `PASS` across all multi-slot kernels (`select_multi`, `pack_head_rows`, `conv_rms_quant_batch`, `rms_quant_batch`, and `df2_gemm` for `ncols = 16, 24, 32`). - `pytest tests/terminal/test_drafting.py` -> `52 passed`. - Live 2-slot (`c=2`), 4-slot (`c=4`), and concurrent prefill (`c=2 + 3,200-token prompt`) serving benchmarks on `gfx1201` (`swift-1.5-iq3_s`, `--serve --batch 4 --draft dflash2 --dflash-no-mtp --mtp-draft-vocab draft_vocab.bin --batch-draft-window 8 --batch-draft-depth 1`, 256 greedy tokens/request): - **`c=2` (2 concurrent requests, 512 tokens/burst):** - Baseline (serial co-draft, per-row batch QSA/GDN/KV): Cold R1 `50.90 ms/win` (`125.1 rows/s`, `105.4 tok/s` HTTP wall = `52.7 tok/s/slot`); Warm R2 `43.46 ms/win` (`144.6 rows/s`, `122.0 tok/s` HTTP wall = `61.0 tok/s/slot`). - Optimized (`42864fcc`): Cold R1 **`43.28 ms/win` (`emit 3.76 ms`)** (`145.2 rows/s`, **`124.08 tok/s`** HTTP wall = **`62.04 tok/s/slot`**); Warm R2 **`39.77 ms/win` (`emit 3.88 ms`, `-8.5%`)** (`159.9 rows/s` `+10.6%`, **`132.96 tok/s`** HTTP wall = **`66.48 tok/s/slot`**, `+9.0%`). - **`c=4` (4 concurrent requests, 1024 tokens/burst):** - Baseline (serial co-draft, per-row batch QSA/GDN/KV): Cold R1 `49.36 ms/win` (`run 39.32 + emit 9.54`, `148.5 rows/s`, `124.5 tok/s` HTTP wall = `31.1 tok/s/slot`); Warm R2 `49.20 ms/win` (`run 38.90 + emit 9.58`, `149.0 rows/s`, `125.6 tok/s` HTTP wall = `31.4 tok/s/slot`). - Optimized (`42864fcc`): R1 **`42.46 ms/win` (`-14.0%`, `run 36.47 + emit 5.46`)** (`167.8 rows/s` `+13.0%`, **`140.00 tok/s`** HTTP wall = **`35.00 tok/s/slot`**, `+12.5%`); Warm R2 **`143.76 tok/s`** HTTP wall (**`35.94 tok/s/slot`**, `+14.5%`). - **`c=2` active decode + concurrent `3,200`-token prompt prefill arrival (`--expert-cache-per-layer`):** - Before (`layer-major` expert lending + un-chunked `8192` prefill): `lend(8192)` borrowed `1,367` slots (`2.96 GiB`), evicting 100% of resident experts in layers 42–47 for the entire prompt read and collapsing concurrent decode to `~8 tok/s/slot`. - After (`c7cc3c4a` rank-major lending + `42864fcc` `STRATA_BATCH_PREFILL_CHUNK=2048`): prefill chunks at `2048` tokens (borrowing only `342` slots = `0.74 GiB`, `~7` coldest experts/layer evenly across all 48 layers), yields `1,069 ms` to `piped_decode` (`173` tokens decoded mid-prefill), and sustains **`70.39 tok/s` aggregate decode (`35.20 tok/s/slot`, `~4.4x` faster) simultaneously with `1,532 tok/s` prompt processing**. **Failed:** - none observed **Not run:** - Multi-GPU physical `--layer-split` runtime execution across 2+ cards (host has a single `gfx1201` GPU; layer-split tap addressing, stage boundaries, and batch-group selection are verified via `dflash2_tap_test`, `batch_groups_test`, `split_rules_test`, and `stage_reserve_test`). - CUDA, SYCL, and Apple Silicon M-series hardware builds and per-window-size (8 vs 16-row) runtime sweeps. ## Limits - One `Dflash2Drafter` caps concurrent batch slots at `kDf2MaxSlots = 8` (`STRATA_DF2_BATCHBODY` batches up to 4 active slots / 32 columns per launch and falls back to per-slot body graphs above 4 concurrent co-drafting slots); `--batch > 8` with `--draft dflash2` is clamped to 8 slots with a startup warning. - Layer-split with `--batch` + `--draft dflash2` runs in 1 serial batch group (`batch_groups::Serial::BatchDflash2`), matching `--batch-mtp`. - Parked conversations do not serialize DFlash2 K/V rings into the conversation cache; a conversation resumed from the park cache re-primes its DFlash2 ring from its own committed rows. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:33:50 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5256
No description provided.