Skip to content

Conversation

tomeras91
Copy link
Collaborator

@tomeras91 tomeras91 commented Aug 11, 2025

Summary by CodeRabbit

  • Refactor

    • Moved Mamba cache and hybrid cache functionality into a dedicated cache component; behavior and resource management remain consistent for users.
    • Internal imports updated to use the new component, preserving existing functionality.
  • Chores

    • Updated ownership entries to point to the new cache component.

Description

prior to this PR, nemotron-devs were code owners of resource_manager.py, because it contained MambaCacheManager and MambaHybridCacheManager which are unique and needed for mamba and hybrid attention mamba models (specifically, Nemotron-H architecture). This resulted in many false positives of for reviewing PRs which aren't really relevant for Nemotron models. This PR moves these classes to a separate file mamba_cache_manager.py, and replaces code ownership of resource_manager.py with this new file.

@tomeras91 tomeras91 requested review from a team as code owners August 11, 2025 12:50
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

📝 Walkthrough

Walkthrough

MambaCacheManager and MambaHybridCacheManager were moved from resource_manager.py into a new module mamba_cache_manager.py; imports were updated in _util.py and CODEOWNERS entries were updated to reference the new path. No runtime behavior changes beyond relocation.

Changes

Cohort / File(s) Summary
Mamba cache managers (new module)
tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
New module implementing MambaCacheManager and MambaHybridCacheManager with GPU cache allocation, block pooling, prepare/free resource APIs, state accessors, and shutdown.
Resource manager removals
tensorrt_llm/_torch/pyexecutor/resource_manager.py
Removed MambaCacheManager and MambaHybridCacheManager class definitions from this file; other resource-management code remains.
Import updates
tensorrt_llm/_torch/pyexecutor/_util.py
Import adjusted to pull MambaHybridCacheManager from the new mamba_cache_manager module; no logic changes.
Ownership metadata
.github/CODEOWNERS
Two CODEOWNERS entries updated to replace references to .../resource_manager.py with .../mamba_cache_manager.py, adjusting owner lists accordingly.

Sequence Diagram(s)

