Skip to content

[None][fix] Update stale attention and KV-cache import paths that break main - #18771

Merged
juney-nvidia merged 1 commit into
NVIDIA:mainfrom
brnguyen2:fix/fmha-kv-cache-manager-v2-import-path
Sep 6, 2026
Merged

[None][fix] Update stale attention and KV-cache import paths that break main#18771
juney-nvidia merged 1 commit into
NVIDIA:mainfrom
brnguyen2:fix/fmha-kv-cache-manager-v2-import-path

Conversation

@brnguyen2

@brnguyen2 brnguyen2 commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Description

Two module moves landed while dependent PRs were in flight, and current main
cannot import the PyTorch runtime.

1. KV-cache manager V2 moved; the FMHA libraries still use the old path.
#17899 moved tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py into the
new pyexecutor/kv_cache/ subpackage and updated the importers that existed at
the time. #17399, which added the phased and PrimTS FMHA libraries, was in
flight in parallel and still refers to the pre-move path:

$ python -c "import tensorrt_llm._torch.attention.backends"
ModuleNotFoundError: No module named 'tensorrt_llm._torch.pyexecutor.kv_cache_manager_v2'

fmha/__init__.py imports phased and prims_ts, and
attention/backends/__init__.py reaches the fmha package through trtllm.py,
so importing any attention backend executes the broken import and every unit
test under tests/unittest/_torch/attention/ fails collection.

2. The attention backend package moved; the new LoRA engine module still uses
the old path.
#17968 moved tensorrt_llm/_torch/attention_backend/ to
tensorrt_llm/_torch/attention/backends/. #18652 extracted
pyexecutor/engine/lora.py with the old path, and model_engine.py imports
engine.lora, so the executor stays unimportable even with (1) fixed:

tensorrt_llm/_torch/pyexecutor/engine/lora.py:8: in <module>
    from tensorrt_llm._torch.attention_backend.interface import AttentionMetadata
ModuleNotFoundError: No module named 'tensorrt_llm._torch.attention_backend'

This PR repoints every stale reference in the tree at the current paths:

  • attention/backends/fmha/{phased,prims_ts,utils}.py and
    tests/unittest/_torch/attention/{test_combined_fmha,test_fmha_page_index,test_prims_ts_fmha}.py
    to tensorrt_llm._torch.pyexecutor.kv_cache.kv_cache_manager_v2
  • pyexecutor/engine/lora.py, visual_gen/attention_backend/flashinfer.py and
    tests/unittest/_torch/visual_gen/test_attention_flashinfer.py
    to tensorrt_llm._torch.attention.backends.interface

The fully qualified KV-cache path is used rather than a shorter re-export because
pyexecutor/kv_cache/__init__.py is intentionally empty; this matches the
sibling backends (attention/backends/interface.py,
attention/backends/sparse/dsa/cache_manager.py).

This is an import-path change only. No logic, signatures or behavior are
touched.

Test Coverage

New CPU-only guard, tests/unittest/_torch/attention/test_backends_importable.py:
imports tensorrt_llm._torch.attention.backends, each of the three fmha
modules and pyexecutor.engine.lora, and asserts the moved names resolve at
their source modules. On the parent commit it fails at collection with the
errors above; the intent is that the next time one of these modules moves, the
unit tests catch it instead of whole suites going uncollected.

Verified on a built checkout at the parent commit plus this change:
test_backends_importable.py passes; import tensorrt_llm._torch.attention.backends
succeeds; the three previously uncollectable FMHA unit tests collect and pass
(test_combined_fmha.py 152, test_fmha_page_index.py 33,
test_prims_ts_fmha.py 78); tests/unittest/_torch/attention/test_flashinfer_attention.py
passes on one GPU; tests/unittest/_torch/visual_gen/test_attention_flashinfer.py
collects and passes on one GPU (15 passed, 4 skipped); from tensorrt_llm import LLM
and the model engine import succeed.

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

  • Updated stale imports for KVCacheManagerV2, Role, AttentionMetadata, and PredefinedAttentionMask.
  • Added CPU-only importability checks for attention backends, FMHA modules, LoRA, and KV-cache symbols.
  • Changes are consistent with the relocated module paths.
  • No runtime logic, API signatures, performance behavior, or configuration files changed.
  • No test-list files changed.

QA Engineer Review

  • Added:
    • test_attention_backends_package_imports
    • test_fmha_module_imports
    • test_engine_lora_imports
    • test_kv_cache_manager_v2_names_resolve
  • Updated imports in affected FMHA and FlashInfer tests.
  • The modified tests are not listed in tests/integration/test_lists/, test-db/, or qa/.
  • Reported validation includes test collection and execution for affected CPU tests, plus GPU FlashInfer test coverage.
  • Verdict: needs follow-up to confirm CI test-list coverage for the new importability tests.

@brnguyen2
brnguyen2 force-pushed the fix/fmha-kv-cache-manager-v2-import-path branch 2 times, most recently from 7202d1e to 949f0ff Compare September 6, 2026 16:32
@brnguyen2 brnguyen2 changed the title [None][fix] Update stale kv_cache_manager_v2 import paths in the fmha backends [None][fix] Update stale attention and KV-cache import paths that break main Sep 6, 2026
…ak main

