mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4937] [CLOSED] [Engine] Update: DFlash2 batched multi-slot drafting, co-draft body/head, and concurrent prefill fixes #5256
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5256
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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 testsfe5356b[Engine] DFlash2 batching 2/4: multi-slot drafter, batched co-draft head kernels and parity/bench checks0f3a807[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 tests0953d86batch(hip,dflash2): multi-row QSA/GDN, batched KV/idx appends, async PLE gather & co-draft overlapc224f4fFix review findings (bench buffers, DF2_DEPTH=auto, suffix thresholds) and Metal buildb9a575efix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission9ca84bdperf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admission1bf2243perf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY)0efa111perf(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 dflash2only served one CLI conversation on a single card:--servewith--batchcould 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-splithad no cross-stage tap handoff for prefill or verify windows,BGENadmission (max_new = 1) skipped the final prompt token (ids[n - 1]) tap and resetsl.sfx, and concurrent prompt prefill with--expert-cache-per-layerevicted 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):--serve --batch N --draft dflash2/--batch-dflash2): oneDflash2Drafterinstance serves up tokDf2MaxSlots = 8concurrent 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(8or16) are divided among slots with a draft ready (include/strata/core/batch_spec.hpp,include/strata/core/batch_spec_slots.hpp).--batch-dflash2): on a single card,--batch-dflash2defaults--batch-draft-windowto 8 rows (W=8, depth=1is fastest on one card:42.46 ms/win,167.8 rows/s,140.0-143.8 tok/sHTTP wall atc=4ongfx1201vs82.14 ms/win,129.2 rows/satW=16, depth=3). When--layer-splitis active,--batch-dflash2defaults--batch-draft-windowto 16 rows where wide windows are compiled in (amortizing stage handoffs on multi-cardgfx12and NVIDIA Blackwell setups; Intel SYCL, Apple Silicon M-series, and older NVIDIA cards still need per-window-size benchmarking).STRATA_DF2_BATCHBODY,STRATA_DF2_BATCHHEAD, default on) + Layer-36 context projection overlap (Verifier::set_taps_ready):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 acrosstotal_b = 8 * n_itemscolumns (gemm8_kernel<..., NCOLS, R>withR = 4forncols <= 16andR = 2forncols <= 32), reading the~435 MBof DFlash2 body weights once per window instead ofn_itemstimes (4.57 msfor 4 slots vs~12 msserial).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, launchingDflash2Drafter::precompute_batch_context(df2_rope_table,df2_quant_rows,fc.weight,hidden_norm, and 5x{k_proj, v_proj}) ondf2.stream()concurrently with target verify Layers 37–47 + output head, cutting post-verifyemittime to3.76-3.88 ms/winatc=2and5.46 ms/winatc=4.STRATA_DF2_BATCHHEADpacks 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 launchesdf2_select_multiondf2.stream()while overlappingver.wait_commit(Verifier::set_commit_async(stages.empty())).BGEN) bug fixes & device-to-deviceDflash2Drafter::copy_slot(a6a4d7c4,4c4ceef7):n - 1prompt token tap (df2.feed_context) and initial speculative draft (admit_df2_draft,admit_df2_ready = true) whenBGENrewrites admissionmax_new = 1(admit_max_new > 1), and preservessl.sfxacrosssl = BSlot{}.save_state/restore_stateround-trip onBGENadmission withDflash2Drafter::copy_slot(cudaMemcpy2Ddevice-to-device oncs_), cutting slot admission move time to~24 ms.--expert-cache-per-layerrank-major slot interleaving (c7cc3c4a,42864fcc):ExpertCache::configure_per_layer(c7cc3c4a) in rank-major order (slot = rank * n_layers + layer_idx) solend()borrowing the contiguous tail[slots() - need_p, slots())evicts the coldest-ranked experts evenly across all 48 layers (~7experts/layer at342borrowed slots) instead of wiping out 100% of resident experts in layers 42–47.batch_prefill_chunk(STRATA_BATCH_PREFILL_CHUNK, default2048on single GPU when batch slots are decoding), scalesbatch_decode_sharewith active slots (0.5at 1 slot,0.75at 2 slots,1.0at3+slots), and yields topiped_decodeafter every chunk including the final chunk whenbatch_on()is true (42864fcc).9711061f,src/core/verify.cpp,src/program/generate.cpp):STRATA_BATCH_ATTN_ROWS=1andSTRATA_BATCH_GDN_GROUPS=1on HIP (STRATA_BATCH_ATTN_ROWS=0/STRATA_BATCH_GDN_GROUPS=0disable) and adds per-slot groupedqsa_kv_resolvebetweenqsa_block_topkandqsa_decode_attn_batch_rows/qsa_decode_attn_slotsso multi-row QSA batch attention remains active under--kv-resident.kv_append_q8_steps/kv_append_q4_stepsandnative_qsa_indexer_append_stepsin bothVerifier::record_windowandVerifier::capture_commit_batch.gather_batch(ple_rows_b_,ple_pending_b_) out of synchronousVerifier::stage_batchintoVerifier::run_slot_rowsimmediately aftercudaGraphLaunch+cudaStreamQuery(cs_), overlapping host PLE table gathers with GPU Layer 0 execution.wait_flag_ge(m_flagB_),fetch_blobs,rebase_ptrs,grouped(p_ptr2)) when no layer uses a pinned PCIe complement (eff_pcie_mode = -1).STRATA_BATCH_DF2_DEPTH=auto|1|2|3andSTRATA_BATCH_DF2_DEPTH_FLOOR) & n-gram suffix co-drafter (--batch-suffix-draft N).--layer-splitwith 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,BGENadmission bug fixes, rank-major--expert-cache-per-layerslot lending, and concurrent prefill chunk pacing (STRATA_BATCH_PREFILL_CHUNK).Approach
a6a4d7c4..42864fcc) so individual bug fixes and performance layers can be reviewed or cherry-picked independently:a6a4d7c4fix(batch,dflash2): preserve n-1 prompt tap, initial draft & suffix drafter on BGEN admission4c4ceef7perf(batch,dflash2): add device-to-device Dflash2Drafter::copy_slot on BGEN admissiona8fccb1eperf(dflash2): batch context projection & 5-layer body across active slots (STRATA_DF2_BATCHBODY)900b60ceperf(verify,dflash2): overlap DFlash2 context projections with target verify layers 37-47c7cc3c4afix(expert-cache): interleave per-layer slots rank-major so prefill lend() borrows coldest experts evenly42864fccperf(batch,prefill): cap prefill chunk size and scale decode share when batch slots are activetests/core/andtests/program/plus GPU kernel parity checks indflash2_small_bench.Validation
Passed:
42864fcconorigin/main(c62d5e3a15b40ea51c96aae9e8d36928965f53ab, Strata0.2.9) on Linux7.3.0-2-cachyos-server(AMD Radeon AI PRO R9700gfx120132 GB VRAM, ROCm10.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 parityPASSacross all multi-slot kernels (select_multi,pack_head_rows,conv_rms_quant_batch,rms_quant_batch, anddf2_gemmforncols = 16, 24, 32).pytest tests/terminal/test_drafting.py->52 passed.c=2), 4-slot (c=4), and concurrent prefill (c=2 + 3,200-token prompt) serving benchmarks ongfx1201(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):50.90 ms/win(125.1 rows/s,105.4 tok/sHTTP wall =52.7 tok/s/slot); Warm R243.46 ms/win(144.6 rows/s,122.0 tok/sHTTP wall =61.0 tok/s/slot).42864fcc): Cold R143.28 ms/win(emit 3.76 ms) (145.2 rows/s,124.08 tok/sHTTP wall =62.04 tok/s/slot); Warm R239.77 ms/win(emit 3.88 ms,-8.5%) (159.9 rows/s+10.6%,132.96 tok/sHTTP wall =66.48 tok/s/slot,+9.0%).c=4(4 concurrent requests, 1024 tokens/burst):49.36 ms/win(run 39.32 + emit 9.54,148.5 rows/s,124.5 tok/sHTTP wall =31.1 tok/s/slot); Warm R249.20 ms/win(run 38.90 + emit 9.58,149.0 rows/s,125.6 tok/sHTTP wall =31.4 tok/s/slot).42864fcc): R142.46 ms/win(-14.0%,run 36.47 + emit 5.46) (167.8 rows/s+13.0%,140.00 tok/sHTTP wall =35.00 tok/s/slot,+12.5%); Warm R2143.76 tok/sHTTP wall (35.94 tok/s/slot,+14.5%).c=2active decode + concurrent3,200-token prompt prefill arrival (--expert-cache-per-layer):layer-majorexpert lending + un-chunked8192prefill):lend(8192)borrowed1,367slots (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.c7cc3c4arank-major lending +42864fccSTRATA_BATCH_PREFILL_CHUNK=2048): prefill chunks at2048tokens (borrowing only342slots =0.74 GiB,~7coldest experts/layer evenly across all 48 layers), yields1,069 mstopiped_decode(173tokens decoded mid-prefill), and sustains70.39 tok/saggregate decode (35.20 tok/s/slot,~4.4xfaster) simultaneously with1,532 tok/sprompt processing.Failed:
Not run:
--layer-splitruntime execution across 2+ cards (host has a singlegfx1201GPU; layer-split tap addressing, stage boundaries, and batch-group selection are verified viadflash2_tap_test,batch_groups_test,split_rules_test, andstage_reserve_test).Limits
Dflash2Draftercaps concurrent batch slots atkDf2MaxSlots = 8(STRATA_DF2_BATCHBODYbatches up to 4 active slots / 32 columns per launch and falls back to per-slot body graphs above 4 concurrent co-drafting slots);--batch > 8with--draft dflash2is clamped to 8 slots with a startup warning.--batch+--draft dflash2runs in 1 serial batch group (batch_groups::Serial::BatchDflash2), matching--batch-mtp.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.