Skip to content

[CUDA] Add compact GatedDeltaNet operator - #32282

Merged
Tianlei Wu (tianleiwu) merged 8 commits into
mainfrom
tlwu/qwen_gdn_paged_v2
Aug 28, 2026
Merged

Tianlei Wu (tianleiwu) merged 8 commits into
mainfrom
tlwu/qwen_gdn_paged_v2

Conversation

@tianleiwu

@tianleiwu Tianlei Wu (tianleiwu) commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

  • Add the CUDA GatedDeltaNet contrib operator with recurrent decode and tensor-core chunked prefill paths.
  • Support ragged and rank-4 inputs, fused Qwen gate normalization, and native GDN arithmetic from raw A_log.
  • Return the compact three-output ABI [output, final_state, state_update]. The FP32 state_update capsule packs decay, shared-key, and delta transitions needed to replay accepted speculative prefixes without materializing dense recurrent checkpoints.
  • Add schema and shape validation, CUDA registration, focused tests, a microbenchmark, and an authored operator guide.

Motivation and Context

Dense recurrent checkpoints scale the full FP32 state with draft width. At the Qwen3.8 geometry, a four-slot window across 48 GDN layers consumes 576 MiB. Compact transition capture keeps one committed state and records only the information needed to reconstruct an accepted prefix.

The schema intentionally exposes only native arithmetic and does not include the experimental arithmetic_mode attribute. Models exported with the retired experimental ABI must be re-exported.

Companion ONNX Runtime GenAI integration: microsoft/onnxruntime-genai#2472

Validation

  • ./build/cu130/Debug/onnxruntime_provider_test --gtest_filter='*GatedDeltaNet*'
  • 26/26 focused tests passed on H200 with CUDA 13.0 and cuDNN 9.23.

Performance and Quality

On H200, context 2048, generation 256, with five paired fresh-process repetitions per batch:

  • Native arithmetic won all 40 MTP and DFlash2 throughput pairs versus the retired compatibility experiment. Median native/compatibility ratios were 1.0519 for MTP and 1.0543 for DFlash2.
  • Paired quality differences were not statistically significant: MMLU-Pro 83.75% native vs. 83.38% compatibility (McNemar p=0.73); GPQA 81.82% vs. 78.28% (p=0.23).
  • Against the retired separate-factor representation, the packed capsule preserved exact tokens and replay work. It won 20/20 MTP pairs and was at parity for DFlash2 batch 16, with a small-batch benefit.

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.

Pull request overview

Adds CUDA GatedDeltaNet and compact state updates, extends paged attention and quantized GEMV paths for speculative decoding, and adds supporting tests and documentation.

Changes:

  • Adds GatedDeltaNet and packed variable-length causal convolution.
  • Extends paged attention with non-causal FlashAttention support.
  • Expands small-M and quantized GEMV kernels to 64 rows.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
