Skip to content

Replace speculative fold operators at version 1 - #33550

Merged
Tianlei Wu (tianleiwu) merged 2 commits into
asonawane/main-ops-mtp-fold-statefrom
asonawane/dflash2-fold-contrib-v2
Oct 23, 2026
Merged

Tianlei Wu (tianleiwu) merged 2 commits into
asonawane/main-ops-mtp-fold-statefrom
asonawane/dflash2-fold-contrib-v2

Conversation

@apsonawane

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

Copy link
Copy Markdown
Contributor

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 normalizes converted graphs to the version-1 replacement schema (latest commit efb26517).
  • 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.

Preserve FoldMid2/FoldTail v1, add explicit aliased state outputs and deferred ring publication, and cover S1-S4 acceptance and captured replay.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread onnxruntime/contrib_ops/cuda/llm/speculative_fold_v2.cc Fixed

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

The Microsoft domain version limit blocks normal v2 model loading, and host validation rejects supported muted-prefill row counts.

4 open issues
What changed in this PR

Adds native CUDA v2 speculative-fold operators for multi-row DFlash verification, replacing the legacy custom-op dependency while leaving v1 implementations unchanged.

Changes:

  • Adds v2 schemas, CUDA registrations, and host validation for configurable head rows, cache capacity, and optional hidden-state padding.
  • Defers result-ring publication until tail validation completes.
  • Adds five CUDA tests, test-build integration, and migration documentation.
File Description
onnxruntime/​test/​contrib_ops/​cuda_kernels/​speculative_fold_v2_test.cc Tests acceptance, publication, metadata validation, and graph replay.
onnxruntime/​core/​graph/​contrib_ops/​ms_opset.h Registers the v2 operator schemas.
onnxruntime/​core/​graph/​contrib_ops/​bert_defs.cc Defines v2 interfaces and shape inference.
onnxruntime/​contrib_ops/​cuda/​llm/​speculative_fold_v2.h Declares CUDA launcher interfaces.
onnxruntime/​contrib_ops/​cuda/​llm/​speculative_fold_v2.cu Implements acceptance, padding, and deferred publication.
onnxruntime/​contrib_ops/​cuda/​llm/​speculative_fold_v2.cc Adds host validation and aliased state outputs.
onnxruntime/​contrib_ops/​cuda/​cuda_contrib_kernels.cc Registers v2 CUDA kernels.
docs/​contrib_ops/​cuda/​speculative_fold.md Documents state handling and migration.
cmake/​onnxruntime_unittests.cmake Includes v2 tests and kernels in the test build.

Review effort: Balanced

Comment thread onnxruntime/core/graph/contrib_ops/ms_opset.h Outdated
Comment thread onnxruntime/contrib_ops/cuda/llm/speculative_fold_v2.cc Outdated
Comment thread onnxruntime/test/contrib_ops/cuda_kernels/speculative_fold_v2_test.cc Outdated
Comment thread onnxruntime/core/graph/contrib_ops/bert_defs.cc Outdated
Comment thread onnxruntime/core/graph/contrib_ops/ms_opset.h Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@apsonawane Akshay Sonawane (apsonawane) changed the title Add native speculative fold v2 for multi-row DFlash verification Replace speculative fold operators at version 1 Oct 23, 2026

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

Missing test headers, incompatible graph-output alias assumptions, and an outdated assertion prevent the session regression from compiling and passing.

3 open issues
4 resolved since last review

Review effort: Balanced

Comment on lines +74 to +75
ORT_ENFORCE(updated_ctl->DataRaw() == ctl->DataRaw() && updated_context->DataRaw() == committed->DataRaw(),
"FoldMid2 requires aliased control/context outputs");
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
EXPECT_TRUE(status.IsOK()) << status;
if (status.IsOK()) {
EXPECT_EQ(outputs[6].Get<Tensor>().Data<int64_t>()[0], muted ? 0 : 1);
EXPECT_EQ(outputs[10].Get<Tensor>().Data<int32_t>()[0], muted ? 0 : 1);
@tianleiwu
Tianlei Wu (tianleiwu) merged commit efa5ab5 into asonawane/main-ops-mtp-fold-state Oct 23, 2026
7 checks passed
@tianleiwu
Tianlei Wu (tianleiwu) deleted the asonawane/dflash2-fold-contrib-v2 branch October 23, 2026 23:27
@tianleiwu

Copy link
Copy Markdown
Contributor

Squashed into #33474 (asonawane/main-ops-mtp-fold-state). Closing this stacked PR.

Tianlei Wu (tianleiwu) added a commit that referenced this pull request Oct 23, 2026
…ty, optional in-place ctl/ctx) and remove unused MtpMoe

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants