Skip to content

Integrate the DFlash2 device pipeline with Qwen graph execution - #2771

Open
Akshay Sonawane (apsonawane) wants to merge 6 commits into
asonawane/main-qwen-graph-runtimefrom
asonawane/dflash2-device-pipeline
Open

Akshay Sonawane (apsonawane) wants to merge 6 commits into
asonawane/main-qwen-graph-runtimefrom
asonawane/dflash2-device-pipeline

Conversation

@apsonawane

@apsonawane Akshay Sonawane (apsonawane) commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Integrate three-token DFlash2 drafting with four-row Qwen graph verification through native Engine and Generator.

  • Include the required native C++ Qwen graph Engine executor and generic multi-row device contract, absent from the published base. Preserve existing Linux guards, resource RAII, session-option inheritance, lattice-return API, and queue commit semantics.
  • Use persistent pinned staging, shared-stream asynchronous drafter execution, and GPU draft-lattice selection.
  • Skip unused MTP sessions/state for DFlash-only packages; use chunk-sized prompt hidden storage, device prefill argmax, and lazy full-logit readback.
  • Preserve Generator logits for every buffered emission, including all three buffered tokens in an S4 cycle.
  • Honor explicit ORT_LIB_PATH from Python instead of silently replacing it with the installed Python package's ORT library. This is required to load the custom API32/contrib stack.
  • Add a portable local-checkpoint BF16/FP8 drafter exporter. Target embedding and FP8 head are retained exactly; BF16 precision refers to body weights, with BF16 activations in both modes.
  • Preserve the published device-only shared-weight pool; exclude unrelated host weight placement/CPU embedding changes.

Base and dependencies

Incremental integration PR against asonawane/main-qwen-graph-runtime, not main. Upstream main and the published feature branch do not contain all native Engine/multi-row prerequisites, so those required C++ pieces are included here explicitly.

Requires the companion ORT branches based on:

  • asonawane/main-ops-sparse-attention-indexer (grouped INT8 S4)
  • asonawane/main-ops-quantized-moe-fp8 (INT2 S4 GEMV/fused routing)
  • asonawane/main-ops-hyperconnection-tensor (S4 work-group tuning)

No benchmark/evaluation scripts, downloaded checkpoints, model assets, binaries, or build helpers are committed. Added standalone tooling includes the drafter exporter and the native version-1 replacement fold converter/test. No Mobius PR is needed because the exporter/runtime changes are in GenAI.

Validation of this rebased GenAI branch

  • Fresh CUDA CMake/Ninja build passed against the existing integration ORT SDK/provider, not a new all-branches ORT build.
  • Focused native tests (*Qwen38*:*Dflash2*:*DFlash2*): 147 passed, 1 skipped, 1 disabled test not executed.
  • Actual H200 model smoke using rebuilt runtime and rebuilt data plane: exact 64-token Engine/Generator parity with the previously tested candidate at 2048 and 8193 prompt tokens, including repeated requests and native Engine warmup. No DFlash failure/disable counters.
  • Generator full logits checked twice at every emission: finite, stable, and argmax equal to the next reference token; observed buffered queue sizes 0/1/2/3.
  • Rebuilt GPU lattice-selection and prefill-argmax reference tests: 2 passed, including ties/control preservation.
  • Portable FP8 exporter executed successfully on the pinned real DFlash2 checkpoint and target. BF16 export mode is not separately qualified here.
  • git diff --check and changed-line C++ formatting passed.

The three companion ORT branches have source/test translation-unit compilation only at this publication stage. The original combined experiment passed 24 numeric reference tests, but that is not exact-rebase operator qualification. A clean combined-branch ORT build and full numerical/accuracy qualification remain pending; therefore this is a draft integration PR.

Historical combined-stack H200 results

INT2 Qwen target + FP8 DFlash2; greedy batch one; six-run means:

Context Decode tokens/s TTFT ms
2K 333.964 580.497
8K 342.140 2421.365
16K 339.684 5030.850
32K 336.767 10520.556

Peak sampled GPU memory: 59.350 GiB, versus 64.322 GiB fresh old-runtime control. Exact 512-token parity with the prior DFlash candidate at all four contexts. Steady-state profiling observed no cudaDeviceSynchronize/cudaHostAlloc, with lattice selection and fused INT2 FC2 kernels present.

These are historical results for the previously tested combined experimental integration, not fresh six-run measurements of this rebased branch or per-component ablations. Synthetic prompts have unusually high draft acceptance; real-code throughput/acceptance varies.

Accuracy caveats

  • HumanEval: DFlash and same-S4 perturbed-draft control both 154/164 (93.90%), exact token/program parity across all 164, draft acceptance 95.40%. Perturbing drafts is not a guaranteed zero-acceptance control. Three responses hit the 1024-token cap and were counted as failures.
  • Five original LiveCodeBench problems, one completion each: DFlash 2/5 versus historical MTP 3/5. abc400_d regressed to a capacity-limited incomplete result; abc400_e and abc400_g also hit session capacity. Historical MTP is not a matched same-S4 control.
  • Broader S2/MTP versus S4 numerical differences and target-specific accuracy qualification remain open. Do not promote this stack as an accuracy-qualified default based on synthetic speed alone.