onnxruntime/core/graph/contrib_ops/bert_defs.cc Adds schemas and causality attribute.
onnxruntime/core/graph/contrib_ops/ms_opset.h Registers new schemas.
onnxruntime/contrib_ops/cuda/cuda_contrib_kernels.cc Registers CUDA kernels.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net.h Declares GDN kernel.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net.cc Validates and dispatches GDN.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_impl.h Defines GDN launch interface.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_impl.cu Implements recurrent/chunked GDN.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_mma.cuh Adds tensor-core primitives.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_plan.h Defines planning heuristics.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_plan.cc Implements plan caching.
onnxruntime/contrib_ops/cuda/bert/gated_delta_net_split_impl.cu Adds split chunked engine.
onnxruntime/contrib_ops/cuda/bert/varlen_causal_conv_with_state.h Declares packed convolution.
onnxruntime/contrib_ops/cuda/bert/varlen_causal_conv_with_state.cc Validates packed convolution inputs.
onnxruntime/contrib_ops/cuda/bert/varlen_causal_conv_with_state_impl.cu Implements packed convolution.
onnxruntime/contrib_ops/cuda/bert/paged_attention.h Stores causality configuration.
onnxruntime/contrib_ops/cuda/bert/paged_attention.cc Routes non-causal attention.
onnxruntime/contrib_ops/cuda/bert/paged_attention_impl.cu Passes causality to FlashAttention.
onnxruntime/contrib_ops/cuda/bert/group_query_attention.cc Allows batched subsequent prompts.
onnxruntime/contrib_ops/cuda/bert/causal_conv_with_state.cc Improves validation context.
onnxruntime/contrib_ops/cpu/bert/group_query_attention_helper.h Adds prompt-validation override.
onnxruntime/contrib_ops/cpu/bert/causal_conv_with_state.cc Supplies operator name to validation.
onnxruntime/contrib_ops/cpu/bert/causal_conv_with_state_helper.h Generalizes validation messages.
onnxruntime/contrib_ops/cpu/bert/attention_parameters.h Adds paged-attention causality state.
onnxruntime/core/providers/cuda/math/matmul.cc Moves counter initialization into launcher.
onnxruntime/core/providers/cuda/math/matmul_small_n_gemv.h Documents 64-row support.
onnxruntime/core/providers/cuda/math/matmul_small_n_gemv.cu Adds chunked row launches.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp8.h Exposes FP8 GEMV limit.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp8.cc Uses dynamic FP8 GEMV limit.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp8.cu Adds multi-row FP8 MMA.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp4.h Exposes FP4 GEMV limit.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp4.cc Uses dynamic FP4 GEMV limit.
onnxruntime/contrib_ops/cuda/math/matmul_block_scaled_fp4.cu Adds multi-row FP4 MMA.
onnxruntime/python/tools/microbench/gdn.py Adds GDN microbenchmark.
onnxruntime/test/python/transformers/test_paged_attention.py Tests non-causal paged attention.
onnxruntime/test/providers/cuda/test_cases/matmul_small_n_gemv_op_test.cc Tests expanded GEMV shapes.
onnxruntime/test/contrib_ops/matmul_block_scaled_fp8_test.cc Tests FP8 row tiling.
onnxruntime/test/contrib_ops/matmul_block_scaled_fp4_test.cc Tests FP4 row tiling.
onnxruntime/test/contrib_ops/gated_delta_net_op_test.cc Covers GDN behavior and planning.
onnxruntime/test/contrib_ops/causal_conv_with_state_op_test.cc Covers packed convolution.
docs/contrib_ops/cuda/gdn.md Documents GDN contracts and results.
docs/ContribOperators.md Updates generated schemas.
docs/OperatorKernels.md Updates generated kernel inventory.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread docs/ContribOperators.md Resolved
Comment thread docs/OperatorKernels.md Resolved
@tianleiwu
Tianlei Wu (tianleiwu) marked this pull request as draft August 26, 2026 18:50
@tianleiwu Tianlei Wu (tianleiwu) changed the title [CUDA] Add paged GatedDeltaNet with compact state updates [CUDA] Add compact GatedDeltaNet operator Aug 26, 2026
@tianleiwu
Tianlei Wu (tianleiwu) marked this pull request as ready for review August 27, 2026 04:13
Tianlei Wu (tianleiwu) added a commit that referenced this pull request Aug 28, 2026
### Description

- Replace dense `VarlenCausalConvWithState` checkpoint output with the
compact three-output ABI `[output, final_state, state_update]`.
- Add optional per-request `capture_count` input and bounded
`state_update_capacity` attribute.
- Return only the appended activation values required to replay accepted
speculative prefixes, shaped `[batch_size, state_update_capacity,
channels]`.
- Remove the retired `max_checkpoints` attribute and `prefix_states`
output.
- Add schema validation, CUDA shape/runtime checks, and focused
compact-capture tests.

### Motivation and Context

Dense checkpoint output scales the full convolution state with
speculative width. The convolution transition only needs the newly
appended value at each accepted position, so compact capture avoids
duplicating the full `[channels, kernel_size - 1]` state while
preserving exact replay from committed state.

This change is coordinated with the compact GatedDeltaNet operator and
ONNX Runtime GenAI replay integration:

- #32282
- microsoft/onnxruntime-genai#2472

### Validation

