Skip to content

[TRTLLM-14304][feat] Integrate embeddings cache with encoder side-stream - #16554

Merged
2ez4bz merged 3 commits into
NVIDIA:mainfrom
2ez4bz:dev-mm-encoder-cache
Jul 31, 2026
Merged

2ez4bz merged 3 commits into
NVIDIA:mainfrom
2ez4bz:dev-mm-encoder-cache

Conversation

@2ez4bz

@2ez4bz 2ez4bz commented Jul 17, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Refactors Gemma4 and Qwen3 multimodal wrappers around shared APIs, enabling encoder-cache integration and preserving multimodal item ordering during cross-iteration prefetch.
  • Adds encoder-cache support declarations for Qwen3, Qwen3 MoE, and Qwen3.5 models.
  • Improves multimodal token-ID compatibility by preferring multimodal_token_ids with legacy mm_token_ids fallback.
  • Tightens active-token filtering and updates Qwen3 deepstack fusion and embedding behavior.
  • Updates Qwen Image Bench configuration to disable encoder caching while preserving runtime metadata.
  • Documentation now describes supported models and combined side-stream/cache memory behavior.
  • Review areas: validate the substantial Gemma4 inheritance and weight-loading changes, confirm the new get_language_model_extra_forward_kwargs API is consistent across wrappers, and verify the single-modality-per-request restriction does not regress supported use cases.
  • CI has reported failures for multiple commits and should be investigated before merge.

QA Engineer Review

  • Added or updated coverage for:
    • test_cross_iter_prefetch_materializes_on_side_stream
    • test_prepare_multimodal_indices_uses_mixin_token_ids
    • test_prepare_multimodal_indices_uses_legacy_token_ids
    • test_encoder_cache_reuses_image_embedding_across_requests
    • test_chunked_prefill_reuses_cached_vision_embeddings
    • test_mixed_modality_batch_preserves_request_order
    • test_chunk_without_multimodal_tokens_is_inactive
    • test_single_request_with_multiple_modalities_raises
    • test_qwen3vl_deepstack_fusion_reuses_registered_buffer
  • No test-list changes were identified in the provided summary. CI/test-list coverage for these tests should be confirmed; the reported L0 failures require follow-up.
  • Verdict: needs follow-up.

Description

Test Coverage

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.

@2ez4bz
2ez4bz force-pushed the dev-mm-encoder-cache branch 2 times, most recently from 220dd1d to fa22df4 Compare July 20, 2026 20:08
@2ez4bz 2ez4bz added the api-compatible Accepted LLM API contract change that is backwards-compatible label Jul 20, 2026
@2ez4bz
2ez4bz marked this pull request as ready for review July 20, 2026 21:14
@2ez4bz
2ez4bz requested review from a team as code owners July 20, 2026 21:14
@2ez4bz

2ez4bz commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Changes

Multimodal model interfaces are standardized around shared encoder and language-model hooks. Gemma4 and Qwen3-VL wrappers gain centralized multimodal processing, encoder-cache support, deepstack handling, and updated token contracts. Prefetch ordering, compatibility fallbacks, tests, and supported-model documentation are updated.

Multimodal model integration

Layer / File(s) Summary
Shared multimodal contracts and compatibility
tensorrt_llm/_torch/models/modeling_multimodal_mixin.py, tensorrt_llm/_torch/pyexecutor/model_engine.py, tensorrt_llm/_torch/models/modeling_mistral.py, tensorrt_llm/_torch/models/modeling_qwen3_5.py, tensorrt_llm/_torch/models/modeling_qwen3vl.py, tensorrt_llm/_torch/models/modeling_qwen3vl_moe.py, tensorrt_llm/_torch/models/modeling_qwen_image_bench.py
Shared token-ID lookup, active-parameter filtering, forwarding hooks, encoder-cache flags, and multimodal configuration handling are updated.
Gemma4 shared multimodal base
tensorrt_llm/_torch/models/modeling_gemma4mm.py, tensorrt_llm/_torch/models/modeling_gemma4_unified.py, tests/unittest/_torch/modeling/test_gemma4_multimodal.py
Gemma4 multimodal encoding and forwarding are centralized in Gemma4MultimodalModelBase, with cache reuse, modality validation, ordering, and inactive-chunk tests updated.
Qwen3-VL multimodal flow
tensorrt_llm/_torch/models/modeling_qwen3vl.py, tests/unittest/_torch/modeling/test_modeling_qwen3vl.py
Qwen3-VL encoding, embedding accessors, deepstack fusion, language-model extras, and reusable deepstack-buffer behavior are updated and tested.
Prefetch ordering and cache documentation
tensorrt_llm/_torch/models/modeling_multimodal_mixin.py, tests/unittest/_torch/multimodal/test_mm_encoder_cross_iter_prefetch.py, docs/source/models/supported-models.md
Cross-iteration prefetch propagates multimodal item order, while documentation covers additional cache-capable models and combined side-stream cache behavior.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MultimodalModelMixin
  participant Gemma4MultimodalModelBase
  participant VisionAudioEncoders
  participant LanguageModel
  MultimodalModelMixin->>Gemma4MultimodalModelBase: select multimodal params
  Gemma4MultimodalModelBase->>VisionAudioEncoders: encode multimodal inputs
  VisionAudioEncoders-->>Gemma4MultimodalModelBase: packed embeddings
  Gemma4MultimodalModelBase->>LanguageModel: forward with multimodal extras