Companion ORT draft PRs

Native fold version-1 replacement update

Commit efb26517 updates the graph converter, tests, and migration documentation to normalize legacy com.microsoft::FoldMid2 / FoldTail graphs to the native version-1 replacement schema. Companion ORT PR: microsoft/onnxruntime#33550 (base asonawane/main-ops-mtp-fold-state).

The converter preserves external-weight paths, exposes aliased control/context outputs and adds the mid-to-tail state dependency. It rejects repeat conversion and mismatched legacy control buffers. After conversion, the cleaned package no longer registers or distributes libqwen_fold.so or other ONNX custom-op libraries, and no longer bundles provider/runtime directories. It still retains libdflash_plane_v2.so, a required runtime helper, not an ONNX custom-op registration library. Source-built ORT core/provider and GenAI are required; stock upstream wheels are insufficient.

Validation: all 4 converter tests passed on this publication branch; the combined converter/target-graph suite passed 14 tests. Previously reported combined-stack model parity and cleaned-package checks predate the version-1 replacement and are historical only. The five ORT GPU tests reported for the earlier v2 implementation do not validate this revision; ORT CUDA and InferenceSession tests remain pending a configured build/CI. Existing performance/accuracy caveats above still apply.

Include native Engine and multi-row verification prerequisites, persistent staging, shared-stream GPU lattice selection, DFlash-only memory reductions, per-emission buffered logits, and a portable BF16/FP8 drafter exporter. Honor explicit ORT_LIB_PATH for custom runtime builds. Preserve published graph/resource behavior and device-only shared-weight placement.

Fresh CUDA build and focused C++ checks: 147 passed, one skipped. Exact 64-token Engine/Generator parity at 2048 and 8193 tokens with repeated per-emission logits checks. Exporter FP8 smoke and rebuilt plane tests passed. Combined historical experiment and accuracy caveats are documented in the PR description.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Supported-platform build failures and rejection of headless DFlash-only configurations remain unresolved.

4 open issues
What changed in this PR

Integrates three-token DFlash2 drafting with four-row Qwen graph verification through GenAI’s native Engine and Generator. This remains a draft integration dependent on companion ORT changes, with combined-stack numerical qualification pending.

Changes:

  • Adds a single-slot Engine executor, multi-row device contract, and request lifecycle tests.
  • Introduces asynchronous device drafting, unified prefill, and per-emission buffered logits.
  • Adds a local-checkpoint drafter exporter and honors explicit Python ORT_LIB_PATH selection.
File Description
tools/​qwen38_graph/​README.md Documents integration, export, configuration, and qualification limits.
tools/​qwen38_graph/​export_dflash2.py Adds BF16/FP8 drafter export using target embeddings and head.
test/​cpp/​engine/​qwen38_graph_test_doubles.h Adds a scripted multi-draft device.
test/​cpp/​engine/​qwen38_graph_executor_tests.cpp Tests execution, limits, cancellation, continuation, and failures.
src/​qwen38_plane/​qwen38_plane.cu Adds device lattice selection, argmax completion, and CUDA helpers.
src/​python/​py/​_dll_directory.py Gives explicit ORT_LIB_PATH precedence.
src/​models/​qwen38_suffix_drafter.h Adds historical suffix-based draft proposals.
src/​models/​qwen38_graph.h Declares multi-row execution and DFlash state.
src/​models/​qwen38_graph.cpp Integrates DFlash drafting and multi-row verification.
src/​models/​qwen38_graph_prefill.cpp Adds unified prefill and lazy logits readback.
src/​models/​qwen38_decode_device.h Defines the portable device contract and state ledger.
src/​engine/​scheduler.cpp Honors backend-specific static batch limits.
src/​engine/​scheduled_requests.h Declares executor-selected token staging.
src/​engine/​scheduled_requests.cpp Commits staged tokens through requests.
src/​engine/​request.h Declares external token commitment.
src/​engine/​request.cpp Applies stopping rules to externally selected tokens.
src/​engine/​qwen38_graph_executor.h Defines the Qwen session, cache manager, and executor.
src/​engine/​qwen38_graph_executor.cpp Implements single-slot Engine execution and device leasing.
src/​engine/​model_executor.h Adds token-selection, validation, and statistics hooks.
src/​engine/​engine.cpp Routes Qwen models through the new executor.
src/​engine/​cache_manager.h Adds static backend capacity hooks.
src/​dflash2_drafter.h Exposes device-selection outputs and persistent staging.
src/​dflash2_drafter.cpp Reuses staging buffers and supports asynchronous proposals.
src/​decoding/​qwen38_graph_strategy.h Consolidates speculative statistics storage.
src/​decoding/​qwen38_graph_strategy.cpp Handles multi-token queues and buffered logits.
src/​config.h Adds prefill and suffix-lookup settings.
src/​config.cpp Parses and validates the new settings.

Review effort: Balanced

