Skip to content

[https://nvbugs/6210714][fix] Fix mamba block calculation - #14524

Merged
VALLIS-NERIA merged 8 commits into
NVIDIA:mainfrom
VALLIS-NERIA:user/xiweny/6210714
Jun 5, 2026
Merged

[https://nvbugs/6210714][fix] Fix mamba block calculation#14524
VALLIS-NERIA merged 8 commits into
NVIDIA:mainfrom
VALLIS-NERIA:user/xiweny/6210714

Conversation

@VALLIS-NERIA

@VALLIS-NERIA VALLIS-NERIA commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes mamba/attention hybrid pool sizing under nvbug 6210714.

Three related fixes:

  1. resource_manager.py budget formula — Remove the heuristic that
    ignored the intercept term whenever mamba_slope > 0 (i.e. whenever
    block reuse + snapshots were enabled). The intercept captures the
    fixed per-rank live-state memory max_batch_size * pp_size * state_bytes_local and is not negligible under PP or large
    max_batch_size; dropping it produced budgets larger than what the
    pool could actually hold, leading to OOM / undersized allocations.
    Now always subtract intercept from the primary budget, and warn
    when a user-specified max_tokens cannot fit the resulting budget.

  2. resource_manager.py dry-run snapshot count — Change the
    estimation-dry-run path so that max_snapshots = live_state_slots + reuse_snapshots instead of max(reuse_snapshots, live_state_slots).
    This mirrors the non-dry-run path (live slots and reuse snapshots
    are additive), so dry-run estimates no longer undershoot the slot
    count actually needed.

  3. Hybrid cache config validation — Add
    validate_hybrid_cache_config to mamba_cache_manager.py and call
    it from CppMambaHybridCacheManager.__init__. When block reuse is
    enabled, it asserts mamba_state_cache_interval > 0 and that it is
    a multiple of tokens_per_block (required for proper block
    alignment). Also relaxes the KvCacheConfig.mamba_state_cache_interval
    field type from PositiveInt (default 256) to Optional[int]
    (default None) so the validator can distinguish "unset" from "set
    to a specific value".

Test plan

  • Mamba-hybrid model (e.g. Nemotron-H / Qwen3-Next) boots with PP > 1
    and block reuse enabled
  • User-specified max_tokens larger than the computed budget
    triggers the new warning rather than silently over-allocating
  • Setting enable_block_reuse=True with an invalid
    mamba_state_cache_interval raises the new assertion
  • Existing unit tests under tests/unittest/ for mamba / hybrid
    cache still pass

Summary by CodeRabbit

  • Bug Fixes

    • Improved cache configuration validation for Mamba models to catch invalid settings during initialization.
    • Added warning when calculated cache capacity is lower than user-specified limits.
  • Changes

    • Cache memory calculation now uses additive sizing for optimal resource utilization.
    • Configuration field for cache state intervals is now optional with automatic handling.

Review Change Stack

Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA
VALLIS-NERIA requested review from a team as code owners May 25, 2026 08:55
@VALLIS-NERIA VALLIS-NERIA changed the title [https://nvbugs/6210714][fix] Fix mamba block calculation (By Agent) [https://nvbugs/6210714][fix] Fix mamba block calculation May 25, 2026
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Configuration schema change makes mamba_state_cache_interval optional (default None). Hybrid cache manager now validates the interval is positive and block-aligned at init time. Linear attention resource sizing switches from max-based to additive snapshot slots and consistently applies memory budget intercept in max_tokens calculation with user-config warnings.

Changes

Mamba cache validation and sizing

Layer / File(s) Summary
Mamba state cache interval config schema update
tensorrt_llm/llmapi/llm_args.py
KvCacheConfig.mamba_state_cache_interval is now optional (default None) instead of a required positive integer with default 256, shifting validation responsibility to callers.
Hybrid cache configuration validation
tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
New validate_hybrid_cache_config() function asserts that mamba_state_cache_interval is positive and divisible by tokens_per_block when block reuse is enabled; invoked early in CppMambaHybridCacheManager.__init__ for fail-fast validation.
Linear attention recurrent state sizing updates
tensorrt_llm/_torch/pyexecutor/resource_manager.py
max_snapshots for recurrent states changed from max-of-live-vs-snapshot heuristic to additive (live state slots plus snapshot-token-derived count); max_tokens calculation now consistently subtracts intercept from memory budget; warning added when computed max_tokens is below user-specified value.

Sequence Diagram

sequenceDiagram
    participant User as User Config
    participant Schema as KvCacheConfig
    participant Validator as validate_hybrid_cache_config
    participant Manager as CppMambaHybridCacheManager
    participant Estimator as _calculate_max_num_blocks_for_linear_attention

    User->>Schema: mamba_state_cache_interval (optional)
    Schema-->>Manager: pass config
    Manager->>Validator: validate_hybrid_cache_config(config, tokens_per_block)
    Validator-->>Manager: assert interval > 0 and aligned
    Manager-->>Manager: initialize successfully
    Manager->>Estimator: estimate resource requirements
    Estimator->>Estimator: max_snapshots = live_state_slots + snapshot_count
    Estimator->>Estimator: max_tokens = max((budget - intercept) // slope, 0)
    Estimator-->>Manager: resource estimates
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • NVIDIA/TensorRT-LLM#14003: Modifies resource_manager.py's linear-attention recurrent-state sizing logic for max_snapshots computation in _calculate_max_num_blocks_for_linear_attention.

Suggested reviewers

  • tomeras91
  • syuoni
  • bo-nv
  • nv-guomingz
  • SimengLiu-nv
  • yuxianq
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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 Title correctly identifies the primary fix (mamba block calculation) and references the NVBugs ID, though it could be more descriptive of the scope of changes.
Description check ✅ Passed Description comprehensively explains all three related fixes with technical details, test coverage, and checklist items completed appropriately.
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.

Actionable comments posted: 1

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

Inline comments:
In `@tensorrt_llm/_torch/pyexecutor/resource_manager.py`:
- Around line 688-690: The estimation path and the runtime allocation both
compute snapshot slot counts differently (variables like max_snapshots,
kv_cache_config.max_tokens, linear_attention_metadata.states_snapshot_interval
and the affine token-budget model used at the other site), causing mismatched
pool sizing and possible under-allocation; refactor by extracting a single
helper (e.g., compute_snapshot_slots or derive_snapshot_slot_count) that
implements the affine formula (intercept + slope * T) and any consistent
+1/draft-slot policy, then replace the ad-hoc additive calculation that updates
max_snapshots and the separate max(...) logic in the runtime allocation with
calls to this helper so both dry-run estimate and actual pool shape are derived
from the same formula.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a9e214f7-5c18-4f3a-a3a3-ddaacc54feaa

📥 Commits

Reviewing files that changed from the base of the PR and between 998f418 and d6ed3ac.

📒 Files selected for processing (3)
  • tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
  • tensorrt_llm/_torch/pyexecutor/resource_manager.py
  • tensorrt_llm/llmapi/llm_args.py

Comment thread tensorrt_llm/_torch/pyexecutor/resource_manager.py
…x (By Agent)

Covers the three pieces of the fix:

- validate_hybrid_cache_config: pure-Python guard. New parametric tests
  exercise the no-op path (reuse disabled), the happy path (positive,
  multiple of tokens_per_block), and the four reject branches (unset,
  zero, negative, non-multiple).
- Dry-run recurrent-state pool sizing under block reuse: new test
  test_cpp_hybrid_dry_run_recurrent_pool_additive_with_block_reuse
  asserts the additive live + reuse formula (was previously a max()).
- Existing test_cpp_hybrid_recurrent_pool_floor_with_block_reuse now
  passes mamba_state_cache_interval=256 explicitly, since the default
  changed from 256 to None.

_build_hybrid_with_mamba_layer gains mamba_state_cache_interval and
is_estimating_kv_cache parameters and forwards is_estimating_kv_cache to
the manager so the dry-run path is reachable from tests.

Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50204 [ run ] triggered by Bot. Commit: ff050a2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50250 [ run ] triggered by Bot. Commit: ff050a2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50312 [ run ] triggered by Bot. Commit: ff050a2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50312 [ run ] completed with state FAILURE. Commit: ff050a2
/LLM/main/L0_MergeRequest_PR pipeline #39842 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

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50421 [ run ] triggered by Bot. Commit: ff050a2 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50421 [ run ] completed with state SUCCESS. Commit: ff050a2
/LLM/main/L0_MergeRequest_PR pipeline #39945 completed with status: 'SUCCESS'

CI Report

Link to invocation

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --help

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot help

@github-actions

Copy link
Copy Markdown

GitHub Bot Help

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental) --high-priority]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Supports wildcard * for pattern matching (e.g., "*PerfSanity*" matches all stages containing PerfSanity). Examples: "A10-PyTorch-1, xxx", "PerfSanity". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Supports wildcard * for pattern matching. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx", --extra-stage "Post-Merge".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

--high-priority (OPTIONAL) : Run the pipeline with high priority. This option is restricted to authorized users only and will route the job to a high-priority queue.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #50802 Bot args parsing error: usage: /bot [-h]
{run,kill,skip,submit,reviewers,reuse-pipeline,reuse-review} ...
/bot: error: unrecognized arguments: --help

Link to invocation

Signed-off-by: xiweny <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52013 [ run ] triggered by Bot. Commit: fb56b5a Link to invocation

Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
…eny/6210714

Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52033 [ run ] triggered by Bot. Commit: a6226f5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52013 [ run ] completed with state ABORTED. Commit: fb56b5a

Link to invocation

Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52036 [ run ] triggered by Bot. Commit: a14c8e5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52033 [ run ] completed with state ABORTED. Commit: a6226f5

Link to invocation

@VALLIS-NERIA
VALLIS-NERIA enabled auto-merge (squash) June 4, 2026 11:22
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Link to invocation

venkywonka added a commit to venkywonka/TensorRT-LLM that referenced this pull request Jun 4, 2026
…gle-GPU

test_single_request_chat_multiple_images[pd_disagg-qwen3_30b_a3b_fp8] in test_mm_encoder_standalone.py fails at setup on the pre-merge DGX_B200 single-GPU stage with a NIXL CacheTransceiver init assertion (status == NIXL_SUCCESS, transferAgent.cpp:614) when the pd_disagg LLM constructs its disaggregated KV-cache transfer agent.

This is a fleet-wide failure on the single-GPU pre-merge stage, observed across many unrelated PRs (e.g. NVIDIA#13978, NVIDIA#13925, NVIDIA#14841, NVIDIA#14599, NVIDIA#14524, NVIDIA#14941, NVIDIA#14398); it passes only intermittently (~1/3) depending on node. Waiving until the single-GPU NIXL EPD-disagg path is fixed or the variant is gated to multi-GPU.

NVBug: https://nvbugs/6269683
Signed-off-by: venkywonka <23023424+venkywonka@users.noreply.github.com>
@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52227 [ run ] triggered by Bot. Commit: a14c8e5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@VALLIS-NERIA

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52287 [ run ] triggered by Bot. Commit: a14c8e5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52287 [ run ] completed with state SUCCESS. Commit: a14c8e5
/LLM/main/L0_MergeRequest_PR pipeline #41596 completed with status: 'SUCCESS'

CI Report

Link to invocation

@VALLIS-NERIA
VALLIS-NERIA merged commit d5de55e into NVIDIA:main Jun 5, 2026
8 checks passed
fbxai pushed a commit to fbxai/TensorRT-LLM that referenced this pull request Jun 5, 2026
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: xiweny <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: NVFB <186336021+NVFB@users.noreply.github.com>
2ez4bz pushed a commit to 2ez4bz/TensorRT-LLM that referenced this pull request Jun 8, 2026
Signed-off-by: Xiwen Yu <13230610+VALLIS-NERIA@users.noreply.github.com>
Signed-off-by: xiweny <13230610+VALLIS-NERIA@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