Two module moves landed while dependent PRs were in flight, and main now
fails to import the PyTorch runtime:

1. NVIDIA#17899 moved tensorrt_llm/_torch/pyexecutor/kv_cache_manager_v2.py
   under the new kv_cache/ subpackage. NVIDIA#17399, which added the phased and
   PrimTS FMHA libraries, still imports the old path:

       ModuleNotFoundError: No module named
       'tensorrt_llm._torch.pyexecutor.kv_cache_manager_v2'

   fmha/__init__.py imports phased and prims_ts, and
   attention/backends/__init__.py reaches fmha through trtllm.py, so the
   whole attention.backends package is unimportable.

2. NVIDIA#17968 moved tensorrt_llm/_torch/attention_backend/ to
   tensorrt_llm/_torch/attention/backends/. NVIDIA#18652 extracted
   pyexecutor/engine/lora.py with the old path, and model_engine.py
   imports engine.lora, so the executor is unimportable even with (1)
   fixed.

Point the three fmha modules, engine/lora.py, the visual-gen FlashInfer
backend and the affected unit tests
at the current paths, matching the sibling modules. Adds a CPU-only
import guard covering both chains so a future move is caught by the unit
tests.

Signed-off-by: Brian Nguyen <brnguyen@nvidia.com>
@brnguyen2
brnguyen2 force-pushed the fix/fmha-kv-cache-manager-v2-import-path branch from 949f0ff to 0c221e3 Compare September 6, 2026 16:44
@brnguyen2
brnguyen2 marked this pull request as ready for review September 6, 2026 16:44
@brnguyen2
brnguyen2 requested review from a team as code owners September 6, 2026 16:44
@brnguyen2

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71777 [ run ] triggered by Bot. Commit: 0c221e3 Link to invocation

@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3594e96a-39ee-4164-8826-2575aa1e4077

📥 Commits

Reviewing files that changed from the base of the PR and between 70feda6 and 0c221e3.

📒 Files selected for processing (10)
  • tensorrt_llm/_torch/attention/backends/fmha/phased.py
  • tensorrt_llm/_torch/attention/backends/fmha/prims_ts.py
  • tensorrt_llm/_torch/attention/backends/fmha/utils.py
  • tensorrt_llm/_torch/pyexecutor/engine/lora.py
  • tensorrt_llm/_torch/visual_gen/attention_backend/flashinfer.py
  • tests/unittest/_torch/attention/test_backends_importable.py
  • tests/unittest/_torch/attention/test_combined_fmha.py
  • tests/unittest/_torch/attention/test_fmha_page_index.py
  • tests/unittest/_torch/attention/test_prims_ts_fmha.py
  • tests/unittest/_torch/visual_gen/test_attention_flashinfer.py

Included review availability: Your plan provides up to 12 included reviews per hour; 4 remain after this review.


Walkthrough

The change updates relocated import paths for KV-cache and attention symbols. It adds CPU-only tests that verify attention backend, FMHA, engine.lora, and KV-cache imports.

Changes

Import path alignment

Layer / File(s) Summary
KV-cache import path updates
tensorrt_llm/_torch/attention/backends/fmha/*, tests/unittest/_torch/attention/test_{combined_fmha,fmha_page_index,prims_ts_fmha}.py
FMHA modules and tests import KVCacheManagerV2 and Role from the nested kv_cache package.
Attention import paths and validation
tensorrt_llm/_torch/pyexecutor/engine/lora.py, tensorrt_llm/_torch/visual_gen/attention_backend/flashinfer.py, tests/unittest/_torch/attention/test_backends_importable.py, tests/unittest/_torch/visual_gen/test_attention_flashinfer.py
Attention symbols use their relocated interface module. New CPU-only tests verify the relevant package and symbol imports.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 0c221

This updates stale module imports after package moves and adds import coverage for affected attention, FMHA, and LoRA paths. The updated destinations provide the required symbols, with no remaining concrete merge-blocking risk.

Suggested reviewers: juney-nvidia

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required format and clearly describes the primary change: fixing stale attention and KV-cache import paths.
Description check ✅ Passed The description explains the causes, affected modules, solution, and test coverage. It includes the required Description, Test Coverage, and PR Checklist sections, with the checklist reviewed for this…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71777 [ run ] completed with state SUCCESS. Commit: 0c221e3
/LLM/main/L0_MergeRequest_PR pipeline #58856 completed with status: 'SUCCESS'

CI Report

Link to invocation

@brnguyen2

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71812 [ run ] triggered by Bot. Commit: 0c221e3 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #71812 [ run ] completed with state SUCCESS. Commit: 0c221e3
/LLM/main/L0_MergeRequest_PR pipeline #58893 completed with status: 'SUCCESS'

CI Report

Link to invocation

@juney-nvidia juney-nvidia 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.

Approved to unblock the urgent PR

@juney-nvidia
juney-nvidia merged commit 75f521d into NVIDIA:main Sep 6, 2026
14 checks passed
mihai-chiorean pushed a commit to mihai-chiorean/TensorRT-LLM-FlashNext that referenced this pull request Sep 6, 2026
…ak main (NVIDIA#18771)

Signed-off-by: Brian Nguyen
(cherry picked from commit 75f521d)
Signed-off-by: Mihai Chiorean <mihai.v.chiorean@gmail.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.

3 participants