Skip to content

[TRTLLM-14855][chore] Use the canonical modules instead of the layout compatibility shims - #22086

Open
YihuiLu512 wants to merge 1 commit into
NVIDIA:mainfrom
YihuiLu512:feat-dev-J14855
Open

YihuiLu512 wants to merge 1 commit into
NVIDIA:mainfrom
YihuiLu512:feat-dev-J14855

Conversation

@YihuiLu512

@YihuiLu512 YihuiLu512 commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The code-layout Epic (TRTLLM-14558) left compatibility forwarding modules (shims) at retired import paths, so that callers outside the repository keep working during the deprecation window. Code inside the repository is expected to use the canonical paths. This PR updates the following imports and code comments that name a shim path:

File Old reference New reference
tensorrt_llm/_torch/pyexecutor/kv_cache/mamba_cache_manager/mamba_cache_manager_v2.py tensorrt_llm._torch.attention_backend.interface (under TYPE_CHECKING) tensorrt_llm._torch.attention.backends.interface
tests/unittest/_torch/ray_orchestrator/multi_gpu/test_mnnvl_allreduce.py tensorrt_llm.ray_stub, tensorrt_llm.executor.ray_gpu_worker tensorrt_llm.executor.ray.stub, tensorrt_llm.executor.ray.gpu_worker
tests/unittest/_torch/ray_orchestrator/multi_gpu/test_refit_compile_isolation.py tensorrt_llm._ray_utils tensorrt_llm.executor.ray.utils
tensorrt_llm/_torch/speculative/dflash.py (docstring) attention_backend/utils.py the function name, append_mla_latent_cache_generation_cuda_graph_safe
cpp/tensorrt_llm/thop/moe/communication/moeAlltoAllOp.cpp (comment) executor/ray_executor.py tensorrt_llm/executor/ray/executor.py
tensorrt_llm/_torch/attention/backends/fp4_mla/cache_update.py (docstring) a sentence naming MLA.forward_impl in tensorrt_llm/_torch/modules/attention.py removed; the caller contract above it stays

The mamba_cache_manager_v2.py import never resolved, because the attention_backend shim is a package with only an __init__.py and has no interface submodule. The import sits under TYPE_CHECKING, so only static type checkers ever evaluated it.

A follow-up PR under the same ticket will delete the shims, together with their tests, their CODEOWNERS entries and the legacy keys in the restricted-unpickle allowlist.

There is no runtime behaviour change. The shims stay in place, and each changed import names the canonical module that defines what it imports.

Test Coverage

  • Local, on a CPU node without Ray: pytest --collect-only on the two changed test files. Collection runs their module-level imports (tensorrt_llm.executor.ray.utils, and the tensorrt_llm.executor.ray.stub fallback when Ray is absent).
  • The RayWorkerWrapper import in test_mnnvl_allreduce.py runs inside a Ray actor. It runs whenever that test creates its workers, which happens in its existing pre-merge GPU entries: l0_dgx_b200 lists the file, and l0_dgx_h100 selects it with -m "gpu2".
  • The TYPE_CHECKING import is checked statically: locally, pyrefly reports it as a missing import before this change and reports no error after it.

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.

Dev Engineer Review

  • Six files changed: 8 additions and 9 deletions.
  • Imports and documentation references now use canonical TensorRT-LLM module paths.
  • No production logic, public API, defaults, or test definitions changed.
  • Import resolution is the main verification point.

QA Engineer Review

  • Two existing test files were modified. No test files or test-list files were added or removed.
  • Existing test functions and waivers remain unchanged. The affected tests are test_mnnvl_allreduce_over_process_group, test_refit_isolation_engine, test_refit_isolation_decode, and test_refit_isolation_report.
  • The MNNVL test is listed in tests/integration/test_lists/test-db/l0_dgx_b200.yml.
  • No matching CI or manual-QA entry exists for the refit isolation test.
  • Current-head test results are not available. Coverage verdict: needs follow-up.

Per-File QA Perspective

  • cpp/tensorrt_llm/thop/moe/communication/moeAlltoAllOp.cpp: Comment-only path correction. No observable behavior changes.
  • tensorrt_llm/_torch/attention/backends/fp4_mla/cache_update.py: Docstring-only change. The pre-sliced cache contract remains unchanged.
  • tensorrt_llm/_torch/pyexecutor/kv_cache/mamba_cache_manager/mamba_cache_manager_v2.py: The TYPE_CHECKING import now uses the canonical path. Static type checking should resolve AttentionMetadata.
  • tensorrt_llm/_torch/speculative/dflash.py: Documentation-only path correction. No observable behavior changes.
  • tests/unittest/_torch/ray_orchestrator/multi_gpu/test_mnnvl_allreduce.py: Covers Ray-orchestrated MNNVL all-reduce with fusion and no-fusion cases. The canonical Ray imports must resolve during collection and worker execution. The test is listed in the DGX B200 CI database.
  • tests/unittest/_torch/ray_orchestrator/multi_gpu/test_refit_compile_isolation.py: Covers engine refit isolation, decode behavior, and reporting. The canonical decorator import must resolve during collection. No matching CI or manual-QA test-list entry exists.

