Skip to content

[None][fix] Qwen3.5 DFlash#13782

Merged
amukkara merged 3 commits into
NVIDIA:mainfrom
amukkara:qwen3.5-dflash
May 12, 2026
Merged

[None][fix] Qwen3.5 DFlash#13782
amukkara merged 3 commits into
NVIDIA:mainfrom
amukkara:qwen3.5-dflash

Conversation

@amukkara

@amukkara amukkara commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • DFlash speculative decoding now integrates with Mamba cache synchronization for improved efficiency.
  • Improvements

    • Optimized draft window sizing in speculative decoding paths.
    • Enhanced 3D position ID handling support for MRoPE configurations.
    • Hardened position ID tensor handling for broader compatibility.
  • Tests

    • Added FP8 DFlash decoding test coverage for Qwen models.

Description

Minor fixes to combine DFlash with m-rope and linear attention in Qwen3.5:

  1. Since draft uses standard rope, use text dimension position_ids only in draft forward.
  2. In GDN attention, adjust buffer sizes to account for 2K total draft tokens in DFlash (vs K + 1 for Eagle).
  3. Perform state updates in GDN attention after accepting tokens.

Test Coverage

Added new test tests/integration/defs/accuracy/test_llm_api_pytorch.py::TestQwen3_5_4B::test_dflash
and extended tests/unittest/_torch/speculative/test_dflash.py to test Qwen3.5-4B along with Qwen3-8B.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@amukkara
amukkara marked this pull request as ready for review May 6, 2026 01:20
@amukkara
amukkara requested review from a team as code owners May 6, 2026 01:20
@coderabbitai

coderabbitai Bot commented May 6, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR updates TensorRT-LLM's speculative decoding (DFlash) to support Mamba models with MRoPE (Multi-headed Rotary Position Embeddings). Changes include adjusting draft token budgeting, adding 3D position_id tensor handling for MRoPE, integrating Mamba cache state synchronization into DFlash, and adding corresponding test coverage.

Changes

DFlash with Mamba and MRoPE Support

Layer / File(s) Summary
Draft Token Budget Configuration
tensorrt_llm/_torch/modules/mamba/gdn_mixer.py, tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
Draft token sizing switches from max_draft_len to max_total_draft_tokens in gdn_mixer forward paths; mamba_cache_manager now uses tokens_per_gen_step - 1 instead of max_draft_len for speculative token budgeting.
3D Position ID Handling for MRoPE
tensorrt_llm/_torch/pyexecutor/model_engine.py, tensorrt_llm/_torch/speculative/dflash.py
_preprocess_inputs and _postprocess_inputs detect and adjust 3D position_id tensors (shape [3, 1, N]) using previous_pos_id_offsets_cuda; dflash collapses 3D position_ids to 1D while preserving 2D handling.
Mamba Cache State Synchronization
tensorrt_llm/_torch/speculative/dflash.py
DFlash forward path imports MambaHybridCacheManager and calls update_mamba_states after token acceptance when using Mamba cache manager.
Tests and Configuration References
tests/integration/defs/accuracy/references/gsm8k.yaml, tests/integration/defs/accuracy/test_llm_api_pytorch.py, tests/integration/test_lists/qa/llm_function_core.txt, tests/integration/test_lists/test-db/l0_h100.yml
New test_dflash method added to TestQwen3_5_4B for FP8 DFlash decoding validation; reference accuracy (80.5) added for FP8_BLOCK_SCALES with DFlash; test entries registered in QA and H100 test lists.

Sequence Diagram

sequenceDiagram
    participant User as User/Test
    participant LLM as LLM Engine
    participant DFlash as DFlash Decoder
    participant ModelEng as Model Engine
    participant MambaCache as Mamba Cache Manager
    participant GDNMixer as GDN Mixer

    User->>LLM: Initialize with DFlashDecodingConfig
    LLM->>MambaCache: Create with tokens_per_gen_step budget
    LLM->>DFlash: Setup speculative decoding
    
    User->>LLM: Generate tokens (with position_ids 3D)
    
    loop Speculative Decoding
        DFlash->>ModelEng: _preprocess_inputs (adjust 3D position_ids)
        ModelEng->>GDNMixer: forward_decode/forward_extend
        GDNMixer->>GDNMixer: Use max_total_draft_tokens for sizing
        GDNMixer-->>DFlash: Draft tokens
        DFlash->>DFlash: Verify tokens
    end
    
    DFlash->>MambaCache: update_mamba_states (after acceptance)
    MambaCache->>MambaCache: Sync state with accepted tokens
    
    DFlash->>ModelEng: _postprocess_inputs (adjust 3D position_ids)
    DFlash-->>LLM: Accepted tokens + metadata
    
    LLM-->>User: Generated sequence
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title '[None][fix] Qwen3.5 DFlash' is specific and directly related to the changeset, which includes fixes for DFlash integration with Qwen3.5 model architecture involving m-rope, linear attention (GDN), and speculative decoding.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed PR description clearly explains the three specific fixes for DFlash with m-rope and linear attention in Qwen3.5, includes test coverage details, and all checklist items are addressed.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py (1)

