[TRTLLM-14304][feat] Integrate embeddings cache with encoder side-stream#16554
[TRTLLM-14304][feat] Integrate embeddings cache with encoder side-stream#165542ez4bz wants to merge 1 commit into
Conversation
| _MM_ENCODER_CACHE_LOG_NAME = "mm_encoder_cache" | ||
|
|
||
|
|
||
| def _build_request_multimodal_input( |
There was a problem hiding this comment.
This was moved from tensorrt_llm/_torch/pyexecutor/model_engine.py to avoid circular dependencies.
220dd1d to
fa22df4
Compare
|
/bot run |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (9)
🚧 Files skipped from review as they are similar to previous changes (9)
WalkthroughMultimodal encoder caching now works with cross-iteration side-stream prefetch. Cache activation is centralized, CUDA stream ordering is tracked in ChangesMultimodal encoder cache and prefetch
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant PyExecutor
participant MultimodalModelMixin
participant TensorLRUCache
participant ConsumerStream
PyExecutor->>MultimodalModelMixin: Dispatch cross-iteration prefetch
MultimodalModelMixin->>TensorLRUCache: Lookup or store encoder embeddings
TensorLRUCache-->>MultimodalModelMixin: Return embeddings and producer event
MultimodalModelMixin->>ConsumerStream: Attach encoder event and embeddings
ConsumerStream->>ConsumerStream: Wait and record tensor lifetime
Possibly related PRs
Suggested reviewers: 🚥 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
🤖 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
📒 Files selected for processing (13)
docs/source/models/supported-models.mdtensorrt_llm/_torch/models/modeling_multimodal_mixin.pytensorrt_llm/_torch/models/modeling_multimodal_utils.pytensorrt_llm/_torch/pyexecutor/_util.pytensorrt_llm/_torch/pyexecutor/model_engine.pytensorrt_llm/_torch/pyexecutor/py_executor.pytensorrt_llm/_torch/tensor_lru_cache.pytensorrt_llm/inputs/multimodal.pytensorrt_llm/llmapi/llm_args.pytests/unittest/_torch/multimodal/test_mm_encoder_cross_iter_prefetch.pytests/unittest/_torch/multimodal/test_multimodal_mixin.pytests/unittest/_torch/test_tensor_lru_cache.pytests/unittest/llmapi/test_llm_args.py
|
PR_Github #60462 [ run ] triggered by Bot. Commit: |
|
PR_Github #60462 [ run ] completed with state
|
|
/bot run |
|
PR_Github #60491 [ run ] triggered by Bot. Commit: |
|
PR_Github #60491 [ run ] completed with state
|
fa22df4 to
e084f4d
Compare
|
/bot run |
|
PR_Github #60565 [ run ] triggered by Bot. Commit: |
|
PR_Github #60565 [ run ] completed with state
|
|
/bot run |
|
PR_Github #60613 [ run ] triggered by Bot. Commit: |
|
PR_Github #60613 [ run ] completed with state
|
|
/bot run |
|
PR_Github #60720 [ run ] triggered by Bot. Commit: |
|
PR_Github #60720 [ run ] completed with state
|
|
/bot run |
|
PR_Github #60745 [ ] completed with state |
|
/bot run |
|
PR_Github #60816 [ run ] triggered by Bot. Commit: |
|
PR_Github #60816 [ run ] completed with state
|
e084f4d to
bd94ed0
Compare
|
/bot run |
|
PR_Github #61638 [ run ] triggered by Bot. Commit: |
|
PR_Github #61638 [ run ] completed with state
|
* 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 <133824995+2ez4bz@users.noreply.github.com>
bd94ed0 to
76324bd
Compare
|
/bot run |
|
PR_Github #61681 [ run ] triggered by Bot. Commit: |
|
PR_Github #61681 [ run ] completed with state
|
Summary by CodeRabbit
New Features
Bug Fixes / Correctness
TensorLRUCachenow supports CUDA stream-aware entries via producer events, with consumers waiting/recording streams to avoid premature reuse.Documentation
encoder_side_stream_max_aheadinteracts with multimodal embeddings caching and the combined peak-memory implications.Dev Engineer Review
Config / API consistency
MultimodalConfigvalidation was updated to allowencoder_side_stream_max_ahead+encoder_cache_max_bytestogether (memory limits treated as additive), while keeping the existing incompatibility withencoder_cuda_graph.Core implementation
MultimodalModelMixin.encoder_cache_activeto centralize gating for “cache enabled” based on model opt-in (supports_encoder_cache) and configured cache capacity.TensorLRUCache(..., cuda_stream_aware=encoder_side_stream_max_ahead>0).MultimodalInputandMultimodalRuntimeData) when caching is active and routes through persistent-cache lookup/write (_get_or_encode_multimodal_embeddings); otherwise it uses the chunked prefill embedding storage path (_store_chunked_prefill_embeddings).get_multimodal_embeddingsnow waits onparam.encoder_event(when present) and thenrecord_stream(consumer_stream)for CUDA embedding tensors to keep storage valid on the consuming stream.get_multimodal_embeddingsso consumer-side stream attachment occurs before reading.Memory reservation
MultimodalModelMixininstance andmodel.encoder_cache_activeis true, preventing incorrect reservation for models that don’t opt in / aren’t compatible.Supporting plumbing
TensorLRUCachestream-aware mode adds optional producer events onput()and forces cross-stream waiting +record_stream()inget()/pop()when enabled, with associated unit tests.Testing artifacts / CI health
SUCCESSbut L0 pipelineFAILURE; needs follow-up confirmation that the failures are fully resolved and green before merge.QA Engineer Review
tests/): yestests/unittest/_torch/multimodal/test_mm_encoder_cross_iter_prefetch.py_CacheStubModelstub withsupports_encoder_cache = True_make_cacheable_requesttest_cross_iter_prefetch_populates_and_reuses_persistent_cachetest_cross_iter_prefetch_mixed_cache_hit_and_miss_encodes_only_misstest_cross_iter_prefetch_cache_model_preserves_uncacheable_fallbackstest_cross_iter_prefetch_does_not_synchronize_main_streamtest_cross_iter_prefetch_does_not_rewrite_request_local_embeddingtest_prefetched_embedding_records_main_consumer_stream(parametrized)tests/unittest/_torch/multimodal/test_multimodal_mixin.pysupports_encoder_cache = Truetest_encoder_cache_requires_model_opt_intests/unittest/_torch/test_tensor_lru_cache.pytest_stream_aware_mode_leaves_cpu_cache_behavior_unchangedtest_cuda_stream_aware_cache_orders_cross_stream_producer_and_consumertest_cuda_stream_aware_cache_pop_orders_cross_stream_consumertest_cuda_stream_aware_cache_preserves_evicted_consumer_storagetests/unittest/llmapi/test_llm_args.pyModified
encoder_side_stream_max_aheadandencoder_cache_max_bytesRemoved
test_encoder_cache_and_side_stream_max_ahead_are_exclusiveAdded
test_encoder_cache_and_side_stream_max_ahead_can_be_combinedCoverage in
tests/integration/test_lists/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.