Loading

Possibly related PRs

  • NVIDIA/TensorRT-LLM#16662: Also modifies cross-iteration multimodal prefetch dispatch and encoder-cache-aware embedding handling.

Suggested reviewers: qijune, chienchunhung, yihuilu512, schetlur-nv, laikhtewari

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.17% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is only the template with no issue, solution, or test coverage filled in. Add a short problem/solution summary and list the relevant tests in the Description and Test Coverage sections.
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title uses the required ticket/type format and clearly summarizes the cache-side-stream integration.
✨ 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/_torch/multimodal/test_multimodal_mixin.py`:
- Around line 262-269: Update test_encoder_cache_requires_model_opt_in to
reference the public encoder_cache_active property on DummyMultimodalModel
instead of the nonexistent _encoder_cache_active attribute, while preserving the
assertion that the cache is inactive and _get_multimodal_encoder_cache() returns
None.
🪄 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: 643c2135-56e9-45e6-92f6-84de30895f71

📥 Commits

Reviewing files that changed from the base of the PR and between b520c6f and fa22df4.

📒 Files selected for processing (13)
  • docs/source/models/supported-models.md
  • tensorrt_llm/_torch/models/modeling_multimodal_mixin.py
  • tensorrt_llm/_torch/models/modeling_multimodal_utils.py
  • tensorrt_llm/_torch/pyexecutor/_util.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tensorrt_llm/_torch/tensor_lru_cache.py
  • tensorrt_llm/inputs/multimodal.py
  • tensorrt_llm/llmapi/llm_args.py
  • tests/unittest/_torch/multimodal/test_mm_encoder_cross_iter_prefetch.py
  • tests/unittest/_torch/multimodal/test_multimodal_mixin.py
  • tests/unittest/_torch/test_tensor_lru_cache.py
  • tests/unittest/llmapi/test_llm_args.py

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60462 [ run ] triggered by Bot. Commit: fa22df4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@2ez4bz

2ez4bz commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60491 [ run ] triggered by Bot. Commit: fa22df4 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@2ez4bz
2ez4bz force-pushed the dev-mm-encoder-cache branch from fa22df4 to e084f4d Compare July 21, 2026 03:51
@2ez4bz

2ez4bz commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #60565 [ run ] triggered by Bot. Commit: e084f4d Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@2ez4bz
2ez4bz requested a review from crazydemo July 28, 2026 23:50
@2ez4bz

2ez4bz commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62335 [ run ] triggered by Bot. Commit: d295fba Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

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

LGTM

@2ez4bz

2ez4bz commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62564 [ run ] triggered by Bot. Commit: d295fba Link to invocation

@2ez4bz
2ez4bz force-pushed the dev-mm-encoder-cache branch from d295fba to ba4a8a0 Compare July 29, 2026 18:45
@2ez4bz

2ez4bz commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62579 [ run ] triggered by Bot. Commit: ba4a8a0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62564 [ run ] completed with state ABORTED. Commit: d295fba

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@2ez4bz

2ez4bz commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62691 [ run ] triggered by Bot. Commit: ba4a8a0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

2ez4bz added 3 commits July 30, 2026 09:18
* Why?

Side-stream multimodal encoder prefetch and the persistent embeddings cache
were mutually exclusive, preventing requests from benefiting from both
overlapped encoder work and cross-request embedding reuse.

* What?

Allow supported multimodal models to use both features together. Prefetch
now reads and populates the persistent cache while preserving CUDA stream
ordering and tensor lifetimes.

Signed-off-by: William Zhang <[email protected]>
Signed-off-by: William Zhang <[email protected]>
Signed-off-by: William Zhang <[email protected]>
@2ez4bz
2ez4bz force-pushed the dev-mm-encoder-cache branch from ba4a8a0 to 4d1d2f7 Compare July 30, 2026 16:19
@2ez4bz

2ez4bz commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62811 [ run ] triggered by Bot. Commit: 4d1d2f7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62811 [ run ] completed with state FAILURE. Commit: 4d1d2f7
/LLM/main/L0_MergeRequest_PR pipeline #50937 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

@2ez4bz

2ez4bz commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62840 [ run ] triggered by Bot. Commit: 4d1d2f7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62840 [ run ] completed with state FAILURE. Commit: 4d1d2f7
/LLM/main/L0_MergeRequest_PR pipeline #50964 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

@2ez4bz

2ez4bz commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62946 [ run ] triggered by Bot. Commit: 4d1d2f7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

CI Report

Link to invocation

@2ez4bz
2ez4bz merged commit 10a9432 into NVIDIA:main Jul 31, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-compatible Accepted LLM API contract change that is backwards-compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants