Repository navigation
[CUDA] Add FoldMid2 and FoldTail speculative state fold contrib operators - #33474
Akshay Sonawane (apsonawane) wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved memory-safety, state-propagation, uninitialized-output, and documentation-validation issues block approval.
6 open issues
Regenerate operator documentation from the updated build · New Initialize the complete public scratch output buffer · New Handle non-finite router logits without generating invalid expert indices · New Return updated fold state through explicit outputs · New Bound rotary-cache accesses to the actual cache extent · New Validate ring metadata before state commit or record access · New
What changed in this PR
Adds CUDA contrib operators for multi-token prediction and speculative decoding directly on main, replacing the earlier stacked PR.
Changes:
- Implements NVFP4
MtpMoeprojections andFoldMid2/FoldTailstate updates. - Adds schemas, CUDA registrations, and operator documentation.
- Adds internal kernel tests; fresh GPU execution remains outstanding.
| File | Description |
|---|---|
| onnxruntime/test/contrib_ops/cuda_kernels/speculative_fold_test.cc | Tests acceptance, state updates, and muted calls. |
| onnxruntime/test/contrib_ops/cuda_kernels/mtp_moe_test.cc | Tests routing and reference projection arithmetic. |
| onnxruntime/core/graph/contrib_ops/ms_opset.h | Registers the three schemas. |
| onnxruntime/core/graph/contrib_ops/contrib_defs.cc | Defines operator contracts and types. |
| onnxruntime/contrib_ops/cuda/llm/speculative_fold.h | Declares fold launchers. |
| onnxruntime/contrib_ops/cuda/llm/speculative_fold.cu | Implements speculative state kernels. |
| onnxruntime/contrib_ops/cuda/llm/speculative_fold.cc | Adds fold validation and CUDA wrappers. |
| onnxruntime/contrib_ops/cuda/llm/mtp_moe.h | Defines dimensions and launcher interfaces. |
| onnxruntime/contrib_ops/cuda/llm/mtp_moe.cu | Implements routing and expert projections. |
| onnxruntime/contrib_ops/cuda/llm/mtp_moe.cc | Adds validation and output allocation. |
| onnxruntime/contrib_ops/cuda/cuda_contrib_kernels.cc | Registers CUDA implementations. |
| docs/ContribOperators.md | Documents the new operators. |
| cmake/onnxruntime_unittests.cmake | Includes internal tests and kernel sources. |
Review effort: Balanced
Keep router expert indices valid for non-finite logits, initialize the public scratch buffer, return fold state through declared reusable outputs, and guard rotary and ring metadata before committing. Add session-level and kernel regressions and regenerate operator documentation.
There was a problem hiding this comment.
🟡 Changes recommended
Accepted row counts exceed CUDA launch limits, and documentation ordering conflicts with generator validation.
2 open issues
6 resolved since last review
Validate ring metadata before state commit or record access Bound rotary-cache accesses to the actual cache extent Return updated fold state through explicit outputs Handle non-finite router logits without generating invalid expert indices Initialize the complete public scratch output buffer Regenerate operator documentation from the updated build
Review effort: Balanced
|
Pushed 24625bf to address both outstanding review threads and the common root cause of all six failed CUDA/TensorRT/plugin pipelines.
Validation: full-PR lintrunner apply/check-only passes, git diff --check passes, affected schema/kernel documentation matches the official Python renderer with source-derived metadata, entire TOC support-level/name ordering passes, and static validation placement checks pass. No local builds or compilation were run. The new native tests were not executed locally. Fresh CI is triggered by this push and is not claimed green. |
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>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ty, optional in-place ctl/ctx) and remove unused MtpMoe Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # docs/ContribOperators.md
efa5ab5 to
a602c0c
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Summary
Adds the$S \in [2, 4]$ DFlash2 verification (squashing #33550 and removing unused
com.microsoft::FoldMid2andcom.microsoft::FoldTail(version 1) CUDA contrib operators for speculative decoding andMtpMoe):com.microsoft::FoldMid2(onnxruntime/contrib_ops/cuda/llm/speculative_fold.{h,cc,cu}):head_rows2 through 4,head_capacity = 262144), prepares head token IDs / cache slots / rotary slices, and updates control/context state (MayInplaceor in-place 7-output DFlash2 mode) and the mapped host result ring.com.microsoft::FoldTail(onnxruntime/contrib_ops/cuda/llm/speculative_fold.{h,cc,cu}):ctl_slotin{-1, 2, 8, 9}), and publishes the result-ring sequence word.