Skip to content

[TRTLLM-17767][refactor] Pin down multimodal item lifetimes across inline, scheduled and prefetched encoding - #21986

Draft
lori-ren wants to merge 7 commits into
NVIDIA:mainfrom
lori-ren:refactor/mm-item-lifetimes
Draft

lori-ren wants to merge 7 commits into
NVIDIA:mainfrom
lori-ren:refactor/mm-item-lifetimes

Conversation

@lori-ren

@lori-ren lori-ren commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

@coderabbitai summary

Description

An audit of who creates, reads and releases multimodal items (request params, encoder-cache entries, encoder and chunk views, prefetch outputs and events) on the inline, item-scheduled and side-stream prefetch paths. Two gaps were confirmed by tests that fail on main and are fixed here; the other transitions already hold and are now pinned by tests.

  • Prefetch stream order. Side-stream prefetch stages a request's MRoPE positions and embeddings on its own CUDA stream. The forward stream sliced the MRoPE positions during input preparation before any wait, and the prefetch event was dropped when the first prefill chunk had no multimodal rows, so a later chunk read the embedding unordered. Input preparation now waits for the event at the point where it is handed over, and calls record_stream on the request's CUDA tensors so that post-prefill cleanup cannot hand their storage back to the side stream while forward-stream reads are still queued.
  • Items behind a reused KV prefix. The EAGER policy binds a waiting request's items from prompt position zero. When KV reuse then starts the prefill past such an item, the item kept its encoder-cache reference, and with a tight output budget the request could never schedule its first chunk. Item selection now releases the items behind the prefill cursor first.

The PR also drops the stale note that inline encoder caching supports only single-modality requests (the two serve schema snapshots are regenerated for it), and documents the prefetch stream rule and the reference-release points in the multimodal developer guide.

Found and left unchanged:

  • The main and side streams share the vision tower's attention workspace when a prefetch encode overlaps an inline encode. A targeted overlap test on H100 did not produce a mismatch, so no cross-stream fence is added.
  • With KV cache manager V1 and MAX_UTILIZATION, a recompute pause releases multimodal inputs the replay needs. V1 is deprecated, and [#17882][fix] Preserve multimodal data for MAX_UTILIZATION pause replay #18113 addresses it.

Test Coverage

  • tests/unittest/_torch/pyexecutor/engine/runners/decoder/test_inputs.py: prefetch-staged MRoPE positions and embeddings are read after the prefetch event, and staged storage outlives the request while it is still read. These fail without the inputs.py change.
  • tests/unittest/_torch/pyexecutor/test_multimodal_scheduler.py: an EAGER item behind a reused prefix does not block the first chunk (fails without the scheduler.py change); termination between chunks releases each remaining reference once.
  • tests/unittest/_torch/multimodal/test_mm_encoder_cross_iter_prefetch.py and tests/unittest/_torch/pyexecutor/test_recompute_pause.py: cancel after prefetch, and a V2 recompute pause keeping multimodal inputs.
  • MMMU on Qwen3-VL-2B with chunked prefill and KV cache manager V2, for the item, EAGER, inline and prefetch paths: no difference from the unmodified baseline beyond run-to-run noise.

The MMMU runs were done on H100 before the branch was rebased onto current main. The unit tests were rerun after the rebase, against binaries built before it. The serve schema snapshots have not been regenerated since the rebase.

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.

… its first read

Prefetch-staged MRoPE positions were read before any wait, and the
event was lost when the first chunk had no multimodal rows.

Signed-off-by: Lori Ren <lorir@nvidia.com>
… item selection

EAGER binds a waiting request's items from position zero; a prefix
reused afterwards left them holding the output budget of its first chunk.

Signed-off-by: Lori Ren <lorir@nvidia.com>
Also documents the prefetch stream rule and when item references
are released.

Signed-off-by: Lori Ren <lorir@nvidia.com>
…coder caching

Inline caching keys every item in the common item record, so
mixed-modality requests are cached per item.

Signed-off-by: Lori Ren <lorir@nvidia.com>
… of test order

Each test runs its path once before the timed pass, and skips
instead of failing when the race was not set up.

Signed-off-by: Lori Ren <lorir@nvidia.com>
…y chunk selects

Releasing per chunk left an earlier chunk unable to use the space
a later request's skipped item still held in that pass.

Signed-off-by: Lori Ren <lorir@nvidia.com>
…aration

Also limits the developer guide's release rule to context-chunk
selection, and annotates a test.

Signed-off-by: Lori Ren <lorir@nvidia.com>
@lori-ren lori-ren added the api-compatible Accepted LLM API contract change that is backwards-compatible label Nov 10, 2026

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant