[Bugfix] Align video frame consumption reporting with prompt sampling (#7329)
This commit is contained in:
1 parent
3319f6ca78
commit
7bceb1a76b
4 files changed
+232
-22
No files matched your search
@@ -30,7 +30,6 @@ from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from vllm_omni.entrypoints.openai.video_stream_base import (
|
||||
_BAD_FRAME,
|
||||
_DEFAULT_CONFIG_TIMEOUT,
|
||||
_DEFAULT_IDLE_TIMEOUT,
|
||||
PrewarmedFrame,
|
||||
@@ -62,22 +61,19 @@ class QwenOmniStreamingVideoHandler(OmniStreamingVideoHandlerBase):
|
||||
message_history: list[dict[str, Any]],
|
||||
query_text: str,
|
||||
prewarmed_frames: Mapping[str, PrewarmedFrame],
|
||||
*,
|
||||
frame_indices: list[int] | None = None,
|
||||
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
||||
n_buf = len(frame_buffer)
|
||||
if n_buf <= config.num_frames:
|
||||
frames = list(frame_buffer)
|
||||
else:
|
||||
stride = max(1, n_buf // config.num_frames)
|
||||
idx = [i * stride for i in range(config.num_frames - 1)] + [n_buf - 1]
|
||||
frames = [frame_buffer[i] for i in idx]
|
||||
|
||||
prewarmed = prewarmed_frames or {}
|
||||
if frame_indices is None:
|
||||
frame_indices = self._sample_frame_indices(frame_buffer, config.num_frames, prewarmed)
|
||||
user_content: list[dict] = []
|
||||
for frame_b64 in frames:
|
||||
for index in frame_indices:
|
||||
frame_b64 = frame_buffer[index]
|
||||
cached = prewarmed.get(frame_b64)
|
||||
if cached is _BAD_FRAME:
|
||||
continue
|
||||
if cached is not None:
|
||||
# The shared selector excludes failed decodes before this point.
|
||||
assert isinstance(cached, tuple)
|
||||
pil, pil_uuid = cached
|
||||
user_content.append(
|
||||
{
|
||||
|
||||
@@ -93,8 +93,10 @@ class VideoStreamPipelineHooks(Protocol):
|
||||
message_history: list[dict[str, Any]],
|
||||
query_text: str,
|
||||
prewarmed_frames: Mapping[str, PrewarmedFrame],
|
||||
*,
|
||||
frame_indices: list[int] | None = None,
|
||||
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
||||
"""Build OpenAI-style messages and the current user message."""
|
||||
"""Build messages using the supplied frame selection, or sample if omitted."""
|
||||
...
|
||||
|
||||
def on_turn_complete(
|
||||
@@ -179,6 +181,8 @@ class OmniStreamingVideoHandler:
|
||||
message_history: list[dict[str, Any]],
|
||||
query_text: str,
|
||||
prewarmed_frames: Mapping[str, PrewarmedFrame],
|
||||
*,
|
||||
frame_indices: list[int] | None = None,
|
||||
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -639,6 +643,9 @@ class OmniStreamingVideoHandler:
|
||||
ChatCompletionRequest,
|
||||
)
|
||||
|
||||
# Select once from this turn's snapshot so prompt images and the
|
||||
# consumed event refer to exactly the same frames, including decode failures.
|
||||
frame_indices = self._sample_frame_indices(frame_buffer, config.num_frames, prewarmed_frames)
|
||||
messages, user_message = self.build_engine_prompt(
|
||||
config,
|
||||
frame_buffer,
|
||||
@@ -646,6 +653,7 @@ class OmniStreamingVideoHandler:
|
||||
message_history,
|
||||
query_text,
|
||||
prewarmed_frames,
|
||||
frame_indices=frame_indices,
|
||||
)
|
||||
|
||||
request_kwargs: dict[str, Any] = {
|
||||
@@ -678,7 +686,7 @@ class OmniStreamingVideoHandler:
|
||||
await self._send_error(websocket, f"Preprocess failed: {e}")
|
||||
return
|
||||
decoded_ready_ts_ms = _time.monotonic() * 1000
|
||||
selected_metadata = self._sample_frame_metadata(frame_metadata or [], config.num_frames)
|
||||
selected_metadata = [frame_metadata[index] for index in frame_indices] if frame_metadata else []
|
||||
model_selected_ts_ms = _time.monotonic() * 1000
|
||||
|
||||
await websocket.send_json({"type": "response.start"})
|
||||
@@ -1071,15 +1079,19 @@ class OmniStreamingVideoHandler:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _sample_frame_metadata(
|
||||
frame_metadata: list[dict[str, Any]],
|
||||
def _sample_frame_indices(
|
||||
frame_buffer: list[str],
|
||||
num_frames: int,
|
||||
) -> list[dict[str, Any]]:
|
||||
if len(frame_metadata) <= num_frames:
|
||||
return list(frame_metadata)
|
||||
stride = max(1, len(frame_metadata) // num_frames)
|
||||
indices = [index * stride for index in range(num_frames - 1)] + [len(frame_metadata) - 1]
|
||||
return [frame_metadata[index] for index in indices]
|
||||
prewarmed_frames: Mapping[str, PrewarmedFrame],
|
||||
) -> list[int]:
|
||||
"""Stride-sample with the last frame, then drop known bad frames without refilling."""
|
||||
n_buf = len(frame_buffer)
|
||||
if n_buf <= num_frames:
|
||||
indices = list(range(n_buf))
|
||||
else:
|
||||
stride = max(1, n_buf // num_frames)
|
||||
indices = [index * stride for index in range(num_frames - 1)] + [n_buf - 1]
|
||||
return [index for index in indices if prewarmed_frames.get(frame_buffer[index]) is not _BAD_FRAME]
|
||||
|
||||
@staticmethod
|
||||
async def _send_frame_ack(
|
||||
|
||||
Reference in new issue
Block a user