@YihuiLu512

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 272cc2b and 65b9635.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

This change updates module references in comments and imports. It also removes implementation detail from a cache docstring while retaining its pre-slicing contract.

Changes

Path and documentation updates

Layer / File(s) Summary
Update Ray references
cpp/tensorrt_llm/thop/moe/communication/moeAlltoAllOp.cpp, tests/unittest/_torch/ray_orchestrator/multi_gpu/*
The Ray executor comment and test imports now use updated module paths.
Update attention references
tensorrt_llm/_torch/pyexecutor/kv_cache/mamba_cache_manager/mamba_cache_manager_v2.py, tensorrt_llm/_torch/speculative/dflash.py, tensorrt_llm/_torch/attention/backends/fp4_mla/cache_update.py
The type-checking import and documentation use updated attention references. The cache docstring no longer describes how MLA.forward_impl slices latent_cache; its pre-slicing contract remains.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Merge Risk: Minimal · previous review 272cc

This is a mechanical path-reference update with no runtime behavior change, and all new targets resolve. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the ticket, change type, and primary change: replacing layout compatibility shim references with canonical modules.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Description check Passed The description follows the required structure. It clearly explains the compatibility-shim cleanup, lists affected files and references, documents test coverage, and includes the PR checklist. The rep…
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 6 files.

Full details: Description check

Explanation

The description follows the required structure. It clearly explains the compatibility-shim cleanup, lists affected files and references, documents test coverage, and includes the PR checklist. The reported validation and no-runtime-change scope are sufficiently detailed.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b4cede8 and 272cc2b.

Files selected for processing: 1

  • tensorrt_llm/_torch/speculative/dflash.py
Files skipped from review as they are similar to previous changes: 1

  • tensorrt_llm/_torch/speculative/dflash.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@yuxianq

yuxianq commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

@farazkh80, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~

Assignment explanation
Componentsruntime/recurrent-state (50%); runtime/kv-cache/layout-io (30%); unmapped (20%)
TagsNone identified
PR effort1 points — Tiny mechanical attention review: check the canonical metadata import and confirm that removing the stale caller example preserves the documented cache contract.
Affinity (0–1)0.500 component/tag match
Outstanding points at selection48 → 49 (+1)
Points already reserved on this PR0
Effective weight1
Completed review points (preceding 168 hours)13
Combined points after assignment62
Demand-derived target61.00 points (soft share)
Additional fair share before assignment0.00 points
Share explanationWhole PR / qualification or coverage constraint exceeds a soft share; assignment is allowed.
Selection rulebalance-first maintenance
Assignment scope (farazkh80)all

Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once.

@yuxianq
yuxianq requested review from farazkh80 and removed request for lfr-0531 and pengbowang-nv November 11, 2026 06:55
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84053 [ run ] triggered by Bot. Commit: efd7f5d Link to invocation

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

No blockers, possibly-blocking or required items; 3 nice-to-haves (2 inline, 1 below). Each changed import now names the module that defines the object the shim forwarded: RayWorkerWrapper.physical_to_local_id, control_action_decorator, AttentionMetadata, and the Ray stub's remote/__getattr__. tensorrt_llm/executor/ray/__init__.py re-exports nothing, so the Ray-less stub fallback still imports without Ray. The two corrected comments match the code: tensorrt_llm/executor/ray/executor.py:161-164 sets TLLM_DISABLE_MPI=1 for the workers, and attention/backends/utils.py:233-234 holds the V1 divisor. No other .py file imports a shim outside the shims' own tests. CI (PR_Github #84053) is still running. The in-actor RayWorkerWrapper import only runs on the DGX multi-GPU stages your Test Coverage section cites, and those stages also need the ci: full pre-merge approved label.

  • [Nice to have] The sweep misses the perf cookbooks under .claude/skills/: 14 lines in 9 files still name the pre-move paths. The one that will break is perf-regression-cookbook/references/cuda-graph-and-compile/piecewise-attention-torch-compile-host-overhead.md:56: its detection command runs import tensorrt_llm._torch.modules.attention. It already prints (False, False), because maybe_compiled_cat now lives in tensorrt_llm/_torch/utils.py, and it will raise ModuleNotFoundError once the follow-up deletes that shim. The other lines grep tensorrt_llm/_torch/attention_backend/sparse/dsa.py, .../attention_backend/fmha/flashinfer_trtllm_gen.py or '*/attention_backend/*', which no longer exist or match only the shim's __init__.py. Please point them at tensorrt_llm/_torch/attention/backends/sparse/dsa/, tensorrt_llm/_torch/attention/backends/fmha/flashinfer_trtllm_gen.py, tensorrt_llm/_torch/attention/mla.py and tensorrt_llm._torch.utils. Do it here, or add them to the follow-up's list in the description. To find them: git grep -n -E "attention_backend/|modules/attention\.py|_torch\.modules\.attention" -- .claude/skills.

consume. ``MLA.forward_impl`` (tensorrt_llm/_torch/modules/attention.py)
slices ``latent_cache[:num_ctx_tokens]`` for context and
``latent_cache[num_ctx_tokens:]`` for generation before dispatching.
consume.

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.

[Nice to have] Only the path in the removed sentence was stale. MLA now lives in tensorrt_llm/_torch/attention/mla.py, and MLA.forward_impl still slices latent_cache[:num_ctx_tokens, ...] for context (mla.py:1117) and latent_cache[num_ctx_tokens:, ...] for generation (mla.py:1148) before dispatching. That pre-slicing is what the contract above requires of callers, so I'd keep the pointer and fix only the path:

Suggested change
consume.
consume. ``MLA.forward_impl`` (tensorrt_llm/_torch/attention/mla.py)
slices ``latent_cache[:num_ctx_tokens]`` for context and
``latent_cache[num_ctx_tokens:]`` for generation before dispatching.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks — the path was indeed the only stale part. I dropped the sentence rather than re-pointing it, for two reasons:

  1. The slicing lives in the private MLA._forward_impl (mla.py:1117/1148), not forward_impl, which skips it on the sparse-hooks path; with external RoPE the context latent is rebuilt via torch.cat, and latent_cache_gen can be supplied by the caller.
  2. The direct callers of this helper are the backends (e.g. fmha/fp4_mla.py slices latent_cache[:num_tokens] itself), so the caller contract above already states the requirement without a cross-file pointer that can drift again.

num_pool_layers * kv_factor`` plus the K/V field index. What that has to
be divided by to index a ``get_buffers`` view depends on the manager --
see the stride check below; attention_backend/utils.py hardcodes the V1
see the stride check below; attention/backends/utils.py hardcodes the V1

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.

[Nice to have] Consider naming the function instead of the file, so the reference greps and survives the next move. The V1 divisor is hardcoded in append_mla_latent_cache_generation_cuda_graph_safe (tensorrt_llm/_torch/attention/backends/utils.py:139); the // (num_pool_layers * kv_factor) decode is at :233-234.

Suggested change
see the stride check below; attention/backends/utils.py hardcodes the V1
see the stride check below;
``append_mla_latent_cache_generation_cuda_graph_safe`` hardcodes the V1

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 272cc2b, thanks.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84053 [ run ] completed with state SUCCESS. Commit: efd7f5d
/LLM/main/L0_MergeRequest_PR pipeline #69520 completed with status: 'ABORTED'

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

@YihuiLu512

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84116 [ run ] triggered by Bot. Commit: eb742b5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84116 [ run ] completed with state DISABLED
The CI pipeline is currently frozen to deploy an urgent hotfix. For time-sensitive requests, please contact trt-llm-infra-devs.

Link to invocation

@hanjingtian

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84135 [ run ] triggered by Bot. Commit: b4cede8 Link to invocation

@YihuiLu512

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84154 [ run ] triggered by Bot. Commit: 272cc2b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84135 [ run ] completed with state ABORTED. Commit: b4cede8

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84154 [ run ] completed with state SUCCESS. Commit: 272cc2b
/LLM/main/L0_MergeRequest_PR pipeline #69576 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

… compatibility shims

Update the following imports and code comments that name a layout
compatibility shim:

- mamba_cache_manager_v2.py: the TYPE_CHECKING import of AttentionMetadata
  now names tensorrt_llm._torch.attention.backends.interface. The old
  tensorrt_llm._torch.attention_backend.interface never resolved: that
  shim is a package with only an __init__.py.
- test_mnnvl_allreduce.py and test_refit_compile_isolation.py import the
  Ray helpers from tensorrt_llm.executor.ray.{stub,gpu_worker,utils}.
- dflash.py: the docstring names
  append_mla_latent_cache_generation_cuda_graph_safe, the function that
  hardcodes the V1 divisor, instead of its file.
- moeAlltoAllOp.cpp: the comment names tensorrt_llm/executor/ray/executor.py
  as the place that sets TLLM_DISABLE_MPI for Ray workers.
- cache_update.py: drop the docstring sentence that named a shim module as
  the code slicing latent_cache; the caller contract before it stays.

Signed-off-by: Yihui Lu <269394165+YihuiLu512@users.noreply.github.com>
@YihuiLu512

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #84307 [ run ] triggered by Bot. Commit: 65b9635 Link to invocation

This branch has not been deployed

No deployments
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.

7 participants