Comment thread src/engine/engine.cpp
Comment on lines +302 to +304
if (auto graph_model = std::dynamic_pointer_cast<Qwen38GraphModel>(model)) {
return CreateQwen38GraphDependencies(std::move(graph_model));
}

#include <cstddef>
#include <cstdint>
#include <span>
throw std::runtime_error("qwen38_graph: invalid numerical shadow cache " + name);
shape[0] = 1;
if (scoring) {
if (!name.ends_with(".scoring"))
Comment on lines +1558 to +1559
if (q.fold.head_r2.filename.empty() && config_->model.dflash2.filename.empty())
throw std::runtime_error("model.qwen38_graph.fold.head_r2.filename is required");
Expose aliased control/context outputs and order tail publication after the mid-stage state update; document custom-op removal and retained runtime helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pack target weights and PLE into one external file, omit inactive head graphs, support headless folded configuration, and extend cache/rotary/pool contracts with four internal guard slots.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@apsonawane

Copy link
Copy Markdown
Contributor Author

Published consolidation and native 262K support in 7b22453. Includes out-of-place single-target-data packing, removal of inactive graph references, native-context exporter and rotary/KV/index/shared-pool updates. Validation: exact 512-token short-context parity, full 262112-prompt + 32-output boundary twice, zero fallback/DFlash failure/disable counters, EOS/logits checks, 148 native tests passed (1 skipped, 1 disabled). Peak sampled GPU memory at full window: 66.68 GiB on H200. Target KV/index allocation remains full-capacity rather than input-sized; long-context task accuracy is not qualified. Model assets and binaries are not committed. Data-plane integration is the next separate change.

Replace model-local helper loading with a version/size-checked function table from the existing GenAI CUDA library. Remove the standalone helper target and reject obsolete library settings with a migration diagnostic. Update packaging, documentation and native/CUDA regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pin the published combined ORT source and integrated GenAI data plane. Cover source checkout, CUDA plugin builds, model conversion prerequisites, packaging, native context, runtime tuning and validation limits.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@apsonawane

Copy link
Copy Markdown
Contributor Author

Latest integration source is now fully committed and published. GenAI runtime db154bc integrates the Qwen data plane into the standard CUDA add-on: no model-local libdflash_plane_v2.so, no separate helper target, and an explicit migration diagnostic for legacy plane_library configs. Documentation-only tip 65424b4 adds the complete pinned-source build/conversion/run guide at tools/qwen38_graph/BUILD_AND_RUN.md. This supersedes older notes saying a separate runtime helper remains required.

Companion complete combined ORT integration branch: asonawane/remaining-standard-op-fusions at 13aa2a1e428a1e31ebc6f027e774674bc27d0aef (https://github.com/microsoft/onnxruntime/tree/asonawane/remaining-standard-op-fusions). Incremental operator PRs remain separate; no cherry-pick recipe onto main is implied.

Pre-publication checks: combined ORT core/CUDA-plugin/provider-test build passed; 5 fold GPU tests passed. GenAI build and 150 native tests passed (1 skipped, 1 disabled), plus 15 source-tool tests and 4 integrated CUDA tests. Earlier exact source-content model validation preserved 512 token IDs at 2048/8192/16384/32768/8193, passed the 262112+32 boundary twice, EOS/logits and no-helper process mappings, with zero fallback/failure/disable counters. Full-window sampled peak: 67.13 GiB. No new full-model run or from-empty build was performed during this publication because GPUs are occupied. Accuracy caveats remain; model assets are not uploaded or committed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Tianlei Wu (tianleiwu) pushed a commit to microsoft/onnxruntime that referenced this pull request Oct 23, 2026
## Summary
Replace the existing `com.microsoft` speculative-fold operators at opset
1 with the multi-row implementation required by Qwen/DFlash
verification. No opset-2 schemas or kernels are added; model imports
remain compatible with the supported `[1, 1]` `com.microsoft` domain
range.

- Support multi-row verification and muted prefill, including row counts
greater than `head_rows`.
- Preserve the combined verifier/downstream error status through
`FoldTail`.
- Add an InferenceSession load/run regression and CUDA launcher
coverage.
- Update the operator references and migration guide.

## Related GenAI changes
- [GenAI
#2771](microsoft/onnxruntime-genai#2771)
normalizes converted graphs to the version-1 replacement schema (latest
commit `efb26517`).
- [GenAI
#2776](microsoft/onnxruntime-genai#2776) emits
`com.microsoft` opset 1 for the procedural graph builder (latest commit
`2e63ae0c`).

## Base
Incremental PR against `asonawane/main-ops-mtp-fold-state`.

## Validation
- `lintrunner -a` passed for all touched ORT and GenAI paths; `git diff
--check` passed.
- GenAI graph-builder tests: **10 passed, 3 subtests passed**.
- GenAI converter and target-graph tests: **14 passed**.
- ORT C++/CUDA tests and generated-doc validation could not be run
locally: this worktree has no configured ORT build directory or `nvcc`.
These require CI/configured-build verification.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants