Skip to content

[https://nvbugs/6120981][fix] Switch to cu_seqlens_to_chunk_indices_offsets_triton with total_seqlens/extra_ch - #13566

Merged
tcherckez-nvidia merged 2 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6120981
May 25, 2026
Merged

[https://nvbugs/6120981][fix] Switch to cu_seqlens_to_chunk_indices_offsets_triton with total_seqlens/extra_ch#13566
tcherckez-nvidia merged 2 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-bug6120981

Conversation

@tensorrt-cicd

@tensorrt-cicd tensorrt-cicd commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Root cause: GPU->CPU sync in cu_seqlens_to_chunk_indices_offsets deadlocks with pending NCCL all-to-all from MoE expert-parallel layers
  • Fix: Switch to cu_seqlens_to_chunk_indices_offsets_triton with total_seqlens/extra_chunks pre-computed from CPU tensors (batch_info_host, seq_len_host); add output_size to repeat_interleave
  • Automated fix generated by repair-bot

Test plan

  • Verify fix on the same GPU type as the original failure
  • Check for regressions in related tests

Links

Summary by CodeRabbit

  • Bug Fixes

    • Improved Mamba model metadata handling and computation for better stability and accuracy in sequence processing.
  • Performance

    • Optimized metadata preparation path using Triton-based computation for enhanced efficiency in Mamba model inference.

@coderabbitai

coderabbitai Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes refactor Mamba metadata computation by introducing a new compute_extra_chunks_cpu helper function and updating the _mamba_ssm_prepare_metadata signature to accept an additional seq_len_host parameter. Existing inline computation is replaced with this helper function and a Triton-based path for chunk index/offset operations.

Changes

Cohort / File(s) Summary
Mamba Backend Custom Op
tensorrt_llm/_torch/auto_deploy/custom_ops/mamba/mamba_backend_common.py
Updated _mamba_ssm_prepare_metadata and _mamba_ssm_prepare_metadata_fake signatures to accept seq_len_host tensor parameter. Replaced inline chunk index computation with Triton-based path using compute_extra_chunks_cpu helper, adjusted seq_idx_prefill allocation with new output_size parameter.
Mamba Metadata Helper
tensorrt_llm/_torch/modules/mamba/mamba2_metadata.py
Introduced new compute_extra_chunks_cpu helper function that encapsulates CPU-side extra chunks computation. Refactored Mamba2Metadata.prepare to replace inline cumsum/modulo loop with call to the new helper function.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 title clearly identifies the main change: switching to cu_seqlens_to_chunk_indices_offsets_triton with pre-computed total_seqlens and extra_chunks, directly addressing the core fix.
Description check ✅ Passed The PR description explains the root cause, fix, and test plan, though it lacks details on how the changes work and doesn't follow the template's Description section structure.
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.

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

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

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.

🧹 Nitpick comments (1)
tensorrt_llm/_torch/modules/mamba/mamba2_metadata.py (1)

66-77: Harden compute_extra_chunks_cpu against accidental CUDA inputs.

This helper is specifically for host-side computation; a CUDA tensor here can reintroduce sync risk. Consider a fail-fast guard.

Proposed patch
-def compute_extra_chunks_cpu(seq_lens, num_seqs: int, chunk_size: int) -> int:
+def compute_extra_chunks_cpu(
+    seq_lens: torch.Tensor | list[int], num_seqs: int, chunk_size: int
+) -> int:
     """Count extra chunks caused by misaligned sequence boundaries.
 
     Computes from CPU seq_lens to avoid GPU->CPU synchronization.
     """
+    if isinstance(seq_lens, torch.Tensor) and seq_lens.is_cuda:
+        raise ValueError("seq_lens must be a CPU tensor")
+
     cumsum = 0
     extra = 0
     for i in range(num_seqs - 1):
         cumsum += int(seq_lens[i])
         if cumsum % chunk_size != 0:
             extra += 1
     return extra
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tensorrt_llm/_torch/modules/mamba/mamba2_metadata.py` around lines 66 - 77,
The function compute_extra_chunks_cpu must fail fast on CUDA inputs to avoid
accidental GPU->CPU syncs: at the start of compute_extra_chunks_cpu detect if
seq_lens is a torch Tensor on CUDA (e.g., has .device and .device.type ==
"cuda") and raise a clear TypeError telling callers to pass a CPU tensor/ndarray
or call .cpu()/.tolist() first; ensure the check is a simple predicate so Python
lists/ndarrays remain supported and keep the rest of the logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tensorrt_llm/_torch/modules/mamba/mamba2_metadata.py`:
- Around line 66-77: The function compute_extra_chunks_cpu must fail fast on
CUDA inputs to avoid accidental GPU->CPU syncs: at the start of
compute_extra_chunks_cpu detect if seq_lens is a torch Tensor on CUDA (e.g., has
.device and .device.type == "cuda") and raise a clear TypeError telling callers
to pass a CPU tensor/ndarray or call .cpu()/.tolist() first; ensure the check is
a simple predicate so Python lists/ndarrays remain supported and keep the rest
of the logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7335ea2c-1415-46be-b1a0-fff61987ad73

📥 Commits

Reviewing files that changed from the base of the PR and between 1e8640c and eb1231c.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/auto_deploy/custom_ops/mamba/mamba_backend_common.py
  • tensorrt_llm/_torch/modules/mamba/mamba2_metadata.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

[Repair Bot] Attempted automated rebase/maintenance, but could not complete it safely. Leaving the PR unchanged.

Reason:

reserve_gpu: sbatch failed: SSH to computelab-sc-01 timed out after 120s

The bot will try again on a later cycle. Manual rebase is also fine.

@suyoggupta

Copy link
Copy Markdown
Collaborator

@tcherckez-nvidia : any updates here. Have we checked if it fixes https://nvbugs/6120981?

@tcherckez-nvidia

tcherckez-nvidia commented May 14, 2026

Copy link
Copy Markdown
Collaborator

@suyoggupta Looked at it, and I can understand the fix, but I'm not that familiar with the code.
How can we tell this fix the bug? AFAIU this is a flaky bug.
I'll rebase it locally and run it a few times, other then that I don't have a better idea

@tcherckez-nvidia
tcherckez-nvidia force-pushed the repair-bot-bug6120981 branch from eb1231c to e6a83b5 Compare May 14, 2026 13:19
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run --stage-list "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48370 [ run ] triggered by Bot. Commit: e6a83b5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48370 [ run ] completed with state FAILURE. Commit: e6a83b5
/LLM/main/L0_MergeRequest_PR pipeline #38176 (Partly Tested) 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

@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run --stage-list "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48391 [ run ] triggered by Bot. Commit: e6a83b5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48391 [ run ] completed with state FAILURE. Commit: e6a83b5
/LLM/main/L0_MergeRequest_PR pipeline #38194 (Partly Tested) 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

@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6120981 branch 4 times, most recently from c507cb9 to 0546861 Compare May 15, 2026 08:27
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run --stage-list "DGX_B200-4_GPUs-AutoDeploy-1, DGX_H100-4_GPUs-AutoDeploy-1"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48741 [ run ] triggered by Bot. Commit: 0546861 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48741 [ run ] completed with state FAILURE. Commit: 0546861
/LLM/main/L0_MergeRequest_PR pipeline #38508 (Partly Tested) 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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48838 [ run ] triggered by Bot. Commit: 0546861 Link to invocation

@tcherckez-nvidia
tcherckez-nvidia enabled auto-merge (squash) May 18, 2026 07:24
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48838 [ run ] completed with state SUCCESS. Commit: 0546861
/LLM/main/L0_MergeRequest_PR pipeline #38596 (Partly Tested) 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

@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48900 [ run ] triggered by Bot. Commit: 0546861 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #48900 [ run ] completed with state SUCCESS. Commit: 0546861
/LLM/main/L0_MergeRequest_PR pipeline #38649 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

@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6120981 branch from 0546861 to 1ed51c6 Compare May 18, 2026 19:34
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #49223 [ run ] triggered by Bot. Commit: 1ed51c6 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #49223 [ run ] completed with state SUCCESS. Commit: 1ed51c6
/LLM/main/L0_MergeRequest_PR pipeline #38896 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

@tcherckez-nvidia
tcherckez-nvidia force-pushed the repair-bot-bug6120981 branch from 1ed51c6 to 4c68b9a Compare May 20, 2026 04:29
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

1 similar comment
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd
tensorrt-cicd force-pushed the repair-bot-bug6120981 branch from 4c68b9a to 84f3c9f Compare May 21, 2026 11:22
…M metadata to prevent EP deadlock

Replace cu_seqlens_to_chunk_indices_offsets (which iterates GPU tensor elements
causing implicit cudaStreamSynchronize) with cu_seqlens_to_chunk_indices_offsets_triton.
Pre-compute total_seqlens and extra_chunks from CPU-side batch_info_host and
seq_len_host tensors. Add output_size to repeat_interleave to avoid its implicit sync.

This prevents deadlocks when NCCL all-to-all collectives from MoE expert-parallel
layers are pending, as the GPU->CPU sync would block waiting for the collective
while other ranks are still executing MoE layers.

Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
@tcherckez-nvidia
tcherckez-nvidia force-pushed the repair-bot-bug6120981 branch from 84f3c9f to fa1ceae Compare May 24, 2026 05:23
@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #50081 [ run ] triggered by Bot. Commit: fa1ceae Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #50081 [ run ] completed with state SUCCESS. Commit: fa1ceae
/LLM/main/L0_MergeRequest_PR pipeline #39635 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

@tcherckez-nvidia

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #50143 [ run ] triggered by Bot. Commit: fa1ceae Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator Author

PR_Github #50143 [ run ] completed with state SUCCESS. Commit: fa1ceae
/LLM/main/L0_MergeRequest_PR pipeline #39693 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@tcherckez-nvidia
tcherckez-nvidia merged commit 998f418 into NVIDIA:main May 25, 2026
7 checks passed
KleinBlueC pushed a commit to KleinBlueC/TensorRT-LLM that referenced this pull request May 26, 2026
…ffsets_triton with total_seqlens/extra_ch (NVIDIA#13566)

Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
greg-kwasniewski1 added a commit to nv-auto-deploy/TensorRT-LLM that referenced this pull request May 27, 2026
…ixed by previous commit

Removes the two SKIP entries from tests/integration/test_lists/waives.txt
that were tagged with NVBUG 6221483:

  - accuracy/test_llm_api_autodeploy.py::TestNemotronSuperV3::test_mtp[nvfp4_ws4_80gb-trtllm]
  - accuracy/test_llm_api_autodeploy.py::TestNemotronUltraV3::test_accuracy[nvfp4-4]

Both share the same mamba_backend_common.py code path that was reverted to
its pre-NVIDIA#13566 state in the previous commit, so the fix should cover both.
The fp8 variant (TestNemotronSuperV3::test_mtp[fp8_ws4_80gb-trtllm]) was
never in waives.txt - it was running and failing on DGX_H100-4_GPUs stage
already; the AutoDeploy CI stages triggered on this PR exercise it.

Fixes NVIDIA#14595

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
bmarimuthu-nv pushed a commit to nv-auto-deploy/TensorRT-LLM that referenced this pull request May 28, 2026
…ffsets_triton with total_seqlens/extra_ch (NVIDIA#13566)

Signed-off-by: tensorrt-cicd <90828364+tensorrt-cicd@users.noreply.github.com>
galagam added a commit that referenced this pull request May 28, 2026
…etadata to pre-#13566 state (#14640)

Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Signed-off-by: Gal Hubara-Agam <96368689+galagam@users.noreply.github.com>
Co-authored-by: Gal Hubara-Agam <96368689+galagam@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.

4 participants