fix(vllm): preserve source video metadata after frame sampling - #10168
Open
taking-lying-flat wants to merge 1 commit into
Open
taking-lying-flat wants to merge 1 commit into
taking-lying-flat wants to merge 1 commit into
Conversation
Signed-off-by: taking-lying-flat <1615405@qq.com>
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.
PR type
PR information
Preserve source video metadata after
load_vllm_video()samples frames, so downstream timestamp consumers describe the frames at their actual times in the source video. This affects the Gemma4 video path through ms-swift's vLLM backend.The decoder selects source-frame indices with
np.linspace(0, total_frames - 1, num_frames, dtype=int), but_video_get_metadata_local()reports consecutive sampled-frame indices and setsfpstoduration / num_frames(seconds per frame). Consumers that compute timestamps asframe_idx / fpstherefore receive incorrect times, which can become timestamp text in the Gemma4 video prompt.This three-line fix retains the original frame count and FPS, and reports the same source-frame indices used by the decoder. The existing
do_sample_framesflag continues to disable downstream sampling when the loader has already subsampled the video.Experiment results
Generated a real lossless FFV1 AVI with 300 frames at 30 FPS (10 seconds). Each frame encodes its original index in its pixel colors, allowing metadata indices to be checked against the actual decoded frames.
Local regression checks: 30 passed.
Gemma4Template.replace_tag, the actual TransformersGemma4VideoProcessor, andGemma4Processor.replace_video_token. Both sampled videos preserve their frame indices and end with prompt timestamp00:09.git diff --checkpass.Validation used OpenCV 5.0.0, NumPy 2.5.1, and Transformers 5.14.1. Regression scripts were run locally; this PR contains only the production fix. No full model inference or running vLLM service was used.