sequenceDiagram
  participant Scheduler as Scheduler/Caller
  participant Hybrid as MambaHybridCacheManager
  participant Mamba as MambaCacheManager
  participant KV as KVCacheManager

  Scheduler->>Hybrid: prepare_resources(scheduled_batch)
  Hybrid->>Mamba: prepare_resources(scheduled_batch)
  Hybrid->>KV: prepare_resources(scheduled_batch)
  Hybrid-->>Scheduler: done

  Scheduler->>Hybrid: free_resources(request)
  Hybrid->>Mamba: free_resources(request)
  Hybrid->>KV: free_resources(request)
  Hybrid-->>Scheduler: done

  Scheduler->>Hybrid: shutdown()
  Hybrid->>Mamba: shutdown()
  Hybrid->>KV: shutdown()
  Hybrid-->>Scheduler: done
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • chzblych
  • kevinch-nv
  • litaotju

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c52a0a and b06727b.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/_util.py (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/resource_manager.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/pyexecutor/resource_manager.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tensorrt_llm/_torch/pyexecutor/_util.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Pre-commit Check
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tomeras91 tomeras91 force-pushed the mamba-cache-separate-file branch from 25829fb to 91b7bba Compare August 11, 2025 12:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py (3)

28-44: Add class docstring for MambaCacheManager (guidelines prefer Google-style docstrings).

A brief summary of purpose and args improves maintainability and Sphinx rendering.

 class MambaCacheManager(BaseResourceManager):
+    """GPU-resident cache for Mamba conv and SSM states.
+
+    Args:
+        d_state: SSM state size.
+        d_conv: Convolution kernel length.
+        num_heads: Number of attention heads (pre-TP).
+        n_groups: Number of groups for state partitioning.
+        head_dim: Per-head dimension.
+        num_layers: Total transformer layers (pre-PP; will be sharded).
+        max_batch_size: Maximum batch size per rank.
+        mapping: Parallelism mapping.
+        dtype: Torch dtype for conv states.
+        ssm_cache_dtype: Torch dtype for SSM states.
+        layer_mask: Optional mask to select subset of layers locally.
+    """

167-199: Add class docstring for MambaHybridCacheManager.

Documenting the hybrid behavior clarifies dual-manager responsibilities.

 class MambaHybridCacheManager(KVCacheManager, MambaCacheManager):
+    """Hybrid cache manager combining Mamba conv/SSM states with KV cache.
+
+    Initializes both MambaCacheManager and KVCacheManager and delegates
+    prepare/free/shutdown to both.
+    """

77-88: Guard against invalid d_conv values (conv_states uses d_conv - 1).

If d_conv could be 1, this shape would be invalid. A defensive assert avoids silent mis-shapes.

         # mamba conv states
+        assert d_conv >= 2, "d_conv must be >= 2 since conv state uses d_conv - 1"
         self.conv_states = torch.empty(
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e33ed6 and 91b7bba.

📒 Files selected for processing (4)
  • .github/CODEOWNERS (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/_util.py (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py (1 hunks)
  • tensorrt_llm/_torch/pyexecutor/resource_manager.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/pyexecutor/resource_manager.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

**/*.py: Python code should conform to Python 3.8+.
Indent Python code with 4 spaces. Do not use tabs.
Always maintain the namespace when importing in Python, even if only one class or function from a module is used.
Python filenames should use snake_case (e.g., some_file.py).
Python classes should use PascalCase (e.g., class SomeClass).
Python functions and methods should use snake_case (e.g., def my_awesome_function():).
Python local variables should use snake_case. Prefix k for variable names that start with a number (e.g., k_99th_percentile).
Python global variables should use upper snake_case and prefix G (e.g., G_MY_GLOBAL).
Python constants should use upper snake_case (e.g., MY_CONSTANT).
Avoid shadowing variables declared in an outer scope in Python.
Initialize all externally visible members of a Python class in the constructor.
For interfaces that may be used outside a Python file, prefer docstrings over comments.
Comments in Python should be reserved for code within a function, or interfaces that are local to a file.
Use Google style docstrings for Python classes and functions, which can be parsed by Sphinx.
Attributes and variables in Python can be documented inline; attribute docstrings will be rendered under the class docstring.
Avoid using reflection in Python when functionality can be easily achieved without it.
When using try-except blocks in Python, limit the except to the smallest set of errors possible.
When using try-except blocks to handle multiple possible variable types in Python, keep the body of the try as small as possible, using the else block to implement the logic.

Files:

  • tensorrt_llm/_torch/pyexecutor/_util.py
  • tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
**/*.{cpp,h,hpp,cc,cxx,cu,py}

📄 CodeRabbit Inference Engine (CODING_GUIDELINES.md)

All TensorRT-LLM Open Source Software code should contain an NVIDIA copyright header that includes the current year. This includes .cpp, .h, .cu, .py, and any other source files which are compiled or interpreted.

Files:

  • tensorrt_llm/_torch/pyexecutor/_util.py
  • tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py
🧠 Learnings (1)
📚 Learning: 2025-08-06T13:58:07.506Z
Learnt from: galagam
PR: NVIDIA/TensorRT-LLM#6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.

Applied to files:

  • .github/CODEOWNERS
🪛 Ruff (0.12.2)
tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py

197-197: Undefined name DecodingBaseConfig

(F821)


201-201: Line too long (130 > 120)

(E501)

🔇 Additional comments (2)
.github/CODEOWNERS (1)

110-110: CODEOWNERS entry for mamba_cache_manager.py is correct and old entry removed

  • No occurrences of /tensorrt_llm/_torch/pyexecutor/resource_manager.py remain in .github/CODEOWNERS.
  • The new /tensorrt_llm/_torch/pyexecutor/mamba_cache_manager.py entry on line 110 correctly assigns ownership to the Nemotron teams.
tensorrt_llm/_torch/pyexecutor/_util.py (1)

28-33: Verification complete – no stale imports of MambaHybridCacheManager remain

All occurrences of MambaHybridCacheManager are either in its definition file or in _util.py with the updated import path. No other modules import it from resource_manager. Safe to merge.

…che_manager.py - it's redundant. They don't need to specifically own this file, and it is already included under tensorrt_llm/_torch/pyexecutor

Signed-off-by: Tomer Asida <[email protected]>
Signed-off-by: Tomer Asida <[email protected]>
@tomeras91
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14817 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14817 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #11189 completed with status: 'FAILURE'

@tomeras91
Copy link
Collaborator Author

/bot run

Copy link
Collaborator

@omera-nv omera-nv left a comment

Choose a reason for hiding this comment

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

LGTM!

@tomeras91
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14834 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14834 [ run ] completed with state SUCCESS
/LLM/main/L0_MergeRequest_PR pipeline #11204 completed with status: 'FAILURE'

@tomeras91
Copy link
Collaborator Author

/bot run

@tomeras91
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14986 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

PR_Github #14986 [ run ] completed with state FAILURE
/LLM/main/L0_MergeRequest_PR pipeline #11316 completed with status: 'FAILURE'

@tomeras91
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #15145 [ run ] triggered by Bot

@tomeras91
Copy link
Collaborator Author

/bot run

@tensorrt-cicd
Copy link
Collaborator

PR_Github #15304 [ run ] triggered by Bot

@tensorrt-cicd
Copy link
Collaborator

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

Copy link
Collaborator

@DomBrown DomBrown left a comment

Choose a reason for hiding this comment

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

LGTM

@tomeras91 tomeras91 requested a review from omera-nv August 15, 2025 10:31
@tomeras91 tomeras91 merged commit f7dbc14 into NVIDIA:main Aug 15, 2025
5 checks passed
@tomeras91 tomeras91 deleted the mamba-cache-separate-file branch August 15, 2025 13:16
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 17, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 17, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 17, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 17, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 18, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 18, 2025
dominicshanshan pushed a commit to dominicshanshan/TensorRT-LLM that referenced this pull request Aug 18, 2025
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.

5 participants