[None][feat] Enable MM encoder cache on Qwen3.x and Gemma4 VLMs#16662
[None][feat] Enable MM encoder cache on Qwen3.x and Gemma4 VLMs#166622ez4bz wants to merge 2 commits into
Conversation
7da572a to
f6fabcc
Compare
📝 WalkthroughWalkthroughGemma4 and Qwen multimodal model wrappers now use encoder-cache-aware embedding retrieval, expose multimodal embedding metadata, and declare cache support. Tests verify reuse across requests, while documentation lists the expanded supported model set. ChangesMultimodal encoder cache support
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Request
participant MultimodalModel
participant MultimodalModelMixin
participant EncoderCache
participant MultimodalEncoder
Request->>MultimodalModel: image or video inputs
MultimodalModel->>MultimodalModelMixin: _get_or_encode_multimodal_embeddings
MultimodalModelMixin->>EncoderCache: lookup embeddings
alt cache miss
MultimodalModelMixin->>MultimodalModel: encode_multimodal_inputs
MultimodalModel->>MultimodalEncoder: encode multimodal inputs
MultimodalEncoder-->>MultimodalModelMixin: multimodal embeddings
MultimodalModelMixin->>EncoderCache: store embeddings
else cache hit
EncoderCache-->>MultimodalModelMixin: cached embeddings
end
MultimodalModelMixin-->>MultimodalModel: embeddings
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unittest/_torch/modeling/test_gemma4_multimodal.py (1)
765-776: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftAdd production-path cache coverage for Qwen and Gemma.
Coverage is insufficient: this harness calls
_get_or_encode_multimodal_embeddings()directly, so it does not exercise Gemma4forward()or Qwen’s new_get_qwen_multimodal_embeddings()routing. Add cache-hit/miss tests totests/unittest/_torch/modeling/test_gemma4_multimodal.pyand the Qwen3-VL model test module, asserting two identical raw requests invoke the encoder once; parameterize the Qwen test across dense, MoE, and Qwen3.5 wrappers. Run the targeted tests underpytest tests/unittest/.As per path instructions, “Keep feedback actionable: suggest concrete list file names and whether coverage is sufficient, insufficient, or needs follow-up outside the PR.”
🤖 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/_torch/modeling/test_gemma4_multimodal.py` around lines 765 - 776, The cache test only exercises the helper directly and does not cover production routing. Add cache miss/hit tests through Gemma4ForConditionalGeneration.forward and Qwen’s _get_qwen_multimodal_embeddings, asserting identical raw requests invoke the encoder once; parameterize Qwen coverage across dense, MoE, and Qwen3.5 wrappers, and run the targeted tests under pytest tests/unittest/.Source: Path instructions
🤖 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 `@docs/source/models/supported-models.md`:
- Around line 129-138: Add Gemma4ForConditionalGeneration to the
MultimodalModelMixin optimization matrix, mark Multimodal Embeddings Cache as
Yes, and set Multimodal Encoder Side Stream according to its verified support
status.
---
Nitpick comments:
In `@tests/unittest/_torch/modeling/test_gemma4_multimodal.py`:
- Around line 765-776: The cache test only exercises the helper directly and
does not cover production routing. Add cache miss/hit tests through
Gemma4ForConditionalGeneration.forward and Qwen’s
_get_qwen_multimodal_embeddings, asserting identical raw requests invoke the
encoder once; parameterize Qwen coverage across dense, MoE, and Qwen3.5
wrappers, and run the targeted tests under pytest tests/unittest/.
🪄 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: 2af008bf-08c0-455b-8e97-c6273f5a8e3d
📒 Files selected for processing (6)
docs/source/models/supported-models.mdtensorrt_llm/_torch/models/modeling_gemma4mm.pytensorrt_llm/_torch/models/modeling_qwen3_5.pytensorrt_llm/_torch/models/modeling_qwen3vl.pytensorrt_llm/_torch/models/modeling_qwen3vl_moe.pytests/unittest/_torch/modeling/test_gemma4_multimodal.py
f6fabcc to
993b8cd
Compare
Signed-off-by: William Zhang <133824995+2ez4bz@users.noreply.github.com>
993b8cd to
99db94e
Compare
Summary by CodeRabbit
New Features
Documentation
Tests
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.