Skip to content

[https://nvbugs/6422332][fix] Keep SSM cache in weights dtype when ma… - #16065

Merged
nv-guomingz merged 1 commit into
NVIDIA:mainfrom
nv-guomingz:user/guomingz/fix_nvbug_6422332
Jul 8, 2026
Merged

[https://nvbugs/6422332][fix] Keep SSM cache in weights dtype when ma…#16065
nv-guomingz merged 1 commit into
NVIDIA:mainfrom
nv-guomingz:user/guomingz/fix_nvbug_6422332

Conversation

@nv-guomingz

@nv-guomingz nv-guomingz commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

…mba_ssm_cache_dtype is auto

Summary by CodeRabbit

  • Bug Fixes
    • Improved dtype selection for hybrid SSM/Mamba cache allocation, including better handling of nested config values and "auto" settings.
    • Cache allocation now follows the model’s weights dtype in more cases, preventing unintended fallback to float32.
    • Added clearer behavior when checkpoint-declared SSM dtype differs from the cache dtype, with a warning for mismatches.

Description

Test Coverage

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • 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.

@nv-guomingz
nv-guomingz requested a review from a team as a code owner July 7, 2026 10:56
@nv-guomingz
nv-guomingz requested a review from achartier July 7, 2026 10:56
@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "DGX_B200-8_GPUs-PyTorch-PerfSanity-Post-Merge-5"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57994 [ run ] triggered by Bot. Commit: 8aedd43 Link to invocation

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors mamba SSM cache dtype resolution in config_utils.py, splitting the previous single resolver into resolve_ssm_cache_dtype (cache allocation dtype) and resolve_checkpoint_ssm_dtype (checkpoint-declared intent). model_loader.py is updated to use these resolvers and warn on mismatches. Tests are updated to reflect new expected dtypes.

Changes

SSM Cache Dtype Resolution

Layer / File(s) Summary
New dtype resolver helpers
tensorrt_llm/_torch/pyexecutor/config_utils.py
Adds _resolve_config_dtype_field helper and replaces resolve_mamba_ssm_cache_dtype with resolve_ssm_cache_dtype and resolve_checkpoint_ssm_dtype; updates extract_mamba_kv_cache_params fallback to use resolve_ssm_cache_dtype.
Model loader integration and warning
tensorrt_llm/_torch/pyexecutor/model_loader.py
Updates imports and validate_and_set_mamba_ssm_cache_dtype to resolve cache dtype via resolve_ssm_cache_dtype, and warns when resolve_checkpoint_ssm_dtype differs from the "auto"-resolved cache dtype.
Test expectation updates
tests/unittest/_torch/modeling/test_modeling_qwen3_5_vl_moe.py, tests/unittest/_torch/modeling/test_qwen_image_bench_modeling.py
Updates expected mamba_ssm_cache_dtype values from torch.float32 to torch.bfloat16 for "auto" resolution and adds an explicit "float32" opt-in test case.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#14599: Modifies the same Qwen3.5-MoE-VL mamba/SSM hybrid KV-cache dtype resolution logic in config_utils.py and related Qwen3.5-VL test expectations.

Suggested reviewers: yechank-nvidia

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template is mostly unfilled: the Description and Test Coverage sections are empty, so the issue, solution, and tests are missing. Fill in Description with the problem and fix, and add Test Coverage with the relevant tests that cover the new behavior.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is specific and matches the bug fix about keeping the SSM cache in weights dtype for auto.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

@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/pyexecutor/model_loader.py (1)

54-70: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add test coverage for the new checkpoint-dtype mismatch warning.

This is the core of the new warning logic, but no test asserts it actually fires (or is suppressed when dtypes match). test_modeling_qwen3_5_vl_moe.py's fixture already has mamba_ssm_dtype="float32" vs resolved bfloat16 — the exact mismatch scenario — so add a caplog/mock-based assertion there (or a new unit test) verifying logger.warning is invoked with the mismatch message, and ideally a companion case where checkpoint and resolved dtypes match (no warning).

As per path instructions, "Act as a QA engineer reviewing test changes and coverage for TensorRT-LLM ... suggest concrete list file names and whether coverage is sufficient".

🤖 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/model_loader.py` around lines 54 - 70, Add
test coverage for the new checkpoint-dtype mismatch warning in model_loader.py
by asserting the warning path in the relevant model test or a new unit test. Use
the existing mismatch fixture in test_modeling_qwen3_5_vl_moe.py
(mamba_ssm_dtype float32 vs resolved bfloat16) and verify logger.warning is
called with the mismatch message when checkpoint_ssm_dtype differs from
mamba_ssm_cache_dtype in the auto branch. Also add a matching-dtype case to
confirm no warning is emitted when resolve_checkpoint_ssm_dtype and the resolved
cache dtype agree.

Source: Path instructions

🤖 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.

Nitpick comments:
In `@tensorrt_llm/_torch/pyexecutor/model_loader.py`:
- Around line 54-70: Add test coverage for the new checkpoint-dtype mismatch
warning in model_loader.py by asserting the warning path in the relevant model
test or a new unit test. Use the existing mismatch fixture in
test_modeling_qwen3_5_vl_moe.py (mamba_ssm_dtype float32 vs resolved bfloat16)
and verify logger.warning is called with the mismatch message when
checkpoint_ssm_dtype differs from mamba_ssm_cache_dtype in the auto branch. Also
add a matching-dtype case to confirm no warning is emitted when
resolve_checkpoint_ssm_dtype and the resolved cache dtype agree.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ca9aab03-e417-428d-ac18-8506eb37902a

📥 Commits

Reviewing files that changed from the base of the PR and between ce67288 and 8aedd43.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/pyexecutor/config_utils.py
  • tensorrt_llm/_torch/pyexecutor/model_loader.py
  • tests/unittest/_torch/modeling/test_modeling_qwen3_5_vl_moe.py
  • tests/unittest/_torch/modeling/test_qwen_image_bench_modeling.py

@nv-guomingz
nv-guomingz force-pushed the user/guomingz/fix_nvbug_6422332 branch 2 times, most recently from d472023 to 603e5fa Compare July 7, 2026 11:10
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #57994 [ run ] completed with state SUCCESS. Commit: 8aedd43
/LLM/main/L0_MergeRequest_PR pipeline #46664 (Partly Tested) completed with status: 'SUCCESS'

CI Report

Link to invocation

@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run

@nv-guomingz
nv-guomingz requested a review from moraxu July 7, 2026 13:22
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58008 [ run ] triggered by Bot. Commit: 603e5fa Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58008 [ run ] completed with state SUCCESS. Commit: 603e5fa
/LLM/main/L0_MergeRequest_PR pipeline #46678 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

…mba_ssm_cache_dtype is auto

PR NVIDIA#14599 made the 'auto' resolution of mamba_ssm_cache_dtype also honor
the checkpoint's mamba_ssm_dtype field. Qwen3.5 checkpoints declare
mamba_ssm_dtype=float32 (SSM compute intent), so the GDN state cache
silently flipped from bf16 to fp32. An fp32 state cache disables the
FlashInfer bf16-state GDN decode kernel (falls back to the slower Triton
recurrent kernel) and doubles state memory traffic and footprint,
regressing qwen3_5_397b_fp4_dep4_1k1k perf-sanity output throughput by
~19.5% (25435.9 -> 20479.4 tok/s) on B200.

Restore the pre-NVIDIA#14599 behavior: 'auto' resolves from the explicit
mamba_ssm_cache_dtype field (top-level or text_config) and otherwise
falls back to the model weights dtype. The checkpoint's mamba_ssm_dtype
is no longer used for cache allocation; users can still opt in
explicitly via kv_cache_config.mamba_ssm_cache_dtype.

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
@nv-guomingz
nv-guomingz force-pushed the user/guomingz/fix_nvbug_6422332 branch from 603e5fa to 693c414 Compare July 7, 2026 16:05
@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58030 [ run ] triggered by Bot. Commit: 693c414 Link to invocation

@moraxu moraxu 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.

Thanks for updating these snippets

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58030 [ run ] completed with state SUCCESS. Commit: 693c414
/LLM/main/L0_MergeRequest_PR pipeline #46700 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

@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58099 [ run ] triggered by Bot. Commit: 693c414 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58099 [ run ] completed with state SUCCESS. Commit: 693c414
/LLM/main/L0_MergeRequest_PR pipeline #46762 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

@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58150 [ run ] triggered by Bot. Commit: 693c414 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58150 [ run ] completed with state SUCCESS. Commit: 693c414
/LLM/main/L0_MergeRequest_PR pipeline #46803 completed with status: 'SUCCESS'

CI Report

Link to invocation

@nv-guomingz
nv-guomingz merged commit d163e74 into NVIDIA:main Jul 8, 2026
7 checks passed
@nv-guomingz

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "DGX_B200-8_GPUs-PyTorch-PerfSanity-Post-Merge-5"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #58185 [ ] completed with state FAILURE. Commit: 693c414
Not allowed on merged PR

Link to invocation

BrianLi23 pushed a commit to BrianLi23/TensorRT-LLM that referenced this pull request Jul 9, 2026
NVIDIA#16065)

Signed-off-by: nv-guomingz <137257613+nv-guomingz@users.noreply.github.com>
nv-guomingz pushed a commit that referenced this pull request Jul 14, 2026
…emantics (#16264)

Signed-off-by: Michal Guzek <mguzek@nvidia.com>
@nv-guomingz
nv-guomingz deleted the user/guomingz/fix_nvbug_6422332 branch July 21, 2026 08: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.

4 participants