Repository navigation
[TRTLLM-12869][feat] Encode images and video without a prompt, and prefill from the encoded items - #20902
Draft
yechank-nvidia wants to merge 7 commits into
Draft
[TRTLLM-12869][feat] Encode images and video without a prompt, and prefill from the encoded items#20902yechank-nvidia wants to merge 7 commits into
yechank-nvidia wants to merge 7 commits into
Conversation
This was referenced Oct 23, 2026
1 task done
1 task done
yechank-nvidia
force-pushed
the
refactor/mm-handoff-compatible-20261023
branch
from
November 16, 2026 10:46
1c70c4b to
b2ce284
Compare
This was referenced Nov 16, 2026
Closed
1 task done
Problem ------- A caller with cached image or video embeddings must send the full prompt to encode the remaining items. A synthetic prompt's positions cannot be reused in another request. Solution -------- Let processors opt in to an item-only encoder request. Build one placeholder per item and keep the synthetic layout and positions out of the result. Release the unused position handles. Preserve each item's hash on its handle, including across a cache hit. Give each item its own random key when the encoder has no content hash. Validation ---------- CPU tests cover pixel and grid parity, two-step preprocessing, hash precedence and release of synthetic position handles. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- The video grid alone cannot reproduce the temporal positions of Qwen2.5-VL or the frame timestamps in a Qwen3-VL prompt. Solution -------- Keep the sampled video timing beside its host-built grid. Export seconds per grid step for Qwen2.5-VL and the processor's frame-group timestamps for Qwen3-VL. Keep each value with its video when the encoder selects a subset. Validation ---------- Processor tests reconstruct a video prompt from the exported timing and check that each video keeps its metadata in prompt order. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- Prefill cannot combine cached images with newly encoded videos when the encoder has never seen the final prompt. Solution -------- Expand the real prompt using each item's grid and video timing, then tokenize it once. Rebuild its mRoPE positions and KV-cache spans. Accept attached tensors grouped by modality or handles in prompt order. Keep the existing handoff for handles with a prompt layout or mRoPE. Validate each item's geometry against its embedding rows. Validation ---------- Compare prompt IDs, positions, spans and hashes against raw media for both prefill entry points. Cover images, video, mixed item order, partial cache hits and inconsistent metadata. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- A typed caller cannot submit the documented media-only input to the encoder. Its asynchronous method also excludes preprocessed inputs. Solution -------- Give the standalone encoder a media-only dictionary type. Use the existing single-input check for batched requests and pass each request through the asynchronous entry point. Validation ---------- Type-check single and batched media, asynchronous generation and preprocessing followed by submission. The caller passes all cases. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- The SM103 vision target accepts attached rows but only runs its embedding splice for raw pixels. The decoder can consume pad tokens in place of the encoded video. Solution -------- Reject precomputed embeddings at request admission on this target. Validation ---------- The CPU test builds a real video item through the Qwen processor. Admission now raises a request error for its attached rows. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- Splitting a Qwen request can change video sampling or pixel rescaling. An absent media bucket creates a placeholder, and an invalid item order can send the wrong media to the processor. Solution -------- Require a sampling decision for prompt-free videos with a frame target. Accept raw RGB frames with consistent rescaling across calls. Skip absent buckets and validate the order within each modality. Validation ---------- CPU tests reproduce all six failures before the fix. Compare the pixels and frame times of two separate encodes with a full request under each explicit sampling policy. Signed-off-by: Yechan Kim <[email protected]>
Problem ------- The item matcher rejects valid Qwen prompts. External video timing can exceed the rotary table. Two videos with the same layout or two encodes with different normalization can reuse the wrong KV blocks. Solution -------- Match Qwen's pad tokens and video wrappers. Validate frame times and rotary positions on the host. Store timestamps as ordinary floats. Give each encoder export and each hashless submission a fresh item identity. Validate supplied digests before constructing KV inputs. Document how to cache owned rows and schedule single-modality batches. Validation ---------- Compare raw, attached and handle prompts and positions. Check video timing, safe reload, digest bounds and output length on CPU. On GB200 the old head returned the red clip's answer for a blue clip after four block hits, and reused seven blocks for different normalization. Signed-off-by: Yechan Kim <[email protected]>
yechank-nvidia
force-pushed
the
refactor/mm-handoff-compatible-20261023
branch
from
November 23, 2026 02:55
b2ce284 to
5dc8913
Compare
Collaborator
Author
|
/bot run |
Collaborator
|
PR_Github #86632 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #86632 [ run ] completed with state
|
1 task done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
An application with a cached image and a new video should be able to encode just the video and use both items in a later prompt. The standalone encoder currently needs the full prompt, and video rows alone do not identify the frame times or positions that prefill needs.
What
MultimodalEncoder. Each exported item carries its grid, video timing where applicable, and a fresh hash for its encoded rows.{"mm_embeddings": tensor, **metadata}form or encoder handles in prompt order. It rebuilds the prompt IDs, mRoPE positions and KV spans. It accepts Qwen image-pad spacing and the Qwen3 bare-video spelling. The pixel-only SM103 target rejects attached rows at admission.fpsornum_framesrequire an explicitdo_sample_framessetting across the request. Qwen2.5 needs homogeneous scheduled encoder batches. A shared encoder can setmax_batch_size=1and accept one modality per request.Validation
Validated revision
5dc8913d4e82is based on33d42fadb9a6, which includes #22328.The reviewed head reproduced both cache problems on a shared GB200. A blue video submitted after a red one reused four KV blocks and answered red. Changing image normalization for the same UUID reused seven blocks and returned the previous output. On the fixed Qwen3-VL head, those inputs and a raw-to-attached normalization test all matched their independent cold controls. Reuse stopped at the first media token (10 common prefix tokens for video and four for images). Submitting one saved video twice through fresh CUDA exports reused 128 tokens on each call and preserved the raw result.
The broad CPU run had 6,738 passes and nine failures. All 6,855 shared cases had the same outcome on the reviewed control. All 18 added cases passed. The nine failures reproduced on the controls. With the final test expectations applied to both revisions, all 20 targeted regressions failed before the fixes and passed after them. Another 99 V2, encoder, SM103 and serving ownership cases and 38 protected LLM API tests passed.
On a shared GB200 at TP1 and BF16, attached tensors and handles matched the full raw prompt and all 32 greedy output tokens in 44/44 comparisons (24 Qwen3-VL-8B and 20 Qwen2.5-VL-7B). All 13 encoder comparisons were bitwise equal. These comparisons used CPU-staged handles with block reuse disabled. The separate warm-cache tests above used default V2 and fresh CUDA exports. Qwen2.5 concurrent image/video submissions matched their solo encodes in both orders at batch size one. Tests used the
8ba86b8bnative build with its matching operator registrations. The SM103 admission test ran on CPU.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.