Repository navigation
Description
System Info
- TensorRT-LLM 1.3.0rc25 (
785c948); transformers 5.5.4 (the version pinned inrequirements.txt, also onmain). - Re-checked on
mainat760a584(2026-10-12):_decide_do_sample_framesandQwen3VLInputProcessorBase._preprocessare identical to rc25 (main L169-221 and L349-425). - Model:
Qwen/Qwen3-VL-2B-Instruct(the 8B model goes through the same code path). - Seen end-to-end through the NVIDIA Dynamo TensorRT-LLM backend (
7e8b9fc2) in aggregated multimodal mode; the reproduction below is CPU-only and needs only the HF processor.
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examplesfolder (such as GLUE/SQuAD, ...) - My own task or dataset (give details below)
Reproduction
Qwen3VLInputProcessorBase._preprocess (tensorrt_llm/_torch/models/modeling_qwen3vl.py, L400-412 in rc25, L402-414 on main) forwards VideoData.metadata to the HF processor with total_num_frames rewritten to len(vd.frames), so that HF's sample_frames (np.linspace(0, total_num_frames - 1, num_frames)) stays in range. The metadata fps (source video fps) and frames_indices are left untouched. When the IO layer has already subsampled the clip (e.g. 40 frames out of a 10 s / 24 fps / 240-frame video), HF's Qwen3VLVideoProcessor therefore believes the video is 40/24 = 1.67 s long and, with its class defaults (fps=2, min_frames=4), samples int(40/24*2) = 3 -> 4 frames. This is the default path: when the caller passes no do_sample_frames / num_frames / fps, _decide_do_sample_frames (L167-219 in rc25, L169-221 on main) turns sampling on to match HF's class default. Two consequences:
- Only 4 of the 40 decoded frames reach the ViT (1760 visual tokens instead of 11880). Any caller that does not pass
mm_processor_kwargs={"do_sample_frames": False}(or an exactnum_frames) silently gets a 4-frame summary of the video, regardless of clip length (a 30 s clip decoded to 40 frames gives the identical 4-frame result). - The
<t seconds>timestamp tokens inserted by the processor are computed from the resampled indices over the rewrittentotal_num_framesdivided by the source fps, so they are compressed by (decoded frames / source frames): for the 10 s clip the model sees<0.3 seconds>and<1.4 seconds>for frames that are actually at about 0 s, 3.3 s, 6.7 s and 10 s.
With do_sample_frames=False the processor uses frames_indices / fps, and both the frame count and the timestamps are correct, which shows the frame list itself is fine; only the sampling-path metadata is inconsistent. For comparison, HF sampling the 240-frame source itself at the default fps=2 would keep int(240/24*2) = 20 frames with timestamps in source seconds, so the rewrite also makes the default path diverge from stock HF, which _decide_do_sample_frames intends to match.
Reproduction (CPU only, HF processor only):
- Decode a 10 s, 24 fps, 1280x720 H.264 clip into 40 uniformly spaced RGB float32
(C, H, W)tensors in [0, 1], metadata ={"fps": 24.0, "total_num_frames": 240, "duration": 10.0, "frames_indices": linspace(0, 239, 40)}. - Apply the same rewrite as
_preprocess(total_num_frames := 40) and callAutoProcessor.from_pretrained("Qwen/Qwen3-VL-2B-Instruct")(text=[chat_template_text], videos=[frames], video_metadata=[meta], do_sample_frames=True, do_rescale=False, padding=True, return_tensors="pt"). - Observe
video_grid_thw == [2, 44, 80], 1760<|video_pad|>tokens, timestamps<0.3 seconds>,<1.4 seconds>. - Same call with
do_sample_frames=False:video_grid_thw == [20, 36, 66], 11880 tokens, timestamps<0.1 seconds>,<0.6 seconds>,<1.1 seconds>,<1.6 seconds>, ... (one per 0.5 s across the clip). - Without the rewrite (original
total_num_frames=240) HF raisesIndexError: index 50 is out of bounds for axis 0 with size 40, which confirms why the rewrite exists. - End-to-end: the Dynamo TensorRT-LLM worker's
/metricsreportstrtllm_prompt_tokens_total = 1789(= 1760 visual + 4 vision markers + 12 timestamp tokens + 13 text) for this request.
Expected behavior
Either (a) when rewriting total_num_frames to the decoded count, also rescale fps to len(frames) / duration and reset frames_indices to range(len(frames)), so HF's duration and timestamps stay consistent with the frames it receives, or (b) default do_sample_frames to False whenever the caller passes an already-subsampled frame list with frames_indices (the IO layer has done the sampling), and only sample when the caller explicitly asks for num_frames / fps.
actual behavior
With default mm_processor_kwargs, 4 of 40 decoded frames reach the ViT and the timestamps are compressed by 40/240 (details under Reproduction).
additional notes
Impact. Silent quality loss for every video request that relies on defaults (temporal reasoning over a ~2 s window of a longer clip, wrong timestamps), plus misleading throughput numbers (the prompt is ~7x shorter than intended).
Workaround. Pass mm_processor_kwargs={"do_sample_frames": False} per request (the frame count is then whatever the IO layer decoded, e.g. DYN_MM_VIDEO_NUM_FRAMES in Dynamo).
The metadata rewrite and _decide_do_sample_frames were introduced in #15598.
Related: #20138 (Qwen3-VL video over the E/PD handoff; its reproduction passes do_sample_frames=False to get all decoded frames into the ViT, i.e. the workaround above).
Before submitting a new issue...
- Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.
Activity
Epsilon006 commentedon Oct 12, 2026
Hi, I'd like to work on this issue.
I'll start by adding CPU-only regression tests for pre-sampled video inputs, focusing on frame sampling and timestamp consistency.
Then I'll implement a minimal fix that preserves the original temporal metadata and avoids unintended re-sampling, while keeping existing behavior compatible.
I'll submit a PR once the fix is tested.
Epsilon006 commentedon Oct 18, 2026
Thanks @karljang for the 👍 on my contribution request above.
The fix is ready on my existing fork branch, with the original implementation commits preserved. The latest commit is ab58aef6c, which only adds regression coverage.
The adapter keeps IO-sampled frames by default and maps explicitly resampled positions back to their source indices/FPS, including nonuniform indices and mixed-video batches.
Validation with the pinned transformers 5.5.4 on CPU:
All 23 regression cases pass with the fix; the same tests against the unmodified adapter at current main 2f5bb04 produce 14 failures and 9 passes.
Tests cover actual timestamp text sent to the tokenizer, frame selection/pixels, duration fallback, explicit controls, full-video HF parity, and input immutability.
Full pre-commit passes for both changed files; commit-message DCO checks pass. All three commits include Signed-off-by.
A Git trial merge against current main completes without conflicts. The CPU test directory is already covered by l0_cpu.yml.
GPU inference, Dynamo end-to-end tests, and performance benchmarks have not been run.
I checked related PRs, including #20497 for the separate #20138 E/PD layout problem; I found no direct competing fix for this sampling path.
CONTRIBUTING.md says issue requests must be reviewed and approved by TensorRT-LLM engineers before code review. Could you confirm whether your 👍 means this issue is approved for a PR? The signed branch and PR description are prepared; I am waiting for that confirmation before opening the PR.
karljang commentedon Oct 19, 2026
Thank you for bringing this to my attention. It appears that the contribution guide requires an update.
Please create a pull request and the review process will commence from there. Thank you!
[NVIDIA#20141][fix] Preserve Qwen3-VL sampled video frames and timest…
[NVIDIA#20141][refactor] Prepare each Qwen3-VL video in one helper