mirror of
https://github.com/hiyouga/LLaMA-Factory.git
synced 2026-07-07 17:45:26 +08:00
[fix] Fixes Qwen3-VL prompt expansion for multiple videos (#10518)
Co-authored-by: gemini-code-assist <200291788+gemini-code-assist@users.noreply.github.com>
This commit is contained in:
@@ -2379,16 +2379,13 @@ class Qwen3VLPlugin(Qwen2VLPlugin):
|
||||
|
||||
image_grid_thw = mm_inputs.get("image_grid_thw", [])
|
||||
video_grid_thw = mm_inputs.get("video_grid_thw", [])
|
||||
num_frames = video_grid_thw[0][0] if len(video_grid_thw) > 0 else 0 # hard code for now
|
||||
video_metadata = mm_inputs.get("video_metadata", [])
|
||||
|
||||
else:
|
||||
image_grid_thw = [None] * len(images)
|
||||
video_grid_thw = [None] * len(videos)
|
||||
num_frames = 0
|
||||
timestamps = [0]
|
||||
|
||||
for idx, message in enumerate(messages):
|
||||
for message in messages:
|
||||
content = message["content"]
|
||||
while IMAGE_PLACEHOLDER in content:
|
||||
image_seqlen = (
|
||||
@@ -2403,19 +2400,17 @@ class Qwen3VLPlugin(Qwen2VLPlugin):
|
||||
|
||||
while VIDEO_PLACEHOLDER in content:
|
||||
if self.expand_mm_tokens:
|
||||
metadata = video_metadata[idx]
|
||||
video_grid = video_grid_thw[num_video_tokens]
|
||||
num_frames = int(video_grid[0].item())
|
||||
metadata = video_metadata[num_video_tokens]
|
||||
timestamps = processor._calculate_timestamps(
|
||||
metadata.frames_indices,
|
||||
metadata.fps,
|
||||
video_processor.merge_size,
|
||||
getattr(video_processor, "temporal_patch_size", 2),
|
||||
)
|
||||
video_structure = ""
|
||||
video_seqlen = int((video_grid[1:].prod() // video_merge_length).item())
|
||||
for frame_index in range(num_frames):
|
||||
video_seqlen = (
|
||||
video_grid_thw[num_video_tokens][1:].prod() // video_merge_length
|
||||
if self.expand_mm_tokens
|
||||
else 1
|
||||
)
|
||||
timestamp_sec = timestamps[frame_index]
|
||||
frame_structure = (
|
||||
f"<{timestamp_sec:.1f} seconds>"
|
||||
|
||||
Reference in New Issue
Block a user