Skip to content

[None][fix] Use HND mapping for MiniMax-M3 MSA KV cache - #17374

Open
peihu-nv wants to merge 1 commit into
NVIDIA:mainfrom
peihu-nv:codex/port-pr17011-main-20260806
Open

[None][fix] Use HND mapping for MiniMax-M3 MSA KV cache#17374
peihu-nv wants to merge 1 commit into
NVIDIA:mainfrom
peihu-nv:codex/port-pr17011-main-20260806

Conversation

@peihu-nv

@peihu-nv peihu-nv commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • MiniMax-M3 MSA now uses HND cache views and the INDEXED mapper.
  • Triton continues to use NHD and the existing mapper behavior.
  • Index-K remains REPLICATED.
  • Optional layout arguments now default to the selected backend layout.
  • NVFP4 scale-pool handling remains restricted to Triton/NHD.
  • Python compilation and changed-file pre-commit checks passed.
  • CUDA transfer validation requires GPU CI and runtime bindings.
  • No configuration or test-list files changed.

QA Engineer Review

Test functions added or modified:

  • test_minimax_msa_hnd_head_mismatch_transfer
  • test_minimax_disagg_role_mapper_kinds
  • Updated layout-aware MiniMax-M3 KV-transfer coverage

These tests are not covered by tests/integration/test_lists/test-db/ or qa/ entries in this change.

Verdict: needs follow-up. GPU CI coverage is required to validate the TP1 context-to-TP4 generation transfer path.

Description

MiniMax-M3 MSA stores its main paged K/V cache in HND layout, but disaggregated KV transfer declared the cache as NHD. This causes head-mismatched context and generation parallelism to use the wrong transfer mapping.

Select the INDEXED mapper and HND cache views for MSA while preserving the existing NHD behavior for the Triton backend. Add focused TP1-to-TP4 transfer coverage for the MSA path. MiniMax-M3 MSA uses FP8 rather than NVFP4 KV cache, so NVFP4 scale-pool handling remains explicitly scoped to the Triton/NHD path.

Test Coverage

  • Added MSA HND FP8 KV-transfer coverage for TP1 context to TP4 generation, with request metadata updated both before and after transfer.
  • Added mapper-selection coverage for Triton/NHD and MSA/INDEXED.
  • Homebrew Python 3.12 syntax compilation passed for all changed Python files.
  • Changed-file pre-commit checks passed, including Ruff, Ruff format, codespell, and repository validation hooks.
  • CUDA transfer test not run locally; requires GPU CI and TensorRT-LLM runtime bindings.

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.

Signed-off-by: peihengh <259410613+peihu-nv@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

MiniMax M3 cache management now selects NHD or HND layouts from the attention implementation. Mapper kinds, buffer access, KV-transfer test setup, and verification now follow the selected layout.

Changes

MiniMax M3 KV layout handling

Layer / File(s) Summary
Backend layout and mapper selection
tensorrt_llm/_torch/attention_backend/sparse/minimax_m3/cache_manager.py, tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py
The manager selects HND for MSA and NHD otherwise. Mapper kinds and optional buffer-layout arguments follow that selection.
Layout-aware test setup and verification
tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py
Test managers, cache data, NVFP4 scales, and KV comparisons now support HND and NHD layouts.
Backend-specific transfer coverage
tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py, tests/unittest/disaggregated/test_pool_matching.py
Tests cover Triton/NHD and MSA/INDEXED mappings, FP8 MSA/HND transfers, and the MiniMax M3 Triton shape description.

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

Sequence Diagram(s)

sequenceDiagram
  participant ContextManager
  participant GenerationManager
  participant KVTransferTest
  ContextManager->>GenerationManager: transfer layout-specific KV buffers
  GenerationManager->>KVTransferTest: expose transferred buffers
  KVTransferTest->>KVTransferTest: compare HND or NHD slices
Loading

Possibly related PRs

Suggested reviewers: schetlur-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the issue, solution, test coverage, limitations, and checklist status; it is sufficiently complete for review.
Title check ✅ Passed The title follows the required format and clearly identifies the HND mapping fix for the MiniMax-M3 MSA KV cache.
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

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.

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 `@tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py`:
- Around line 101-109: Add type annotations to all newly changed functions:
annotate the parametrized arguments of test_minimax_disagg_role_mapper_kinds and
the parameters of its nested fake_base_init, then annotate
update_before_transfer as bool in
tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py at lines 101-109 and
660 respectively.
🪄 Autofix

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: f3f6b46b-52f1-4280-9113-7c8a73bd351d

📥 Commits

Reviewing files that changed from the base of the PR and between f12c5e5 and a435608.

📒 Files selected for processing (4)
  • tensorrt_llm/_torch/attention_backend/sparse/minimax_m3/cache_manager.py
  • tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py
  • tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py
  • tests/unittest/disaggregated/test_pool_matching.py

Comment on lines +101 to +109
def test_minimax_disagg_role_mapper_kinds(
monkeypatch, implementation, expected_main_mapper
) -> None:
def fake_base_init(self, *args, **kwargs):
self.is_disagg = kwargs.get("is_disagg", False)
self.dtype = kwargs.get("dtype", DataType.BF16)
self.layer_offsets = {}
self.max_batch_size = 1
self.max_seq_len = 1

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add required annotations to new test functions.

Both changed test functions add unannotated parameters. fake_base_init is also new without annotations.

  • tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py#L101-L109: Annotate the parametrized test arguments and fake_base_init.
  • tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py#L660-L660: Annotate update_before_transfer as bool.

As per coding guidelines, annotate every function.

📍 Affects 1 file
  • tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py#L101-L109 (this comment)
  • tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py#L660-L660
🤖 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/unittest/disaggregated/test_minimax_m3_kv_transfer.py` around lines 101
- 109, Add type annotations to all newly changed functions: annotate the
parametrized arguments of test_minimax_disagg_role_mapper_kinds and the
parameters of its nested fake_base_init, then annotate update_before_transfer as
bool in tests/unittest/disaggregated/test_minimax_m3_kv_transfer.py at lines
101-109 and 660 respectively.

Source: Coding guidelines

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.

2 participants