[PR #3322] [CLOSED] [Engine] support the official Flash-Next DFlash2 checkpoint #4567

Closed
opened 2026-11-07 15:37:28 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3322
Author: @j-luwierski
Created: 10/20/2026
Status: ❌ Closed

Base: main ← Head: codex/dflash2-main


📝 Commits (10+)

  • 814d886 dflash: the standalone DFlash artifact contract (GGUF metadata, geometry, CLI)
  • 155211c dflash: the target feature taps [3,15,23,35,43] (HC-contracted residuals)
  • 2b17354 dflash: the standalone block forward, wired into the plain decode loop (greedy)
  • 6ae809f dflash: a numpy reference forward for the fixture-parity harness
  • 8adb9bc dflash: the forward's debug probes behind STRATA_DF_DBG, noise prints removed
  • 54e1402 fix(dflash): use the drafter's full-head 256-dim NeoX RoPE
  • 47b925a fix(dflash): initialize the batched attention's identity rows for every query
  • 9294eee fix(dflash): the host-only dflash_load_test needs the CUDA include path (dflash.hpp -> session.hpp)
  • 4199104 fix(dflash): one definition of dflash_identity_fill (the anonymous-namespace copy made the call ambiguous)
  • e63c241 refactor(dflash): split the loader and the device runtime into separate TUs

📊 Changes

953 files changed (+218800 additions, -285 deletions)

View changed files

📝 CMakeLists.txt (+63 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q4_0-command.json (+79 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q4_0-progress.log (+16 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q4_0.json (+248 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q4_0.log (+83 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q5_0-command.json (+79 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q5_0-progress.log (+17 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q5_0.json (+264 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q5_0.log (+86 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q8_0-command.json (+79 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q8_0-progress.log (+17 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q8_0.json (+264 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/Q8_0.log (+86 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/README.md (+54 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/analyze.py (+86 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/ar-command.json (+75 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/ar-progress.log (+8 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/ar.json (+152 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/ar.log (+61 -0)
➕ bench/results/2026-10-19-dflash2-pr-performance/artifacts.json (+60 -0)

...and 80 more files

📄 Description

Problem and result

The official incoai/Qwen3.8-Flash-Next-DFlash2 checkpoint requires five attention layers with 128-wide heads, raw HC-mean target features, dynamic convolution and a predecessor-conditioned selector. This change implements that checkpoint contract and supports original BF16 weights plus Q8_0, Q5_0 and Q4_0 backbone quantizations, using the full shared target output head. This PR resolves the Qwen3.8-Flash-Next speculative-decoding gap tracked in issue #3304 by adding opt-in DFlash2 support and setup integration. The measured results do not establish the suggested 1.5–2× gain across workloads; performance depends on target, prompts, hardware and configuration, as detailed below.

Setup offers MTP (default), experimental DFlash2, or no model drafter. DFlash2 selection enables the local CUDA build, pinned download/conversion and artifact-specific calibration. Weights, private KV pools and attention scratch are accounted for before auto-sizing the expert cache, including the configured context length and elastic growth. MTP and DFlash2 cannot be selected together.

Explicit maintainer confirmation of the expanded official-checkpoint/setup scope remains pending. This remains a draft while that scope and missing backend validation are resolved.

Approach

DFlash2 is opt-in behind STRATA_ENABLE_DFLASH2=ON. The converter validates the checkpoint geometry and preserves all 45 norm, convolution and selector tensors in BF16; the 36 backbone matrices can be quantized. Setup offers BF16, Q8_0 and Q4_0; Q5_0 is also supported by the converter/runtime and included in the measurements below.

Prompt and conversation snapshots retain the draft context. Cache controls enforce matching actual expert placement before checking output. The shared runtime includes the infrastructure required for proposal verification, a fix for state publication on the opt-in QFUSE path and a fix for the CPU-only loader-test build dependency. The existing default drafter stays MTP.

Current implementation and speed comparison — measured 2026-10-23

The official DFlash2 path and opt-in runtime optimizations are implemented. The suggested +32.23% long-prompt decode advantage has not been reached. The new 256K code run measures +14.84% decode speed over MTP; full request time is 0.72% slower because prompt processing dominates.

The short-context rows are the three-repeat small-page-on audit from 2026-10-22. The 256K row is a paired run from 2026-10-23. Hardware: RTX 4070 Ti SUPER 16 GiB, Ryzen 9 5900X, 125.7 GiB RAM, Linux, CUDA 13.4 / SM89. Target: local Flash-Next NVFP4, BF16 embeddings, FP8 PLE, full shared Q8_0 head and INT8 KV. Native decode tok/s excludes startup and prompt processing.

Task Input tokens Context / resident KV MTP, tok/s DFlash2 Q8_0, tok/s DFlash2 profile DFlash2 vs MTP
Code, short 27 8192 / 8192 38.030 [37.788–38.083], n=3 49.077 [49.045–49.183], n=3 Small-page on +29.05%
Code, repeated-note padding 2427 8192 / 8192 36.813 [36.401–36.909], n=3 40.915 [40.865–41.041], n=3 Small-page on +11.15%
Cache, repeated notes 2425 8192 / 8192 51.026 [51.020–51.064], n=3 51.135 [51.110–51.186], n=3 Small-page on +0.21%
Code, 256K context 261747 262144 / 32768 34.900, n=1 40.080, n=1 Recorded Q8_0 profile +14.84%

For the first three rows, ranges are observed min–max, not confidence intervals. Small-page off → on changed DFlash2 speed from 48.952 → 49.077 tok/s (+0.26%) for short code, 40.759 → 40.915 (+0.38%) for padded code and 50.622 → 51.135 (+1.01%) for cache. DFlash2 accepted/offered counts were 70/85, 58/87 and 66/78. These results are fixture-specific measurements from one machine.

256K code run: decode and full-request cost

The paired run used the same 261,747-token prompt, target model, executable, expert profile, 96-token greedy output and seed in both arms. All 96 output token IDs matched.

Metric MTP, max T=4 DFlash2 Q8_0, block 7 DFlash2 vs MTP
Decode speed 34.900 tok/s 40.080 tok/s +14.84%
Decode time for 96 tokens 2.751 s 2.395 s 0.356 s saved
Full request time, prompt + decode 1012.19 s 1019.47 s 0.72% slower
Accepted / offered draft tokens 50 / 88 (56.82%) 53 / 62 (85.48%) —

Each method ran once because processing the prompt took about 17 minutes per arm; the 256K tok/s values have no statistical interval. Full request time is not a prompt-only measurement. DFlash2 saved 0.356 seconds during decode, while its whole request took 7.280 seconds longer. The +32.23% target would require 46.149 tok/s at this MTP rate. Shared settings: 2,700 actual expert slots, 11 workers, verifier capacity 8, prefill 512, short-read 64 and 480 MiB reserve; prompt cache, adaptive swaps and PCIe sharing were disabled. Method settings were held fixed: DFlash2 block 7 / spec_min_p=0.7; MTP max T=4 / spec_min_p=0.5. No launch-parameter sweep was performed.

Full 256K report, exact prompt IDs and provenance, commands, raw measurements and logs · Machine-readable summary · 2026-10-22 raw commands and output controls

The short and padded-code target continuations diverge at output index 11, and the cache task uses different content. These rows do not isolate context length from continuation difficulty. The older +32.23% short-code result used a different profile and is historical; do not combine it with these measurements.

How to enable the pushed optimization options

Use a build containing this PR (implementation dbaa12db, evidence follow-up 3aef66c3) and a compatible DFlash2 artifact. These are engine environment variables, not new command-line flags. Set them before starting the engine, then restart the engine after changes; several switches are read only at startup or first use. Selecting MTP does not activate DFlash2-specific kernels.

For a source CUDA build, enable the extension in the normal CUDA configuration:

cmake -S . -B build-dflash2 -DSTRATA_ENABLE_CUDA=ON -DSTRATA_ENABLE_DFLASH2=ON
cmake --build build-dflash2 --target strata -j4

Keep the existing model paths and DFlash2 launch arguments. Set the desired options in the same shell that starts the engine/server; an already-running process does not inherit later shell changes.

Environment variable What setting it to 1 enables Default / important limits
STRATA_DFLASH2_SMALL_PAGE_ATTENTION Specialized attention indexing and aligned paired FP16 value loads for the runtime's four-cell pages Off. Official 32Q/8KV geometry; other geometries retain the general path. This is the new kernel option measured in the table.
STRATA_DFLASH2_PROMPT_TAIL Skips whole context-fusion batches that future local attention cannot read Off. Fresh native requests with --prompt-cache 0; reference/parity/debug paths keep full processing. Improves prompt processing only, not token acceptance.
STRATA_DFLASH2_PARALLEL_PROJECTIONS Runs proposal Q/K/V projections on separate streams, and overlaps gate/up projections Off. Reference, tensor-dump, debug and section-timing paths retain serial execution. This does not enable the rejected context K/V prototype.
STRATA_DFLASH2_REGISTER_TOPK Register-based local candidate top-k within the tiled path Off. Requires the tiled path and workspace; tiled top-k is already enabled by default. Do not force STRATA_DFLASH2_SERIAL_TOPK=1 when testing it.
STRATA_DFLASH2_FUSED_CONV Fuses convolution epilogues with following conversion/residual work Off. Reference/parity/debug paths retain their diagnostic behavior.
STRATA_DFLASH2_LATTICE_SELECTOR Computes candidate transition scores in parallel before walking the conditioned path Off. Requires normal selector workspace; serial/reference selector paths bypass it.
STRATA_DFLASH_HEAD_IL + STRATA_MMVQ_IL_Q8_HEAD Enables DFlash2 interleaved head dispatch and the compatible Q8_0 shared-head kernel Both off. Set both to 1. The Q8_0 specialization is gated to measured SM89, vocabulary 248320 and supported row counts; unsupported cases retain the existing path. No head weights are replaced.

For the small-page-on arm of the speed table, use the two shared-head options in both MTP and DFlash2 comparisons, and enable only the new small-page option on the DFlash2 arm:

export STRATA_DFLASH_HEAD_IL=1
export STRATA_MMVQ_IL_Q8_HEAD=1
export STRATA_DFLASH2_SMALL_PAGE_ATTENTION=1
# Start the existing DFlash2 engine command from this shell.

Optional, independently testable additions for the existing DFlash2 command:

export STRATA_DFLASH2_PARALLEL_PROJECTIONS=1
export STRATA_DFLASH2_PROMPT_TAIL=1
# PROMPT_TAIL requires --prompt-cache 0 and the fresh native request path.
# Restart the engine after changing these variables.

PowerShell equivalent (syntax reference; Windows execution has not been validated):

$env:STRATA_DFLASH_HEAD_IL = "1"
$env:STRATA_MMVQ_IL_Q8_HEAD = "1"
$env:STRATA_DFLASH2_SMALL_PAGE_ATTENTION = "1"
$env:STRATA_DFLASH2_PARALLEL_PROJECTIONS = "1"
$env:STRATA_DFLASH2_PROMPT_TAIL = "1"
# Start/restart the existing DFlash2 engine command from this PowerShell session.

The table is not a measurement of all options enabled together. Parallel projections, prompt-tail, register top-k, fused convolution and lattice selector are separate experiments; do not infer an additive speedup. To restore these opt-in paths to their defaults, unset the corresponding variables (or set them to 0) and restart. In Bash use unset STRATA_DFLASH2_PARALLEL_PROJECTIONS; in PowerShell use Remove-Item Env:STRATA_DFLASH2_PARALLEL_PROJECTIONS, and likewise for each enabled option.

The rejected STRATA_DFLASH2_PARALLEL_CONTEXT, STRATA_DFLASH2_WARP_ATTENTION_MAX and STRATA_DFLASH2_BF16_STREAM_MEAN prototypes are not present in production and must not be advertised as usable optimization options.

Prompt-processing and acceptance findings

A separate 7227-token code fixture measures prompt-tail processing at 16897.4 → 16759.0 ms (−0.82%), with identical output IDs and 20/28 acceptance. Decode medians are 713.4 and 713.9 ms: no steady-state win. Prompt-time changes on the 2427/2425-token fixtures are negligible. This evidence is separate from the decode-speed table.

The joint diagnostic capture records native BF16 proposals and their exact target features at 95 anchor positions per task. The published BF16 PyTorch drafter, consuming those same features, chooses the same first proposal at all 285 positions: 90/95 correct for short code, 81/95 for padded code and 83/95 for cache. Later proposals can differ; this is not full bitwise PyTorch parity or validation of native target features against the upstream teacher. Reference/native correct-prefix sums are 256/258 for padded code and 348/348 for cache. Simply reproducing reference BF16 arithmetic does not recover the missing acceptance on these fixtures.

Context deduplication, two-pass self-conditioning and causal per-request selector feedback did not consistently improve acceptance. Extra context K/V parallelism and warp-maximum reduction did not establish a speed benefit and were removed. Their patches, results and limitations remain as negative evidence. No weights were fine-tuned in these experiments.

Latest validation

Passed: CUDA builds with DFlash2 enabled and disabled; dflash_load_test, dflash_policy_test; default/enabled dflash2_parity --bench; 30 before/default/enabled attention outputs bit-identical, including four-cell pages, unaligned fallback and physical rings; independent FP64 attention oracle; long NumPy stage oracle for all five layers/live KV/final normalization/selector within documented tolerances; fresh native output controls, complete joint feature/proposal capture and Python syntax compilation of the modified stage oracle.

Diagnostic prototypes were removed and production rebuilt. SHA256 42a56c9a217ddb47c58fa6f42ad331c77ae2c296a532d84c53b3610fedb4a3f2 matches the executable used for the latest table.

Failed / rejected: the follow-up algorithm and scheduling experiments did not meet their acceptance/performance goals. Initial incomplete captures were retained and excluded from final findings. Earlier test failures remain documented below and in their original reports.

Not run on the latest head: HIP/SYCL compilation/execution (compilers unavailable), Metal, Windows, other target families, multi-GPU, vision, concurrent requests, a held-out long-prompt suite or full 128K prompt sweep. Earlier validation at another revision is not claimed as a latest-head rerun. This PR remains a draft pending scope agreement and missing backend validation.

Historical performance and validation reports

These links preserve previous tables and their original settings. They are not the current speed table:

Historical validation — original revisions

Earlier checkpoint validation used engine source at af85f5ce3b4411833b5529361ae18ffdadbdce3f, based on main e88ee39d1d6be6e3364183af3b39b62a7ed6f211. Performance evidence commit: 86af7286254d1efb148cf0aa8c9a96868d4e9f09; it adds scripts/results without changing engine code. Linux, RTX 4070 Ti SUPER 16 GiB, Ryzen 9 5900X, 125.7 GiB RAM, CUDA 13.4, GCC 14.2, SM89.

Passed:

  • Follow-up fix at c7bebe215a6feb754e08dfbc02a3ac12d38fa55f: CUDA extension ON/OFF builds; three ON and two OFF CTests; native fixed-block default/explicit-zero checks; 192/192 target-only fixture IDs match all threshold/block repeats at matching 3279 expert slots. Same-day MTP fixture IDs also match.
  • CUDA extension ON/OFF builds; 12 selected CUDA CTests, plus extension-OFF loader rejection.
  • 203 setup/conversion/cache/tool tests and 342 server tests.
  • CPU-only full build after fixing the loader test's CUDA-header dependency.
  • Main/OFF/ON regression comparison: 768 candidate IDs match main across AR/MTP, greedy/sampled requests and three prompts. Final rebuild executable hashes are unchanged.
  • Official Q8 DFlash2 cache test: eight cases, 256/256 IDs equal both fresh DFlash2 and target-only controls at matching 2000 expert slots. Checks live continuation, parked conversation restoration, prompt snapshots, rewind and sampled-to-greedy transition.
  • Full 128K draft-memory allocation with BF16/Q8/Q4 and short generation; one actual 8192→16384-cell growth with an 8448-token prompt.

Commands, source/executable hashes, raw IDs and logs are in validation evidence.

Failed:

  • One follow-up output-control startup provided 3275 rather than the requested 3279 slots; the placement assertion stopped before any request. The successful unmeasured controls use a 480 MiB reserve to retain exactly 3279 actual slots. Performance runs keep 512 MiB. The failed startup is retained in the follow-up evidence.

  • Four CPU CTests fail with the available dependency/tooling: three require missing Trellis types and one reports an AVX512 allowlist violation. All four reproduce on unmodified main. The full candidate CPU run has 44 passed, one skipped and four failed tests.

  • Initial CPU-only build and setup golden-fixture failures were corrected and rerun successfully; original failures are retained.

  • The initial default-path harness rejected a valid early EOS from a truncated prompt. The corrected harness uses the full prompt and compares actual IDs; its failed attempt is retained.

  • An earlier 256 MiB VRAM-reserve startup failed to fit verifier allocations. That failed attempt and an interrupted fixed-cache experiment are retained in the earlier quantization evidence and excluded from measured medians.

  • A preliminary performance restart overlapped teardown of the preceding engine and failed the host memory guard. The previous process tree was fully stopped before the final complete series. That failure and the interrupted prefill-512 attempt are retained and excluded from medians.

Not run:

HIP/SYCL compilation and execution (ROCm/icpx unavailable), Metal, Windows, multi-GPU, concurrent requests and a full 128K-token prompt. The CUDA extension is explicitly restricted to one GPU and serial requests. Shared backend changes still require the missing builds; keep this draft pending targeted validation.

Limits

Sampled DFlash2 requests use target-only fallback. Cache equality checks cover tested arithmetic paths and matching placement, not every configuration. Disk session restoration is unsupported. The CUDA extension is restricted to one GPU and serial requests. The latest table uses equal actual expert placement; older auto-cache reports allowed different placement, so their results must not be mixed. Performance conclusions apply to the measured hardware and prompts. No universal speedup or +32% long-prompt result is claimed.

Additional setup checkpoint (2026-10-20)

Setup now offers the pinned Turbo-Brilliance DFlash2 fine-tune with --dflash2-head turbo-brilliance; the official checkpoint remains the default. This fine-tune was trained for DavidAU's Turbo-Brilliance GSQ-RCO IQ3_S target. Setup downloads its BF16 model.safetensors, converts it to GGUF and keeps it in a separate cache. The repository's t3000-q8-dv.gguf is a separate plain-DFlash artifact and is not used by this CUDA DFlash2 path.

Validation: pinned revision and SHA-256 checked; config and all 81 BF16 tensor shapes matched the converter using ranged reads of the checkpoint header (the full 1.2 GB weights were not downloaded). Setup choice, cache/conversion, quantizer and calibration-key tests pass. The CUDA DFlash2 conversion of this fine-tune has not been performance-benchmarked; the upstream Apple M4 timings are for the separate plain-DFlash GGUF.


🔄 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/3322 **Author:** [@j-luwierski](https://github.com/j-luwierski) **Created:** 10/20/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/dflash2-main` --- ### 📝 Commits (10+) - [`814d886`](https://github.com/Niko1221/Strata/commit/814d8863d4d25c3ae7964a781d1d9152e0d53c8b) dflash: the standalone DFlash artifact contract (GGUF metadata, geometry, CLI) - [`155211c`](https://github.com/Niko1221/Strata/commit/155211ccd031868cae8ceb2f71bff6771f215a98) dflash: the target feature taps [3,15,23,35,43] (HC-contracted residuals) - [`2b17354`](https://github.com/Niko1221/Strata/commit/2b1735492544032d2ba78c18badde9d2e38265d4) dflash: the standalone block forward, wired into the plain decode loop (greedy) - [`6ae809f`](https://github.com/Niko1221/Strata/commit/6ae809f043ea1d1639208ea93a908431753c4af3) dflash: a numpy reference forward for the fixture-parity harness - [`8adb9bc`](https://github.com/Niko1221/Strata/commit/8adb9bc5a3713bfca4343faa435b9decab632c0d) dflash: the forward's debug probes behind STRATA_DF_DBG, noise prints removed - [`54e1402`](https://github.com/Niko1221/Strata/commit/54e1402760e690718d39d9054b72706f09c48124) fix(dflash): use the drafter's full-head 256-dim NeoX RoPE - [`47b925a`](https://github.com/Niko1221/Strata/commit/47b925aab365f085f2a5eb152a73e75c6911612b) fix(dflash): initialize the batched attention's identity rows for every query - [`9294eee`](https://github.com/Niko1221/Strata/commit/9294eeeb044529a198aacb184fe79fb001246ed4) fix(dflash): the host-only dflash_load_test needs the CUDA include path (dflash.hpp -> session.hpp) - [`4199104`](https://github.com/Niko1221/Strata/commit/41991049d2d243fcc2acf465e6b91b933edc8e74) fix(dflash): one definition of dflash_identity_fill (the anonymous-namespace copy made the call ambiguous) - [`e63c241`](https://github.com/Niko1221/Strata/commit/e63c24156198cc9cab28d035f932206d5c742a25) refactor(dflash): split the loader and the device runtime into separate TUs ### 📊 Changes **953 files changed** (+218800 additions, -285 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+63 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q4_0-command.json` (+79 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q4_0-progress.log` (+16 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q4_0.json` (+248 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q4_0.log` (+83 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q5_0-command.json` (+79 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q5_0-progress.log` (+17 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q5_0.json` (+264 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q5_0.log` (+86 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q8_0-command.json` (+79 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q8_0-progress.log` (+17 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q8_0.json` (+264 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/Q8_0.log` (+86 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/README.md` (+54 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/analyze.py` (+86 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/ar-command.json` (+75 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/ar-progress.log` (+8 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/ar.json` (+152 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/ar.log` (+61 -0) ➕ `bench/results/2026-10-19-dflash2-pr-performance/artifacts.json` (+60 -0) _...and 80 more files_ </details> ### 📄 Description ## Problem and result The official `incoai/Qwen3.8-Flash-Next-DFlash2` checkpoint requires five attention layers with 128-wide heads, raw HC-mean target features, dynamic convolution and a predecessor-conditioned selector. This change implements that checkpoint contract and supports original BF16 weights plus Q8_0, Q5_0 and Q4_0 backbone quantizations, using the full shared target output head. This PR resolves the Qwen3.8-Flash-Next speculative-decoding gap tracked in [issue #3304](https://github.com/Niko1221/Strata/issues/3304) by adding opt-in DFlash2 support and setup integration. The measured results do not establish the suggested 1.5–2× gain across workloads; performance depends on target, prompts, hardware and configuration, as detailed below. Setup offers MTP (default), experimental DFlash2, or no model drafter. DFlash2 selection enables the local CUDA build, pinned download/conversion and artifact-specific calibration. Weights, private KV pools and attention scratch are accounted for before auto-sizing the expert cache, including the configured context length and elastic growth. MTP and DFlash2 cannot be selected together. ## Related discussion Explicit maintainer confirmation of the expanded official-checkpoint/setup scope remains pending. This remains a draft while that scope and missing backend validation are resolved. ## Approach DFlash2 is opt-in behind `STRATA_ENABLE_DFLASH2=ON`. The converter validates the checkpoint geometry and preserves all 45 norm, convolution and selector tensors in BF16; the 36 backbone matrices can be quantized. Setup offers BF16, Q8_0 and Q4_0; Q5_0 is also supported by the converter/runtime and included in the measurements below. Prompt and conversation snapshots retain the draft context. Cache controls enforce matching actual expert placement before checking output. The shared runtime includes the infrastructure required for proposal verification, a fix for state publication on the opt-in QFUSE path and a fix for the CPU-only loader-test build dependency. The existing default drafter stays MTP. ## Current implementation and speed comparison — measured 2026-10-23 The official DFlash2 path and opt-in runtime optimizations are implemented. **The suggested +32.23% long-prompt decode advantage has not been reached.** The new 256K code run measures +14.84% decode speed over MTP; full request time is 0.72% slower because prompt processing dominates. The short-context rows are the three-repeat small-page-on audit from 2026-10-22. The 256K row is a paired run from 2026-10-23. Hardware: RTX 4070 Ti SUPER 16 GiB, Ryzen 9 5900X, 125.7 GiB RAM, Linux, CUDA 13.4 / SM89. Target: local Flash-Next NVFP4, BF16 embeddings, FP8 PLE, full shared Q8_0 head and INT8 KV. Native decode tok/s excludes startup and prompt processing. | Task | Input tokens | Context / resident KV | MTP, tok/s | DFlash2 Q8_0, tok/s | DFlash2 profile | DFlash2 vs MTP | | --- | ---: | ---: | ---: | ---: | --- | ---: | | Code, short | 27 | 8192 / 8192 | 38.030 [37.788–38.083], n=3 | **49.077 [49.045–49.183], n=3** | Small-page on | **+29.05%** | | Code, repeated-note padding | 2427 | 8192 / 8192 | 36.813 [36.401–36.909], n=3 | **40.915 [40.865–41.041], n=3** | Small-page on | **+11.15%** | | Cache, repeated notes | 2425 | 8192 / 8192 | 51.026 [51.020–51.064], n=3 | **51.135 [51.110–51.186], n=3** | Small-page on | **+0.21%** | | Code, 256K context | **261747** | **262144 / 32768** | 34.900, n=1 | **40.080, n=1** | Recorded Q8_0 profile | **+14.84%** | For the first three rows, ranges are observed min–max, not confidence intervals. Small-page off → on changed DFlash2 speed from 48.952 → 49.077 tok/s (+0.26%) for short code, 40.759 → 40.915 (+0.38%) for padded code and 50.622 → 51.135 (+1.01%) for cache. DFlash2 accepted/offered counts were 70/85, 58/87 and 66/78. These results are fixture-specific measurements from one machine. ### 256K code run: decode and full-request cost The paired run used the same 261,747-token prompt, target model, executable, expert profile, 96-token greedy output and seed in both arms. All 96 output token IDs matched. | Metric | MTP, max T=4 | DFlash2 Q8_0, block 7 | DFlash2 vs MTP | | --- | ---: | ---: | ---: | | Decode speed | 34.900 tok/s | **40.080 tok/s** | **+14.84%** | | Decode time for 96 tokens | 2.751 s | **2.395 s** | **0.356 s saved** | | Full request time, prompt + decode | **1012.19 s** | 1019.47 s | **0.72% slower** | | Accepted / offered draft tokens | 50 / 88 (56.82%) | **53 / 62 (85.48%)** | — | Each method ran once because processing the prompt took about 17 minutes per arm; the 256K tok/s values have no statistical interval. Full request time is not a prompt-only measurement. DFlash2 saved 0.356 seconds during decode, while its whole request took 7.280 seconds longer. The +32.23% target would require 46.149 tok/s at this MTP rate. Shared settings: 2,700 actual expert slots, 11 workers, verifier capacity 8, prefill 512, short-read 64 and 480 MiB reserve; prompt cache, adaptive swaps and PCIe sharing were disabled. Method settings were held fixed: DFlash2 block 7 / `spec_min_p=0.7`; MTP max T=4 / `spec_min_p=0.5`. No launch-parameter sweep was performed. [Full 256K report, exact prompt IDs and provenance, commands, raw measurements and logs](https://github.com/j-luwierski/Strata/blob/4335151c/bench/results/2026-10-23-dflash2-256k-code/README.md) · [Machine-readable summary](https://github.com/j-luwierski/Strata/blob/4335151c/bench/results/2026-10-23-dflash2-256k-code/summary.json) · [2026-10-22 raw commands and output controls](https://github.com/j-luwierski/Strata/blob/3aef66c338a662213d07bff9f489c6682279b0ea/bench/results/2026-10-22-dflash2-context-audit/README.md) The short and padded-code target continuations diverge at output index 11, and the cache task uses different content. These rows do not isolate context length from continuation difficulty. The older **+32.23%** short-code result used a different profile and is historical; do not combine it with these measurements. ## How to enable the pushed optimization options Use a build containing this PR (implementation `dbaa12db`, evidence follow-up `3aef66c3`) and a compatible DFlash2 artifact. These are **engine environment variables**, not new command-line flags. Set them before starting the engine, then restart the engine after changes; several switches are read only at startup or first use. Selecting MTP does not activate DFlash2-specific kernels. For a source CUDA build, enable the extension in the normal CUDA configuration: ```bash cmake -S . -B build-dflash2 -DSTRATA_ENABLE_CUDA=ON -DSTRATA_ENABLE_DFLASH2=ON cmake --build build-dflash2 --target strata -j4 ``` Keep the existing model paths and DFlash2 launch arguments. Set the desired options in the same shell that starts the engine/server; an already-running process does not inherit later shell changes. | Environment variable | What setting it to 1 enables | Default / important limits | | --- | --- | --- | | `STRATA_DFLASH2_SMALL_PAGE_ATTENTION` | Specialized attention indexing and aligned paired FP16 value loads for the runtime's four-cell pages | Off. Official 32Q/8KV geometry; other geometries retain the general path. This is the new kernel option measured in the table. | | `STRATA_DFLASH2_PROMPT_TAIL` | Skips whole context-fusion batches that future local attention cannot read | Off. Fresh native requests with `--prompt-cache 0`; reference/parity/debug paths keep full processing. Improves prompt processing only, not token acceptance. | | `STRATA_DFLASH2_PARALLEL_PROJECTIONS` | Runs proposal Q/K/V projections on separate streams, and overlaps gate/up projections | Off. Reference, tensor-dump, debug and section-timing paths retain serial execution. This does not enable the rejected context K/V prototype. | | `STRATA_DFLASH2_REGISTER_TOPK` | Register-based local candidate top-k within the tiled path | Off. Requires the tiled path and workspace; tiled top-k is already enabled by default. Do not force `STRATA_DFLASH2_SERIAL_TOPK=1` when testing it. | | `STRATA_DFLASH2_FUSED_CONV` | Fuses convolution epilogues with following conversion/residual work | Off. Reference/parity/debug paths retain their diagnostic behavior. | | `STRATA_DFLASH2_LATTICE_SELECTOR` | Computes candidate transition scores in parallel before walking the conditioned path | Off. Requires normal selector workspace; serial/reference selector paths bypass it. | | `STRATA_DFLASH_HEAD_IL` + `STRATA_MMVQ_IL_Q8_HEAD` | Enables DFlash2 interleaved head dispatch and the compatible Q8_0 shared-head kernel | Both off. Set both to 1. The Q8_0 specialization is gated to measured SM89, vocabulary 248320 and supported row counts; unsupported cases retain the existing path. No head weights are replaced. | For the **small-page-on arm of the speed table**, use the two shared-head options in both MTP and DFlash2 comparisons, and enable only the new small-page option on the DFlash2 arm: ```bash export STRATA_DFLASH_HEAD_IL=1 export STRATA_MMVQ_IL_Q8_HEAD=1 export STRATA_DFLASH2_SMALL_PAGE_ATTENTION=1 # Start the existing DFlash2 engine command from this shell. ``` Optional, independently testable additions for the existing DFlash2 command: ```bash export STRATA_DFLASH2_PARALLEL_PROJECTIONS=1 export STRATA_DFLASH2_PROMPT_TAIL=1 # PROMPT_TAIL requires --prompt-cache 0 and the fresh native request path. # Restart the engine after changing these variables. ``` PowerShell equivalent (syntax reference; Windows execution has not been validated): ```powershell $env:STRATA_DFLASH_HEAD_IL = "1" $env:STRATA_MMVQ_IL_Q8_HEAD = "1" $env:STRATA_DFLASH2_SMALL_PAGE_ATTENTION = "1" $env:STRATA_DFLASH2_PARALLEL_PROJECTIONS = "1" $env:STRATA_DFLASH2_PROMPT_TAIL = "1" # Start/restart the existing DFlash2 engine command from this PowerShell session. ``` The table is **not** a measurement of all options enabled together. Parallel projections, prompt-tail, register top-k, fused convolution and lattice selector are separate experiments; do not infer an additive speedup. To restore these opt-in paths to their defaults, unset the corresponding variables (or set them to 0) and restart. In Bash use `unset STRATA_DFLASH2_PARALLEL_PROJECTIONS`; in PowerShell use `Remove-Item Env:STRATA_DFLASH2_PARALLEL_PROJECTIONS`, and likewise for each enabled option. The rejected `STRATA_DFLASH2_PARALLEL_CONTEXT`, `STRATA_DFLASH2_WARP_ATTENTION_MAX` and `STRATA_DFLASH2_BF16_STREAM_MEAN` prototypes are **not present in production** and must not be advertised as usable optimization options. ## Prompt-processing and acceptance findings A separate 7227-token code fixture measures prompt-tail processing at **16897.4 → 16759.0 ms (−0.82%)**, with identical output IDs and 20/28 acceptance. Decode medians are 713.4 and 713.9 ms: no steady-state win. Prompt-time changes on the 2427/2425-token fixtures are negligible. This evidence is separate from the decode-speed table. The joint diagnostic capture records native BF16 proposals and their exact target features at 95 anchor positions per task. The published BF16 PyTorch drafter, consuming those same features, chooses **the same first proposal at all 285 positions**: 90/95 correct for short code, 81/95 for padded code and 83/95 for cache. Later proposals can differ; this is not full bitwise PyTorch parity or validation of native target features against the upstream teacher. Reference/native correct-prefix sums are 256/258 for padded code and 348/348 for cache. Simply reproducing reference BF16 arithmetic does not recover the missing acceptance on these fixtures. Context deduplication, two-pass self-conditioning and causal per-request selector feedback did not consistently improve acceptance. Extra context K/V parallelism and warp-maximum reduction did not establish a speed benefit and were removed. Their [patches, results and limitations](https://github.com/j-luwierski/Strata/blob/3aef66c338a662213d07bff9f489c6682279b0ea/bench/results/2026-10-22-dflash2-context-audit/README.md#follow-up-experiments-rejected-after-the-implementation-commit) remain as negative evidence. No weights were fine-tuned in these experiments. ## Latest validation **Passed:** CUDA builds with DFlash2 enabled and disabled; `dflash_load_test`, `dflash_policy_test`; default/enabled `dflash2_parity --bench`; 30 before/default/enabled attention outputs bit-identical, including four-cell pages, unaligned fallback and physical rings; independent FP64 attention oracle; long NumPy stage oracle for all five layers/live KV/final normalization/selector within documented tolerances; fresh native output controls, complete joint feature/proposal capture and Python syntax compilation of the modified stage oracle. Diagnostic prototypes were removed and production rebuilt. SHA256 `42a56c9a217ddb47c58fa6f42ad331c77ae2c296a532d84c53b3610fedb4a3f2` matches the executable used for the latest table. **Failed / rejected:** the follow-up algorithm and scheduling experiments did not meet their acceptance/performance goals. Initial incomplete captures were retained and excluded from final findings. Earlier test failures remain documented below and in their original reports. **Not run on the latest head:** HIP/SYCL compilation/execution (compilers unavailable), Metal, Windows, other target families, multi-GPU, vision, concurrent requests, a held-out long-prompt suite or full 128K prompt sweep. Earlier validation at another revision is not claimed as a latest-head rerun. This PR remains a draft pending scope agreement and missing backend validation. ## Historical performance and validation reports These links preserve previous tables and their original settings. They are not the current speed table: - [2026-10-19: all-quantization four-task comparison](https://github.com/j-luwierski/Strata/blob/86af7286254d1efb148cf0aa8c9a96868d4e9f09/bench/results/2026-10-19-dflash2-pr-performance/README.md). - [2026-10-20: confidence gate](https://github.com/j-luwierski/Strata/blob/c7bebe215a6feb754e08dfbc02a3ac12d38fa55f/bench/results/2026-10-20-dflash2-long-prompt/README.md) and [first attention optimization](https://github.com/j-luwierski/Strata/blob/2ad8e64662a6847db61aa12783fc82d862fbf87c/bench/results/2026-10-20-dflash2-attention/README.md). - [2026-10-20: decoder-read profile with historical +32.23% short-code result](https://github.com/j-luwierski/Strata/blob/27b65cc8b4c42c83da65bbed605c8ab6bba8171b/bench/results/2026-10-20-dflash2-long-tuned/README.md). - [2026-10-20: fresh-prompt profiles and setup calibration](https://github.com/j-luwierski/Strata/blob/59454fee/bench/results/2026-10-20-dflash2-fast-prompt/README.md). The broad run had 9 failures, 16 missing-rich/textual errors and 48 skips; not all were resolved or attributed by a clean-parent rerun. - [2026-10-20: long-KV regression](https://github.com/j-luwierski/Strata/blob/8cefe4d1a2919584c387f9dce90e9c558377a580/bench/results/2026-10-20-dflash2-kv-ring/README.md). The 135296-token request with 12300 generated tokens used synthetic prior history plus the supplied final prompt, not the unavailable original full conversation. An earlier parallel snapshot assertion failed while isolated/sequential reruns passed; its cause remains unknown. ## Historical validation — original revisions Earlier checkpoint validation used engine source at `af85f5ce3b4411833b5529361ae18ffdadbdce3f`, based on main `e88ee39d1d6be6e3364183af3b39b62a7ed6f211`. Performance evidence commit: `86af7286254d1efb148cf0aa8c9a96868d4e9f09`; it adds scripts/results without changing engine code. Linux, RTX 4070 Ti SUPER 16 GiB, Ryzen 9 5900X, 125.7 GiB RAM, CUDA 13.4, GCC 14.2, SM89. **Passed:** - Follow-up fix at `c7bebe215a6feb754e08dfbc02a3ac12d38fa55f`: CUDA extension ON/OFF builds; three ON and two OFF CTests; native fixed-block default/explicit-zero checks; 192/192 target-only fixture IDs match all threshold/block repeats at matching 3279 expert slots. Same-day MTP fixture IDs also match. - CUDA extension ON/OFF builds; 12 selected CUDA CTests, plus extension-OFF loader rejection. - 203 setup/conversion/cache/tool tests and 342 server tests. - CPU-only full build after fixing the loader test's CUDA-header dependency. - Main/OFF/ON regression comparison: 768 candidate IDs match main across AR/MTP, greedy/sampled requests and three prompts. Final rebuild executable hashes are unchanged. - Official Q8 DFlash2 cache test: eight cases, 256/256 IDs equal both fresh DFlash2 and target-only controls at matching 2000 expert slots. Checks live continuation, parked conversation restoration, prompt snapshots, rewind and sampled-to-greedy transition. - Full 128K draft-memory allocation with BF16/Q8/Q4 and short generation; one actual 8192→16384-cell growth with an 8448-token prompt. Commands, source/executable hashes, raw IDs and logs are in [validation evidence](https://github.com/j-luwierski/Strata/blob/86af7286254d1efb148cf0aa8c9a96868d4e9f09/bench/results/2026-10-19-dflash2-pr/README.md). **Failed:** - One follow-up output-control startup provided 3275 rather than the requested 3279 slots; the placement assertion stopped before any request. The successful unmeasured controls use a 480 MiB reserve to retain exactly 3279 actual slots. Performance runs keep 512 MiB. The failed startup is retained in the follow-up evidence. - Four CPU CTests fail with the available dependency/tooling: three require missing Trellis types and one reports an AVX512 allowlist violation. All four reproduce on unmodified main. The full candidate CPU run has 44 passed, one skipped and four failed tests. - Initial CPU-only build and setup golden-fixture failures were corrected and rerun successfully; original failures are retained. - The initial default-path harness rejected a valid early EOS from a truncated prompt. The corrected harness uses the full prompt and compares actual IDs; its failed attempt is retained. - An earlier 256 MiB VRAM-reserve startup failed to fit verifier allocations. That failed attempt and an interrupted fixed-cache experiment are retained in the earlier quantization evidence and excluded from measured medians. - A preliminary performance restart overlapped teardown of the preceding engine and failed the host memory guard. The previous process tree was fully stopped before the final complete series. That failure and the interrupted prefill-512 attempt are retained and excluded from medians. **Not run:** HIP/SYCL compilation and execution (ROCm/`icpx` unavailable), Metal, Windows, multi-GPU, concurrent requests and a full 128K-token prompt. The CUDA extension is explicitly restricted to one GPU and serial requests. Shared backend changes still require the missing builds; keep this draft pending targeted validation. ## Limits Sampled DFlash2 requests use target-only fallback. Cache equality checks cover tested arithmetic paths and matching placement, not every configuration. Disk session restoration is unsupported. The CUDA extension is restricted to one GPU and serial requests. The latest table uses equal actual expert placement; older auto-cache reports allowed different placement, so their results must not be mixed. Performance conclusions apply to the measured hardware and prompts. No universal speedup or +32% long-prompt result is claimed. ## Additional setup checkpoint (2026-10-20) Setup now offers the pinned Turbo-Brilliance DFlash2 fine-tune with `--dflash2-head turbo-brilliance`; the official checkpoint remains the default. This fine-tune was trained for DavidAU's Turbo-Brilliance GSQ-RCO IQ3_S target. Setup downloads its BF16 `model.safetensors`, converts it to GGUF and keeps it in a separate cache. The repository's `t3000-q8-dv.gguf` is a separate plain-DFlash artifact and is not used by this CUDA DFlash2 path. Validation: pinned revision and SHA-256 checked; config and all 81 BF16 tensor shapes matched the converter using ranged reads of the checkpoint header (the full 1.2 GB weights were not downloaded). Setup choice, cache/conversion, quantizer and calibration-key tests pass. The CUDA DFlash2 conversion of this fine-tune has not been performance-benchmarked; the upstream Apple M4 timings are for the separate plain-DFlash GGUF. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 15:37:28 +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#4567
No description provided.