- `ContribOpVarlenCausalConvWithStateTest.*`: 39/39 passed on H200 with
CUDA 13.0 and cuDNN 9.23.
- Coverage includes sequential-prefix equivalence, all-ones decode,
adjacent requests, omitted output at zero capacity, capture-count
requirements and shape validation, and capacity bounds.
- File-scoped lintrunner and `git diff --check` passed for all five
changed files.
- Generated `docs/ContribOperators.md` is intentionally excluded and
left to CI generation.

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.

Looks good.

@tianleiwu
Tianlei Wu (tianleiwu) merged commit 7fe62a3 into main Aug 28, 2026
91 of 92 checks passed
@tianleiwu
Tianlei Wu (tianleiwu) deleted the tlwu/qwen_gdn_paged_v2 branch August 28, 2026 06:26
Tianlei Wu (tianleiwu) added a commit to microsoft/onnxruntime-genai that referenced this pull request Aug 28, 2026
## Summary
- export packed Qwen3.5/3.8 linear-attention layers with
`VarlenCausalConvWithState` and `GatedDeltaNet`
- replace dense recurrent checkpoints with compact convolution values
and GDN transition capsules
- export raw `A_log`/`dt_bias` for native Qwen gate arithmetic, without
`arithmetic_mode`
- keep committed paged recurrent state unwindowed, FP32, and V-major
while preserving the dense `LinearAttention` default

The existing `state_groups` schema is unchanged in this PR. Parsing
compact update metadata and replaying these transitions is handled by
the stacked runtime PR #2454.

## Dependencies
- microsoft/onnxruntime#32282
- microsoft/onnxruntime#32290
- microsoft/onnxruntime#32307

## Testing
- `python3 -m pytest test/python/builder/test_decoder_state_groups.py
test/python/builder/test_qwen_vl.py -q` (50 passed)
- `python3 -m pytest test/python/builder -q` (493 passed, 3 skipped)
Tianlei Wu (tianleiwu) added a commit to microsoft/onnxruntime-genai that referenced this pull request Aug 30, 2026
## Summary

Replace dense recurrent checkpoint tensors with compact state-update
replay for dynamically batched hybrid models. The engine now owns fixed
convolution and GatedDeltaNet state beside paged KV cache, captures
packed per-token updates, and replays only an accepted prefix into
inactive state banks before atomically publishing both cache types.

## Stack

- Stacked on #2453, which exports compact Qwen3.5/3.8 `value` and
`capsule` outputs.
- Depends on microsoft/onnxruntime#32282 and
microsoft/onnxruntime#32290.
- MTP scheduling and drafter orchestration remain outside this PR.

## Key Changes

- Parse explicit `paged_kv` and `fixed` decoder state groups, including
compact convolution `value` and GDN `capsule` update bindings.
- Add a fixed-state pool with per-request ownership, double-buffered
publication, compact prefix replay, and CPU/CUDA provider
implementations.
- Add composite paged/fixed reservations with validation and preparation
before the allocation-free publication boundary.
- Bind packed variable-length inputs and fixed state together through
`HybridDecoderIO`, including optional packed `position_ids`.
- Resolve paged cache tensor names from explicit manifest bindings while
retaining legacy name-template synthesis for models without
`state_groups`.
- Add synthetic hybrid/composite fixtures and focused manifest,
reservation, replay, transaction, and end-to-end Engine coverage.

## Memory Impact

The runtime no longer requires dense per-token recurrent checkpoint
outputs. Speculative rollback data is bounded by `state_update_capacity`
and represented as compact convolution values or packed GDN transition
capsules.

## Testing

- `test/python/builder/test_decoder_state_groups.py`: 24 passed
- CPU Debug `engine_unit_tests`: 256 passed
- CUDA Debug `engine_unit_tests` on H200: 261 passed
- Paged and hybrid Engine Python tests across CPU/CUDA: 32 passed
- CUDA compact convolution/GDN partial-prefix replay: passed

## Checklist

- [x] Tests added and updated
- [x] CPU and CUDA replay paths validated
- [x] No MTP/drafter scheduling included
- [x] Existing paged-only Engine behavior preserved

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+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.

3 participants

⌂ 换网址