From 52fbe12283f030c6bbfeb835bab634cbf2be045e Mon Sep 17 00:00:00 2001 From: Lynn Date: Wed, 24 Jun 2026 04:38:27 -0500 Subject: [PATCH] [Perf][Multimodal] Avoid building a full timestamps list in video frame sampling (#46543) Signed-off-by: Lynn Co-authored-by: Claude Opus 4.8 (1M context) --- vllm/multimodal/video.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/vllm/multimodal/video.py b/vllm/multimodal/video.py index 4a82dd24e75..c9751ecc66a 100644 --- a/vllm/multimodal/video.py +++ b/vllm/multimodal/video.py @@ -885,7 +885,6 @@ class GLM46VVideoBackend(VideoBackend): extract_t = min(extract_t, cls._MAX_FRAME_COUNT_DYNAMIC) duration_per_frame = 1 / original_fps if original_fps > 0 else 0 - timestamps = [i * duration_per_frame for i in range(total_frames_num)] max_second = int(duration) if duration else 0 if total_frames_num < extract_t: @@ -897,7 +896,7 @@ class GLM46VVideoBackend(VideoBackend): current_second = 0.0 inv_fps = 1 / (temporal_patch_size * target_fps) for frame_index in range(total_frames_num): - if timestamps[frame_index] >= current_second: + if frame_index * duration_per_frame >= current_second: current_second += inv_fps frame_indices.append(frame_index) if current_second >= max_second: @@ -991,7 +990,6 @@ class GLMGAVideoBackend(VideoBackend): extract_t = min(extract_t, max_frames) duration_per_frame = 1 / original_fps - timestamps = [i * duration_per_frame for i in range(total_frames_num)] if total_frames_num < extract_t: frame_indices = [ @@ -1002,7 +1000,7 @@ class GLMGAVideoBackend(VideoBackend): current_second = 0.0 inv_fps = 1 / target_fps for frame_index in range(total_frames_num): - if timestamps[frame_index] >= current_second: + if frame_index * duration_per_frame >= current_second: current_second += inv_fps frame_indices.append(frame_index) if current_second >= duration - inv_fps: