[PR #3869] [Engine] --draft dflash2 when serving, on one card and on a layer split (opt-in) #4808

Open
opened 2026-11-07 15:39:11 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3869
Author: @stuchapin909
Created: 10/23/2026
Status: 🔄 Open

Base: main ← Head: pr/dflash2-serve-split


📝 Commits (1)

  • 5f436de engine: --draft dflash2 when serving, on one card and on a layer split (opt-in)

📊 Changes

8 files changed (+425 additions, -115 deletions)

View changed files

📝 docs/MULTI_GPU.md (+35 -0)
📝 include/strata/core/verify.hpp (+10 -3)
📝 include/strata/prefill/prefill.hpp (+6 -1)
📝 src/core/verify.cpp (+16 -5)
📝 src/prefill/prefill.cpp (+49 -11)
📝 src/program/generate.cpp (+306 -94)
📝 strata_control/drafting.py (+1 -1)
📝 tests/terminal/test_drafting.py (+2 -0)

📄 Description

Problem and result

--draft dflash2 (merged in f-023-df2) runs only in the CLI on one card: with --serve or a layer split the engine prints "it is for one card and the CLI run" and drafts with the MTP. The 0.2.3 notes say the app will offer DFlash2 "once the engine serves it". This adds that, opt-in: --serve --draft dflash2 --draft-model PACK now drafts with DFlash2 on one card and on a layer split of two or more cards, with or without --pipeline-windows 2. Without --draft dflash2 nothing changes.

Result on 2x RTX 3090 (the hardware the maintainers do not have): it works, the text is the target model's, and it is not faster here. DFlash2 decodes 1.8% slower than the MTP on a two-card split, mean of 5 prompt types x 6 runs; on one card 4% slower (one round). So the MTP stays the default and this PR changes no default. Measurements below.

  • 0.2.3 release notes: "The app offers Auto, MTP and Off only; it will show DFlash2 once the engine serves it."
  • #3322 (j-luwierski's DFlash2 PR, CUDA only, one card) and Gamal-ElDeen's measurements there; on 10-21 others noted DFlash2 had "NOT run on Windows or multi-GPU". This is that run.
  • No scope agreement yet for serve / layer-split support: opened as a draft for that reason and for the backends I could not build (below).

Approach

  • Taps across stages. The drafter reads the completed outputs of layers 5, 15, 25, 35, 45. On a split the front stage's verifier writes its tapped layers into a mapped, portable host buffer (Verifier::set_taps(layers, shared_map, ext_dev)); the last stage's record_window copies those rows into its own tap_dev at the start of its part of the window. The odd (pipelined) verifiers get their own mapped buffer. Prompt reading does the same per chunk: a front Prefill writes its taps into pinned host hand-off buffers (double-buffered with the existing hand_buf_) and the next stage uploads them before its layers run.
  • Drafter on the last card, beside the head (df2.load(..., last_st->dev)), so df2.draft(ver.tap_dev(), ...) reads device memory on its own card.
  • --serve loops. The serial decode loop drafts with df2.draft in place of mtp.draft (with the PLE row prefetch the MTP path does). In the pipelined loop, when a window is accepted whole, the drafter drafts from the verified window's taps and the next guessed window is built from that block (make_b); after a partial accept it drafts from the accepted rows. Prompt windows and merged first windows feed df2.context.
  • The MTP layer is not loaded when serving with DFlash2 (its VRAM goes to the expert cache). So a late failure (bind / prepare) stops the server with --draft dflash2: <reason> (start without --draft dflash2 for the MTP) instead of claiming a fallback. The CLI run is unchanged: it still loads the MTP beside DFlash2 and falls back to it, as in main.
  • Default path. Every new branch is behind use_df2 (false unless --draft dflash2 loaded). use_df2 is now declared outside #if defined(STRATA_HAVE_DFLASH2) so the Metal / SYCL builds, which compile without the drafter, still see false. The MTP pipelined chain launch keeps its order (before the front-stage commits).
  • Setup. The engine's refusal line for the modes still not served is new ("it is not available with --batch, a layer split on one GPU, or a CLI run on a layer split (serve it)"); strata_control/drafting.fallback_note reads it as NOT_HERE, with a test. ENGINE_SERVES_DFLASH2 stays False: Control and engine ship separately, so flipping it belongs with the release whose engine has this.
  • Docs: docs/MULTI_GPU.md section "DFlash2 drafting when serving", --help line for --draft.

Validation

All on: 2x RTX 3090 24 GB (driver 617.42, CUDA 13.0.88, sm_86 local build), i9-9920X, 96 GB RAM, Windows 11 Pro 26300. Model Qwen3.8-Flash-Next GSQ-RCO IQ3_S, native pack, --layer-split 25, GPU order [1,0], --spec 4 --spec-min-p 0.5 --max-context 131072 --kv k8v4 --kv-resident 32768 --vram-reserve-mib 700 --remote-expert-opt --adapt-async 1 --pipeline-windows 2 --trim-stage-weights --host-core last --conversation-cache-mib 8192 --conversation-cache-slots 4, env STRATA_SIDE_MIXER=2 STRATA_ADAPT_LAG=2 STRATA_ATTN_DAILY=1 STRATA_QSA_ROWS=1 STRATA_B6_MMVQ_ROWS=1. Drafter: incoai/Qwen3.8-Flash-Next-DFlash2 packed Q8 with tools/dflash2_pack.py (760 MB). Revision: this branch on 7ddc17a3. Baseline: the released 0.1.48 engine component (0.1.48-windows-x86_64-cuda-cuda13; no engine source changed between v0.2.3.1 and 7ddc17a3).

Passed:

  • cmake --build build --target strata (CUDA 13.0, Ninja, MSVC 2022 BuildTools, sm_86): builds and links.

  • python -m unittest tests.terminal.test_drafting: 39 of 40 pass, including the new fallback_note case. The one error (TheDownloadPlanListsIt.test_the_plan_line_and_the_part, KeyError: 'dflash2') fails the same way on a clean 7ddc17a3 checkout on this PC (the DFlash2 pack is already downloaded here).

  • Speed, interleaved A/B, 3 rounds x (0.1.48 release with MTP, this build with MTP, this build with DFlash2); each a fresh server start, one warm-up request, then 5 prompts twice, greedy except one sampled at 0.7, thinking off. Decode tok/s from the engine log ("N generated in X ms"), mean (min-max) of 6 runs:

    chat 250 code 600 reasoning 800 JSON 300 sampled 400 mean
    0.1.48 release, MTP 123.6 (111-133) 146.7 (140-155) 124.2 (119-128) 118.6 (100-134) 117.8 (115-120) 126.2
    this build, MTP 122.5 (117-127) 147.6 (139-156) 123.3 (118-130) 120.2 (99-136) 118.8 (111-125) 126.5 (+0.3%)
    this build, DFlash2 120.4 (117-127) 143.3 (134-156) 124.1 (119-129) 116.8 (110-124) 115.2 (106-122) 124.0 (-1.8%)

    Acceptance (accepted / drafted, all runs): MTP 64 / 83 / 64 / 83 / 61%, DFlash2 65 / 84 / 65 / 83 / 59%. With the MTP, this build is within noise of the release.

  • One card, --serve (GPU 1 only, same args without the split), 1 round x 2 passes: DFlash2 76.0 tok/s mean vs MTP 79.5 (this build). Starts, serves 10 requests, no errors.

  • Start-up line on the split: strata serve: DFlash2 drafter on CUDA1 (...q8.pack, graphs captured in 5 ms; the MTP layer is not loaded).

  • Greedy text (docs/MULTI_GPU.md "Same text" settings: STRATA_IQ_MT_MIN=1 --pcie-frac 0 --adapt-every 0, otherwise the config above), 2 rounds x 3 arms x 4 greedy prompts x cold/warm. With this config the release engine does not reproduce its own greedy text across restarts: 0.1.48 vs 0.1.48 matched in 4 of 16 answers (the JSON prompt every time; chat, code and reasoning split at a near-tie, e.g. code at character 1106 in both arms). This build with MTP matched a 0.1.48 answer in 7 of 16, with DFlash2 in 7 of 16. So no sign of a text change, but this is not a bit-for-bit proof: that needs a config where the release repeats itself, which I did not find in the time I had.

  • CLI run, one card, final binary (--tokens-file bench/results/2026-10-07-community-arc-b65-v01402/benchy-short.ids --max-new 300, same pack and drafter, --max-context 8192): --draft dflash2 prints "DFlash2 drafter on (...), the MTP layer stays as the fallback", 56.6 tok/s, 76% of drafts accepted; MTP 60.3 tok/s, 73%. Both exit 0.

  • Two-card --serve, final binary, 1 round: starts with the DFlash2 line above and serves all 10 requests (the A/B table was measured on the build before the last commit, whose serve path is the same; the last change only restored the CLI's MTP fallback and the --help text).

  • Metal build: this branch plus the one-line runner bump from #3870, metal-build.yml on macos-26 in my fork; "Build and link the engine" passed (build and link only, not run on a Mac): https://github.com/stuchapin909/Strata/actions/runs/39993333283. The metal-link failure shown on this PR is the repo-wide macos-14 SDK issue (MTLGPUFamilyMetal4 / mathMode in metal/src/mtl_rt.mm) that #3870 fixes.

Failed:

  • none observed

Not run:

  • HIP and SYCL builds (no toolchain / hardware here); the Metal engine was built and linked (above) but not run. generate.cpp, verify.cpp, prefill.cpp and both headers are compiled by those backends. I checked by script that every DFlash2 symbol outside the class members is inside #if defined(STRATA_HAVE_DFLASH2), but that is not a build.
  • A forced late DFlash2 failure (bind / prepare) in --serve or the CLI, to see the error exit and the fallback line.
  • --batch, three or more stages, AMD gfx12 (where --pipeline-windows 2 is the default), long prompts (all prompts here are under 150 tokens), tool-call prompts, conversation-cache restores with DFlash2 (see Limits).
  • The CTest suite (verify_parity, spec_verify_parity, verify_batch_parity are not built in this tree).

Limits

  • Slower than the MTP on this rig at every prompt type. I did not tune --draft-cap / --draft-conf for the split.
  • In the pipelined loop the guess for the window after next is made from the drafter's block for the window just verified: the window in flight has no taps yet on the last card. That is the structural cost of overlapping stages.
  • The conversation cache does not save the drafter's context. After a restore the drafter can look back at rows from the conversation it served before, until new windows replace them. Drafts are verified, so this can cost acceptance, not correctness (static reading, not measured).
  • ENGINE_SERVES_DFLASH2 is left False, so the app and strata launch --drafting dflash2 still pick the MTP; the engine flag works when passed directly in a config's args.
  • The pinned tap buffers for the split are allocated once at start and freed at exit (process lifetime).

AI-assisted: a Gemini agent wrote the first version; I (with Claude Code) reviewed it, fixed three issues (a Metal/SYCL build break from use_df2 scoped inside the DFlash2 #if, a reordered MTP chain launch on the default pipelined path, and a broken MTP fallback in both serve and CLI), and produced every measurement above on my machine.


🔄 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/3869 **Author:** [@stuchapin909](https://github.com/stuchapin909) **Created:** 10/23/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/dflash2-serve-split` --- ### 📝 Commits (1) - [`5f436de`](https://github.com/Niko1221/Strata/commit/5f436de2c3a9fbd36d2efa66629015be11308dcc) engine: --draft dflash2 when serving, on one card and on a layer split (opt-in) ### 📊 Changes **8 files changed** (+425 additions, -115 deletions) <details> <summary>View changed files</summary> 📝 `docs/MULTI_GPU.md` (+35 -0) 📝 `include/strata/core/verify.hpp` (+10 -3) 📝 `include/strata/prefill/prefill.hpp` (+6 -1) 📝 `src/core/verify.cpp` (+16 -5) 📝 `src/prefill/prefill.cpp` (+49 -11) 📝 `src/program/generate.cpp` (+306 -94) 📝 `strata_control/drafting.py` (+1 -1) 📝 `tests/terminal/test_drafting.py` (+2 -0) </details> ### 📄 Description ## Problem and result `--draft dflash2` (merged in f-023-df2) runs only in the CLI on one card: with `--serve` or a layer split the engine prints "it is for one card and the CLI run" and drafts with the MTP. The 0.2.3 notes say the app will offer DFlash2 "once the engine serves it". This adds that, opt-in: `--serve --draft dflash2 --draft-model PACK` now drafts with DFlash2 on one card **and on a layer split of two or more cards**, with or without `--pipeline-windows 2`. Without `--draft dflash2` nothing changes. Result on 2x RTX 3090 (the hardware the maintainers do not have): it works, the text is the target model's, and **it is not faster here**. DFlash2 decodes 1.8% slower than the MTP on a two-card split, mean of 5 prompt types x 6 runs; on one card 4% slower (one round). So the MTP stays the default and this PR changes no default. Measurements below. ## Related discussion - 0.2.3 release notes: "The app offers Auto, MTP and Off only; it will show DFlash2 once the engine serves it." - #3322 (j-luwierski's DFlash2 PR, CUDA only, one card) and Gamal-ElDeen's measurements there; on 10-21 others noted DFlash2 had "NOT run on Windows or multi-GPU". This is that run. - No scope agreement yet for serve / layer-split support: **opened as a draft** for that reason and for the backends I could not build (below). ## Approach - **Taps across stages.** The drafter reads the completed outputs of layers 5, 15, 25, 35, 45. On a split the front stage's verifier writes its tapped layers into a mapped, portable host buffer (`Verifier::set_taps(layers, shared_map, ext_dev)`); the last stage's `record_window` copies those rows into its own `tap_dev` at the start of its part of the window. The odd (pipelined) verifiers get their own mapped buffer. Prompt reading does the same per chunk: a front `Prefill` writes its taps into pinned host hand-off buffers (double-buffered with the existing `hand_buf_`) and the next stage uploads them before its layers run. - **Drafter on the last card,** beside the head (`df2.load(..., last_st->dev)`), so `df2.draft(ver.tap_dev(), ...)` reads device memory on its own card. - **`--serve` loops.** The serial decode loop drafts with `df2.draft` in place of `mtp.draft` (with the PLE row prefetch the MTP path does). In the pipelined loop, when a window is accepted whole, the drafter drafts from the verified window's taps and the next guessed window is built from that block (`make_b`); after a partial accept it drafts from the accepted rows. Prompt windows and merged first windows feed `df2.context`. - **The MTP layer is not loaded when serving with DFlash2** (its VRAM goes to the expert cache). So a late failure (bind / prepare) stops the server with `--draft dflash2: <reason> (start without --draft dflash2 for the MTP)` instead of claiming a fallback. The CLI run is unchanged: it still loads the MTP beside DFlash2 and falls back to it, as in main. - **Default path.** Every new branch is behind `use_df2` (false unless `--draft dflash2` loaded). `use_df2` is now declared outside `#if defined(STRATA_HAVE_DFLASH2)` so the Metal / SYCL builds, which compile without the drafter, still see `false`. The MTP pipelined chain launch keeps its order (before the front-stage commits). - **Setup.** The engine's refusal line for the modes still not served is new ("it is not available with --batch, a layer split on one GPU, or a CLI run on a layer split (serve it)"); `strata_control/drafting.fallback_note` reads it as `NOT_HERE`, with a test. `ENGINE_SERVES_DFLASH2` stays `False`: Control and engine ship separately, so flipping it belongs with the release whose engine has this. - Docs: `docs/MULTI_GPU.md` section "DFlash2 drafting when serving", `--help` line for `--draft`. ## Validation All on: 2x RTX 3090 24 GB (driver 617.42, CUDA 13.0.88, sm_86 local build), i9-9920X, 96 GB RAM, Windows 11 Pro 26300. Model Qwen3.8-Flash-Next GSQ-RCO IQ3_S, native pack, `--layer-split 25`, GPU order [1,0], `--spec 4 --spec-min-p 0.5 --max-context 131072 --kv k8v4 --kv-resident 32768 --vram-reserve-mib 700 --remote-expert-opt --adapt-async 1 --pipeline-windows 2 --trim-stage-weights --host-core last --conversation-cache-mib 8192 --conversation-cache-slots 4`, env `STRATA_SIDE_MIXER=2 STRATA_ADAPT_LAG=2 STRATA_ATTN_DAILY=1 STRATA_QSA_ROWS=1 STRATA_B6_MMVQ_ROWS=1`. Drafter: `incoai/Qwen3.8-Flash-Next-DFlash2` packed Q8 with `tools/dflash2_pack.py` (760 MB). Revision: this branch on `7ddc17a3`. Baseline: the released 0.1.48 engine component (`0.1.48-windows-x86_64-cuda-cuda13`; no engine source changed between v0.2.3.1 and `7ddc17a3`). **Passed:** - `cmake --build build --target strata` (CUDA 13.0, Ninja, MSVC 2022 BuildTools, sm_86): builds and links. - `python -m unittest tests.terminal.test_drafting`: 39 of 40 pass, including the new `fallback_note` case. The one error (`TheDownloadPlanListsIt.test_the_plan_line_and_the_part`, `KeyError: 'dflash2'`) fails the same way on a clean `7ddc17a3` checkout on this PC (the DFlash2 pack is already downloaded here). - **Speed, interleaved A/B**, 3 rounds x (0.1.48 release with MTP, this build with MTP, this build with DFlash2); each a fresh server start, one warm-up request, then 5 prompts twice, greedy except one sampled at 0.7, thinking off. Decode tok/s from the engine log ("N generated in X ms"), mean (min-max) of 6 runs: | | chat 250 | code 600 | reasoning 800 | JSON 300 | sampled 400 | mean | |---|---|---|---|---|---|---| | 0.1.48 release, MTP | 123.6 (111-133) | 146.7 (140-155) | 124.2 (119-128) | 118.6 (100-134) | 117.8 (115-120) | 126.2 | | this build, MTP | 122.5 (117-127) | 147.6 (139-156) | 123.3 (118-130) | 120.2 (99-136) | 118.8 (111-125) | 126.5 (+0.3%) | | this build, DFlash2 | 120.4 (117-127) | 143.3 (134-156) | 124.1 (119-129) | 116.8 (110-124) | 115.2 (106-122) | 124.0 (-1.8%) | Acceptance (accepted / drafted, all runs): MTP 64 / 83 / 64 / 83 / 61%, DFlash2 65 / 84 / 65 / 83 / 59%. With the MTP, this build is within noise of the release. - **One card, `--serve`** (GPU 1 only, same args without the split), 1 round x 2 passes: DFlash2 76.0 tok/s mean vs MTP 79.5 (this build). Starts, serves 10 requests, no errors. - Start-up line on the split: `strata serve: DFlash2 drafter on CUDA1 (...q8.pack, graphs captured in 5 ms; the MTP layer is not loaded)`. - **Greedy text** (`docs/MULTI_GPU.md` "Same text" settings: `STRATA_IQ_MT_MIN=1 --pcie-frac 0 --adapt-every 0`, otherwise the config above), 2 rounds x 3 arms x 4 greedy prompts x cold/warm. With this config the release engine does not reproduce its own greedy text across restarts: 0.1.48 vs 0.1.48 matched in 4 of 16 answers (the JSON prompt every time; chat, code and reasoning split at a near-tie, e.g. code at character 1106 in both arms). This build with MTP matched a 0.1.48 answer in 7 of 16, with DFlash2 in 7 of 16. So no sign of a text change, but this is not a bit-for-bit proof: that needs a config where the release repeats itself, which I did not find in the time I had. - **CLI run, one card, final binary** (`--tokens-file bench/results/2026-10-07-community-arc-b65-v01402/benchy-short.ids --max-new 300`, same pack and drafter, `--max-context 8192`): `--draft dflash2` prints "DFlash2 drafter on (...), the MTP layer stays as the fallback", 56.6 tok/s, 76% of drafts accepted; MTP 60.3 tok/s, 73%. Both exit 0. - **Two-card `--serve`, final binary**, 1 round: starts with the DFlash2 line above and serves all 10 requests (the A/B table was measured on the build before the last commit, whose serve path is the same; the last change only restored the CLI's MTP fallback and the `--help` text). - **Metal build**: this branch plus the one-line runner bump from #3870, `metal-build.yml` on `macos-26` in my fork; "Build and link the engine" passed (build and link only, not run on a Mac): https://github.com/stuchapin909/Strata/actions/runs/39993333283. The `metal-link` failure shown on this PR is the repo-wide `macos-14` SDK issue (`MTLGPUFamilyMetal4` / `mathMode` in `metal/src/mtl_rt.mm`) that #3870 fixes. **Failed:** - none observed **Not run:** - HIP and SYCL builds (no toolchain / hardware here); the Metal engine was built and linked (above) but not run. `generate.cpp`, `verify.cpp`, `prefill.cpp` and both headers are compiled by those backends. I checked by script that every DFlash2 symbol outside the class members is inside `#if defined(STRATA_HAVE_DFLASH2)`, but that is not a build. - A forced late DFlash2 failure (bind / prepare) in `--serve` or the CLI, to see the error exit and the fallback line. - `--batch`, three or more stages, AMD gfx12 (where `--pipeline-windows 2` is the default), long prompts (all prompts here are under 150 tokens), tool-call prompts, conversation-cache restores with DFlash2 (see Limits). - The CTest suite (`verify_parity`, `spec_verify_parity`, `verify_batch_parity` are not built in this tree). ## Limits - Slower than the MTP on this rig at every prompt type. I did not tune `--draft-cap` / `--draft-conf` for the split. - In the pipelined loop the guess for the window after next is made from the drafter's block for the window just verified: the window in flight has no taps yet on the last card. That is the structural cost of overlapping stages. - The conversation cache does not save the drafter's context. After a restore the drafter can look back at rows from the conversation it served before, until new windows replace them. Drafts are verified, so this can cost acceptance, not correctness (static reading, not measured). - `ENGINE_SERVES_DFLASH2` is left `False`, so the app and `strata launch --drafting dflash2` still pick the MTP; the engine flag works when passed directly in a config's `args`. - The pinned tap buffers for the split are allocated once at start and freed at exit (process lifetime). AI-assisted: a Gemini agent wrote the first version; I (with Claude Code) reviewed it, fixed three issues (a Metal/SYCL build break from `use_df2` scoped inside the DFlash2 `#if`, a reordered MTP chain launch on the default pipelined path, and a broken MTP fallback in both serve and CLI), and produced every measurement above on my machine. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4808
No description provided.