831-833: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

pool_size can be under-allocated for parallel-draft modes.

Line 850 now correctly uses tokens_per_gen_step - 1 for speculative state depth, but Line 833 still sizes the Mamba pool from max_draft_len. When those diverge (parallel-draft modes), dummy-slot reservation can exceed the pool and hit run out of mamba cache blocks.

💡 Suggested fix
-        max_draft_len = (spec_config.max_draft_len
-                         if spec_config is not None else 0)
-        pool_size = max_batch_size + max_draft_len + 1
+        if spec_config is not None:
+            max_runtime_draft_len = max(
+                spec_config.max_draft_len,
+                spec_config.tokens_per_gen_step - 1,
+            )
+        else:
+            max_runtime_draft_len = 0
+        pool_size = max_batch_size + max_runtime_draft_len + 1
@@
-            speculative_num_draft_tokens=(spec_config.tokens_per_gen_step - 1
-                                          if spec_config is not None else None),
+            speculative_num_draft_tokens=(max_runtime_draft_len
+                                          if spec_config is not None else None),

Also applies to: 850-851

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py` around lines 831 -
833, The pool_size is being computed from max_draft_len but the code elsewhere
uses speculative depth = tokens_per_gen_step - 1, so in Mamba cache sizing
replace the use of max_draft_len with a computed speculative_depth (e.g.,
speculative_depth = spec_config.tokens_per_gen_step - 1 if spec_config is not
None else 0) and set pool_size = max_batch_size + speculative_depth + 1; also
update the other sizing/ reservation sites that currently use max_draft_len (the
later usage around the speculative state depth calculation) to use this same
speculative_depth variable so dummy-slot reservation cannot exceed the pool.
🧹 Nitpick comments (1)
tests/integration/test_lists/qa/llm_function_core.txt (1)

734-734: Please confirm perf guardrail coverage for this speculative-decoding change.

Given the PR modifies performance-sensitive speculative decoding/attention execution paths, confirm there is a corresponding perf scenario in tests/integration/test_lists/test-db/l0_perf.yml (and QA llm_perf_* lists if needed), or track it as explicit follow-up.

As per coding guidelines: "If the PR touches performance-sensitive paths ... check whether a perf test entry is present or updated in (a) tests/integration/test_lists/test-db/l0_perf.yml ... and (b) tests/integration/test_lists/qa/llm_perf_*.yml ..."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration/test_lists/qa/llm_function_core.txt` at line 734, Confirm
that the speculative-decoding/attention execution changes touched by the test
accuracy/test_llm_api_pytorch.py::TestQwen3_5_4B::test_dflash are covered by a
perf guardrail: check the L0 perf DB entry (l0_perf.yml) and the QA llm_perf_*
lists for an existing scenario exercising speculative decoding/attention; if
none exists, add a new perf scenario entry that measures latency/throughput for
speculative decoding (referencing test_dflash or an equivalent workload) in
l0_perf.yml and add/track it in the llm_perf_* QA lists, or create a follow-up
tracking ticket if you cannot add it immediately.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py`:
- Around line 831-833: The pool_size is being computed from max_draft_len but
the code elsewhere uses speculative depth = tokens_per_gen_step - 1, so in Mamba
cache sizing replace the use of max_draft_len with a computed speculative_depth
(e.g., speculative_depth = spec_config.tokens_per_gen_step - 1 if spec_config is
not None else 0) and set pool_size = max_batch_size + speculative_depth + 1;
also update the other sizing/ reservation sites that currently use max_draft_len
(the later usage around the speculative state depth calculation) to use this
same speculative_depth variable so dummy-slot reservation cannot exceed the
pool.

---

Nitpick comments:
In `@tests/integration/test_lists/qa/llm_function_core.txt`:
- Line 734: Confirm that the speculative-decoding/attention execution changes
touched by the test
accuracy/test_llm_api_pytorch.py::TestQwen3_5_4B::test_dflash are covered by a
perf guardrail: check the L0 perf DB entry (l0_perf.yml) and the QA llm_perf_*
lists for an existing scenario exercising speculative decoding/attention; if
none exists, add a new perf scenario entry that measures latency/throughput for
speculative decoding (referencing test_dflash or an equivalent workload) in
l0_perf.yml and add/track it in the llm_perf_* QA lists, or create a follow-up
tracking ticket if you cannot add it immediately.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 850a5460-d612-4112-800c-f7996b0ef776

📥 Commits

Reviewing files that changed from the base of the PR and between 28b3471 and 79e3922.

📒 Files selected for processing (8)
  • tensorrt_llm/_torch/modules/mamba/gdn_mixer.py
  • tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tensorrt_llm/_torch/speculative/dflash.py
  • tests/integration/defs/accuracy/references/gsm8k.yaml
  • tests/integration/defs/accuracy/test_llm_api_pytorch.py
  • tests/integration/test_lists/qa/llm_function_core.txt
  • tests/integration/test_lists/test-db/l0_h100.yml

@ziyixiong-nv ziyixiong-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@amukkara
amukkara force-pushed the qwen3.5-dflash branch 2 times, most recently from 3ab415f to 35da95c Compare May 9, 2026 05:23
@amukkara

amukkara commented May 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47477 [ run ] triggered by Bot. Commit: 35da95c Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47477 [ run ] completed with state FAILURE. Commit: 35da95c
/LLM/main/L0_MergeRequest_PR pipeline #37398 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request May 9, 2026
Cherry-pick of NVIDIA#13782:
- Fix mrope position_ids handling in DFlash
- Fix GDN spec verify buffer sizing for DFlash
- Fix GDN/Mamba2 state updates in DFlash
- Add tests

Original-author: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: ziyixiong-nv <219238287+ziyixiong-nv@users.noreply.github.com>
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request May 11, 2026
Cherry-pick of NVIDIA#13782:
- Fix mrope position_ids in DFlash
- Fix GDN verify buffer size for DFlash
- Fix GDN/Mamba2 state updates in DFlash
- Add tests

Original-author: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: ziyixiong-nv <219238287+ziyixiong-nv@users.noreply.github.com>
@amukkara
amukkara requested review from Wanli-Jiang and removed request for omera-nv May 11, 2026 04:43
@amukkara

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47775 [ run ] triggered by Bot. Commit: b9ff7b3 Link to invocation

@symphonylyh symphonylyh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@lancelly lancelly left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM~

amukkara added 3 commits May 12, 2026 00:44
Signed-off-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
@amukkara

Copy link
Copy Markdown
Collaborator Author

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47810 [ kill ] triggered by Bot. Commit: 97fe446 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47810 [ kill ] completed with state SUCCESS. Commit: 97fe446
Successfully killed previous jobs for commit 97fe446

Link to invocation

@amukkara

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47816 [ run ] triggered by Bot. Commit: 97fe446 Link to invocation

@amukkara
amukkara enabled auto-merge (squash) May 12, 2026 04:16
ziyixiong-nv added a commit to ziyixiong-nv/TensorRT-LLM that referenced this pull request May 12, 2026
Cherry-pick of NVIDIA#13782:
- Fix mrope position_ids in DFlash
- Fix GDN verify buffer size for DFlash
- Fix GDN/Mamba2 state updates in DFlash
- Add tests

Original-author: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
Signed-off-by: ziyixiong-nv <219238287+ziyixiong-nv@users.noreply.github.com>
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #47816 [ run ] completed with state SUCCESS. Commit: 97fe446
/LLM/main/L0_MergeRequest_PR pipeline #37704 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Comment thread tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
Comment thread tensorrt_llm/_torch/modules/mamba/gdn_mixer.py
@amukkara

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48005 [ run ] triggered by Bot. Commit: 97fe446 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #48005 [ run ] completed with state SUCCESS. Commit: 97fe446
/LLM/main/L0_MergeRequest_PR pipeline #37841 completed with status: 'SUCCESS'

CI Report

Link to invocation

@amukkara
amukkara merged commit da31744 into NVIDIA:main May 12, 2026
7 checks passed
yufeiwu-nv pushed a commit to yufeiwu-nv/TensorRT-LLM that referenced this pull request May 19, 2026
Signed-off-by: Anurag Mukkara <134339030+amukkara@users.noreply.github.com>
@amukkara
amukkara deleted the qwen3.5-dflash branch July 10, 2026 18:02
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.

8 participants