[Frontend] Add omni benchmark support for image and video endpoints (#4728)
This commit is contained in:
1 parent
e1c59edec6
commit
b1ec136bd7
21 files changed
+1626
-72
No files matched your search
@@ -52,6 +52,21 @@ _MULTIMODAL_BENCHMARK_FIELDS = [
|
||||
(defs.MEDIAN_IMAGE_GENERATION_MS, float, field(default=0.0)),
|
||||
(defs.STD_IMAGE_GENERATION_MS, float, field(default=0.0)),
|
||||
(defs.PERCENTILES_IMAGE_GENERATION_MS, _PERCENTILE_ROWS_TYPE, field(default=None)),
|
||||
(defs.TOTAL_VIDEO_DURATION_S, float, field(default=0.0)),
|
||||
(defs.TOTAL_VIDEO_FRAMES, int, field(default=0)),
|
||||
(defs.VIDEO_THROUGHPUT, float, field(default=0.0)),
|
||||
(defs.MEAN_VIDEO_RTF, float, field(default=0.0)),
|
||||
(defs.MEDIAN_VIDEO_RTF, float, field(default=0.0)),
|
||||
(defs.STD_VIDEO_RTF, float, field(default=0.0)),
|
||||
(defs.PERCENTILES_VIDEO_RTF, _PERCENTILE_ROWS_TYPE, field(default=None)),
|
||||
(defs.MEAN_VIDEO_GENERATION_MS, float, field(default=0.0)),
|
||||
(defs.MEDIAN_VIDEO_GENERATION_MS, float, field(default=0.0)),
|
||||
(defs.STD_VIDEO_GENERATION_MS, float, field(default=0.0)),
|
||||
(defs.PERCENTILES_VIDEO_GENERATION_MS, _PERCENTILE_ROWS_TYPE, field(default=None)),
|
||||
(defs.MEAN_PEAK_MEMORY_MB, float, field(default=0.0)),
|
||||
(defs.MEDIAN_PEAK_MEMORY_MB, float, field(default=0.0)),
|
||||
(defs.STD_PEAK_MEMORY_MB, float, field(default=0.0)),
|
||||
(defs.PERCENTILES_PEAK_MEMORY_MB, _PERCENTILE_ROWS_TYPE, field(default=None)),
|
||||
]
|
||||
|
||||
MultiModalsBenchmarkMetrics = make_dataclass(
|
||||
@@ -171,8 +186,10 @@ def _stage_modality_flags(
|
||||
) -> tuple[bool, bool, bool, bool, bool]:
|
||||
is_text_stage = final_output_type == "text" or output_unit_type == "text"
|
||||
is_audio_stage = final_output_type == "audio" or output_unit_type == "audio"
|
||||
is_image_stage = final_output_type in {"image", "images"} or output_unit_type == "image"
|
||||
is_video_stage = final_output_type in {"video", "videos"} or output_unit_type == "video"
|
||||
# Video diffusion may still report output_unit_type="image" when frames are
|
||||
# stored in ``images``; prefer video when final_output_type says so.
|
||||
is_image_stage = (not is_video_stage) and (final_output_type in {"image", "images"} or output_unit_type == "image")
|
||||
is_internal_stream_stage = (
|
||||
output_unit_type in _STREAMING_OUTPUT_UNIT_TYPES and not is_text_stage and not is_audio_stage
|
||||
)
|
||||
@@ -222,6 +239,7 @@ def print_metrics(
|
||||
print("{:<40} {:<10.2f}".format("Request goodput (req/s):", metrics.request_goodput))
|
||||
if isinstance(metrics, MultiModalsBenchmarkMetrics):
|
||||
print("{:<40} {:<10.2f}".format("Peak concurrent requests:", metrics.max_concurrent_requests))
|
||||
print_peak_memory_metrics(metrics)
|
||||
if task_type != TaskType.GENERATION or "e2el" in selected_percentile_metrics:
|
||||
process_one_metric("e2el", metrics)
|
||||
print_text_metrics(task_type, selected_percentile_metrics, metrics)
|
||||
@@ -230,9 +248,13 @@ def print_metrics(
|
||||
print_audio_metrics(selected_percentile_metrics, metrics)
|
||||
if _has_image_output(metrics):
|
||||
print_image_metrics(selected_percentiles or [], metrics)
|
||||
if _has_video_output(metrics):
|
||||
print_video_metrics(selected_percentiles or [], metrics)
|
||||
if print_stage and outputs and selected_percentiles is not None:
|
||||
print("\n{s:{c}^{n}}".format(s=" Stage Benchmark Result ", n=50, c="="))
|
||||
for sm in _build_stage_metrics_from_outputs(outputs):
|
||||
stage_metrics = _build_stage_metrics_from_outputs(outputs)
|
||||
if stage_metrics:
|
||||
print("\n{s:{c}^{n}}".format(s=" Stage Benchmark Result ", n=50, c="="))
|
||||
for sm in stage_metrics:
|
||||
print_stage_metrics(
|
||||
task_type,
|
||||
selected_percentile_metrics,
|
||||
@@ -243,6 +265,11 @@ def print_metrics(
|
||||
|
||||
|
||||
def print_text_metrics(task_type, selected_percentile_metrics, metrics: MultiModalsBenchmarkMetrics):
|
||||
# Pure image/video runs have no user-facing text tokens; skip the whole
|
||||
# Text Result section (token throughput / peak would be misleading).
|
||||
if metrics.total_output <= 0 and (_has_image_output(metrics) or _has_video_output(metrics)):
|
||||
return
|
||||
|
||||
print("{s:{c}^{n}}".format(s=" Text Result ", n=50, c="="))
|
||||
print("{:<40} {:<10}".format("Total input tokens:", metrics.total_input))
|
||||
if isinstance(metrics, MultiModalsBenchmarkMetrics):
|
||||
@@ -275,6 +302,14 @@ def _has_image_output(metrics: MultiModalsBenchmarkMetrics) -> bool:
|
||||
return int(getattr(metrics, defs.TOTAL_IMAGES, 0) or 0) > 0
|
||||
|
||||
|
||||
def _has_video_output(metrics: MultiModalsBenchmarkMetrics) -> bool:
|
||||
return (
|
||||
float(getattr(metrics, defs.TOTAL_VIDEO_DURATION_S, 0.0) or 0.0) > 0.0
|
||||
or int(getattr(metrics, defs.TOTAL_VIDEO_FRAMES, 0) or 0) > 0
|
||||
or float(getattr(metrics, defs.MEAN_VIDEO_GENERATION_MS, 0.0) or 0.0) > 0.0
|
||||
)
|
||||
|
||||
|
||||
def print_audio_metrics(selected_percentile_metrics, metrics: MultiModalsBenchmarkMetrics):
|
||||
print("{s:{c}^{n}}".format(s=" Audio Result ", n=50, c="="))
|
||||
print(
|
||||
@@ -293,6 +328,16 @@ def print_audio_metrics(selected_percentile_metrics, metrics: MultiModalsBenchma
|
||||
process_one_metric(metric, metrics)
|
||||
|
||||
|
||||
def print_peak_memory_metrics(metrics: MultiModalsBenchmarkMetrics):
|
||||
if getattr(metrics, defs.MEAN_PEAK_MEMORY_MB) <= 0:
|
||||
return
|
||||
print("{s:{c}^{n}}".format(s="Peak Memory", n=50, c="-"))
|
||||
print("{:<40} {:<10.2f}".format("Mean PEAK_MEMORY_MB (MB):", getattr(metrics, defs.MEAN_PEAK_MEMORY_MB)))
|
||||
print("{:<40} {:<10.2f}".format("Median PEAK_MEMORY_MB (MB):", getattr(metrics, defs.MEDIAN_PEAK_MEMORY_MB)))
|
||||
for p, value in getattr(metrics, defs.PERCENTILES_PEAK_MEMORY_MB) or []:
|
||||
print("{:<40} {:<10.2f}".format(f"P{_p_label(p)} PEAK_MEMORY_MB (MB):", value))
|
||||
|
||||
|
||||
def print_image_metrics(selected_percentiles: list[float], metrics: MultiModalsBenchmarkMetrics):
|
||||
print("{s:{c}^{n}}".format(s=" Image Result ", n=50, c="="))
|
||||
print("{:<40} {:<10}".format("Total images generated:", getattr(metrics, defs.TOTAL_IMAGES)))
|
||||
@@ -311,7 +356,7 @@ def print_image_metrics(selected_percentiles: list[float], metrics: MultiModalsB
|
||||
)
|
||||
)
|
||||
if getattr(metrics, defs.MEAN_IMAGE_GENERATION_MS) > 0:
|
||||
print("-----------------Image Generation-----------------")
|
||||
print("{s:{c}^{n}}".format(s=" Image Generation ", n=50, c="-"))
|
||||
print("{:<40} {:<10.2f}".format("Mean IMAGE_GENERATION (ms):", getattr(metrics, defs.MEAN_IMAGE_GENERATION_MS)))
|
||||
print(
|
||||
"{:<40} {:<10.2f}".format(
|
||||
@@ -324,6 +369,42 @@ def print_image_metrics(selected_percentiles: list[float], metrics: MultiModalsB
|
||||
print("{:<40} {:<10.2f}".format(f"P{_p_label(p)} IMAGE_GENERATION (ms):", value))
|
||||
|
||||
|
||||
def print_video_metrics(selected_percentiles: list[float], metrics: MultiModalsBenchmarkMetrics):
|
||||
print("{s:{c}^{n}}".format(s=" Video Result ", n=50, c="="))
|
||||
print(
|
||||
"{:<40} {:<10.2f}".format(
|
||||
"Total video duration generated(s):",
|
||||
getattr(metrics, defs.TOTAL_VIDEO_DURATION_S),
|
||||
)
|
||||
)
|
||||
print("{:<40} {:<10}".format("Total video frames generated:", getattr(metrics, defs.TOTAL_VIDEO_FRAMES)))
|
||||
print(
|
||||
"{:<40} {:<10.2f}".format(
|
||||
"Video throughput(video duration/s):",
|
||||
getattr(metrics, defs.VIDEO_THROUGHPUT),
|
||||
)
|
||||
)
|
||||
if getattr(metrics, defs.MEAN_VIDEO_RTF) > 0:
|
||||
print("{s:{c}^{n}}".format(s=" Video RTF ", n=50, c="-"))
|
||||
print("{:<40} {:<10.2f}".format("Mean VIDEO_RTF:", getattr(metrics, defs.MEAN_VIDEO_RTF)))
|
||||
print("{:<40} {:<10.2f}".format("Median VIDEO_RTF:", getattr(metrics, defs.MEDIAN_VIDEO_RTF)))
|
||||
for p, value in getattr(metrics, defs.PERCENTILES_VIDEO_RTF) or []:
|
||||
if p in selected_percentiles:
|
||||
print("{:<40} {:<10.2f}".format(f"P{_p_label(p)} VIDEO_RTF:", value))
|
||||
if getattr(metrics, defs.MEAN_VIDEO_GENERATION_MS) > 0:
|
||||
print("{s:{c}^{n}}".format(s=" Video Generation ", n=50, c="-"))
|
||||
print("{:<40} {:<10.2f}".format("Mean VIDEO_GENERATION (ms):", getattr(metrics, defs.MEAN_VIDEO_GENERATION_MS)))
|
||||
print(
|
||||
"{:<40} {:<10.2f}".format(
|
||||
"Median VIDEO_GENERATION (ms):",
|
||||
getattr(metrics, defs.MEDIAN_VIDEO_GENERATION_MS),
|
||||
)
|
||||
)
|
||||
for p, value in getattr(metrics, defs.PERCENTILES_VIDEO_GENERATION_MS) or []:
|
||||
if p in selected_percentiles:
|
||||
print("{:<40} {:<10.2f}".format(f"P{_p_label(p)} VIDEO_GENERATION (ms):", value))
|
||||
|
||||
|
||||
def process_one_metric(
|
||||
metric_attribute_name: str,
|
||||
metrics: MultiModalsBenchmarkMetrics,
|
||||
@@ -495,6 +576,21 @@ def _print_image_stage_metrics(
|
||||
)
|
||||
|
||||
|
||||
def _print_video_stage_metrics(
|
||||
selected_percentiles: list[float],
|
||||
sm: StageBenchmarkMetrics,
|
||||
) -> None:
|
||||
print("{s:{c}^{n}}".format(s=" Video Result ", n=50, c="="))
|
||||
_print_percentile_metric(
|
||||
"Video Generation",
|
||||
"VIDEO_GENERATION",
|
||||
getattr(sm, defs.STAGE_GEN_TIMES_MS),
|
||||
selected_percentiles,
|
||||
values_are_ms=True,
|
||||
to_ms=True,
|
||||
)
|
||||
|
||||
|
||||
def _print_internal_stream_stage_metrics(
|
||||
selected_percentile_metrics: list[str],
|
||||
selected_percentiles: list[float],
|
||||
@@ -549,11 +645,12 @@ def print_stage_metrics(
|
||||
) = _stage_modality_flags(getattr(sm, "final_output_type"), getattr(sm, "output_unit_type"))
|
||||
|
||||
print("{s:{c}^{n}}".format(s=title, n=50, c="="))
|
||||
if is_image_stage:
|
||||
_print_image_stage_metrics(selected_percentiles, sm)
|
||||
if is_video_stage:
|
||||
_print_video_stage_metrics(selected_percentiles, sm)
|
||||
return
|
||||
|
||||
if is_video_stage:
|
||||
if is_image_stage:
|
||||
_print_image_stage_metrics(selected_percentiles, sm)
|
||||
return
|
||||
|
||||
_print_stage_timing(sm, selected_percentiles)
|
||||
@@ -754,6 +851,11 @@ def calculate_metrics(
|
||||
denoise_step_latencies_ms: list[float] = []
|
||||
total_images = 0
|
||||
total_image_pixels = 0
|
||||
video_durations: list[float] = []
|
||||
video_rtfs: list[float] = []
|
||||
total_video_frames = 0
|
||||
video_generation_times_ms: list[float] = []
|
||||
peak_memories_mb: list[float] = []
|
||||
audio_underruns: list[float] = []
|
||||
audio_continuity_ok: list[bool] = []
|
||||
input_audio_duration = 0.0
|
||||
@@ -762,7 +864,18 @@ def calculate_metrics(
|
||||
output_len = outputs[i].output_tokens
|
||||
|
||||
if not output_len:
|
||||
if tokenizer is None:
|
||||
# Pure image/video (no generated text) must stay at 0 tokens.
|
||||
# Do not invent output_len=1 via the tokenizer-is-None placeholder.
|
||||
generated_text = getattr(outputs[i], "generated_text", None) or ""
|
||||
has_image = int(getattr(outputs[i], defs.IMAGE_COUNT, 0) or 0) > 0
|
||||
has_video = (
|
||||
float(getattr(outputs[i], defs.VIDEO_DURATION, 0.0) or 0.0) > 0.0
|
||||
or int(getattr(outputs[i], defs.VIDEO_FRAMES, 0) or 0) > 0
|
||||
or float(getattr(outputs[i], defs.VIDEO_GENERATION_TIME_MS, 0.0) or 0.0) > 0.0
|
||||
)
|
||||
if not generated_text and (has_image or has_video):
|
||||
output_len = 0
|
||||
elif tokenizer is None:
|
||||
output_len = 1
|
||||
else:
|
||||
# We use the tokenizer to count the number of output tokens
|
||||
@@ -827,6 +940,19 @@ def calculate_metrics(
|
||||
denoise_step_latency_ms = float(getattr(outputs[i], defs.DENOISE_STEP_LATENCY_MS, 0.0) or 0.0)
|
||||
if denoise_step_latency_ms > 0:
|
||||
denoise_step_latencies_ms.append(denoise_step_latency_ms)
|
||||
video_duration = float(getattr(outputs[i], defs.VIDEO_DURATION, 0.0) or 0.0)
|
||||
if video_duration > 0:
|
||||
video_durations.append(video_duration)
|
||||
total_video_frames += int(getattr(outputs[i], defs.VIDEO_FRAMES, 0) or 0)
|
||||
video_rtf = float(getattr(outputs[i], defs.VIDEO_RTF, 0.0) or 0.0)
|
||||
if video_rtf > 0:
|
||||
video_rtfs.append(video_rtf)
|
||||
video_generation_time_ms = float(getattr(outputs[i], defs.VIDEO_GENERATION_TIME_MS, 0.0) or 0.0)
|
||||
if video_generation_time_ms > 0:
|
||||
video_generation_times_ms.append(video_generation_time_ms)
|
||||
peak_memory_mb = float(getattr(outputs[i], defs.PEAK_MEMORY_MB, 0.0) or 0.0)
|
||||
if peak_memory_mb > 0:
|
||||
peak_memories_mb.append(peak_memory_mb)
|
||||
audio_underruns.append(getattr(outputs[i], f"{defs.AUDIO_UNDERRUN}_s", 0.0))
|
||||
audio_continuity_ok.append(bool(getattr(outputs[i], defs.AUDIO_CONTINUITY_OK, True)))
|
||||
e2els.append(outputs[i].latency)
|
||||
@@ -892,18 +1018,24 @@ def calculate_metrics(
|
||||
token_timeline_available = False
|
||||
else:
|
||||
# Calculate token generation timestamp using
|
||||
# start_time, ttft, and itl
|
||||
token_times = [output.start_time + output.ttft]
|
||||
current_time = token_times[0]
|
||||
for itl_value in output.itl:
|
||||
current_time += itl_value
|
||||
token_times.append(current_time)
|
||||
# start_time, ttft, and itl. Skip requests with no text tokens
|
||||
# (empty itl, zero output_tokens, and no generated_text) so pure
|
||||
# image/video runs do not seed a fake peak of 1 tok/s from
|
||||
# start_time+ttft alone.
|
||||
output_token_count = int(getattr(output, "output_tokens", 0) or 0)
|
||||
has_generated_text = bool(getattr(output, "generated_text", None) or "")
|
||||
if output_token_count > 0 or output.itl or has_generated_text:
|
||||
token_times = [output.start_time + output.ttft]
|
||||
current_time = token_times[0]
|
||||
for itl_value in output.itl:
|
||||
current_time += itl_value
|
||||
token_times.append(current_time)
|
||||
|
||||
# Add tokens to second buckets
|
||||
for token_time in token_times:
|
||||
second_bucket = int(token_time - min_start_time)
|
||||
if 0 <= second_bucket < duration_seconds:
|
||||
tokens_per_second[second_bucket] += 1
|
||||
# Add tokens to second buckets
|
||||
for token_time in token_times:
|
||||
second_bucket = int(token_time - min_start_time)
|
||||
if 0 <= second_bucket < duration_seconds:
|
||||
tokens_per_second[second_bucket] += 1
|
||||
|
||||
# Track concurrent requests for each second this request was active
|
||||
request_start_second = int(output.start_time - min_start_time)
|
||||
@@ -1009,6 +1141,25 @@ def calculate_metrics(
|
||||
defs.PERCENTILES_IMAGE_GENERATION_MS: [
|
||||
(p, np.percentile(image_generation_times_ms or 0, p)) for p in selected_percentiles
|
||||
],
|
||||
defs.TOTAL_VIDEO_DURATION_S: sum(video_durations),
|
||||
defs.TOTAL_VIDEO_FRAMES: total_video_frames,
|
||||
defs.VIDEO_THROUGHPUT: sum(video_durations) / dur_s,
|
||||
defs.MEAN_VIDEO_RTF: np.mean(video_rtfs or 0),
|
||||
defs.STD_VIDEO_RTF: np.std(video_rtfs or 0),
|
||||
defs.MEDIAN_VIDEO_RTF: np.median(video_rtfs or 0),
|
||||
defs.PERCENTILES_VIDEO_RTF: [(p, np.percentile(video_rtfs or 0, p)) for p in selected_percentiles],
|
||||
defs.MEAN_VIDEO_GENERATION_MS: np.mean(video_generation_times_ms or 0),
|
||||
defs.STD_VIDEO_GENERATION_MS: np.std(video_generation_times_ms or 0),
|
||||
defs.MEDIAN_VIDEO_GENERATION_MS: np.median(video_generation_times_ms or 0),
|
||||
defs.PERCENTILES_VIDEO_GENERATION_MS: [
|
||||
(p, np.percentile(video_generation_times_ms or 0, p)) for p in selected_percentiles
|
||||
],
|
||||
defs.MEAN_PEAK_MEMORY_MB: np.mean(peak_memories_mb or 0),
|
||||
defs.STD_PEAK_MEMORY_MB: np.std(peak_memories_mb or 0),
|
||||
defs.MEDIAN_PEAK_MEMORY_MB: np.median(peak_memories_mb or 0),
|
||||
defs.PERCENTILES_PEAK_MEMORY_MB: [
|
||||
(p, np.percentile(peak_memories_mb or 0, p)) for p in selected_percentiles
|
||||
],
|
||||
defs.MEAN_AUDIO_UNDERRUN_S: np.mean(audio_underruns or 0),
|
||||
defs.STD_AUDIO_UNDERRUN_S: np.std(audio_underruns or 0),
|
||||
defs.MEDIAN_AUDIO_UNDERRUN_S: np.median(audio_underruns or 0),
|
||||
|
||||
@@ -14,7 +14,7 @@ import time
|
||||
import traceback
|
||||
import uuid
|
||||
import wave
|
||||
from collections.abc import Iterable
|
||||
from collections.abc import Iterable, Mapping
|
||||
from dataclasses import dataclass, replace
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
@@ -23,6 +23,7 @@ from typing import TYPE_CHECKING, Any, Literal
|
||||
import aiohttp
|
||||
import numpy as np
|
||||
import pybase64 as base64
|
||||
from PIL import Image
|
||||
from tqdm.asyncio import tqdm
|
||||
from vllm.benchmarks import datasets
|
||||
from vllm.benchmarks.datasets import SampleRequest
|
||||
@@ -85,7 +86,7 @@ from vllm_omni.benchmarks.omniinteract import (
|
||||
write_batch_artifacts as write_omniinteract_batch_artifacts,
|
||||
)
|
||||
from vllm_omni.metrics import definitions as defs
|
||||
from vllm_omni.metrics.utils import coerce_positive_int_scalar
|
||||
from vllm_omni.metrics.utils import coerce_bool, coerce_positive_float_scalar, coerce_positive_int_scalar
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm_omni.clients.duplex import DuplexClient
|
||||
@@ -100,7 +101,13 @@ logger = init_logger(__name__)
|
||||
|
||||
_AUDIO_CONTINUITY_THRESHOLD_ENV = "VLLM_OMNI_BENCH_AUDIO_CONTINUITY_THRESHOLD_S"
|
||||
RETURN_STAGE_METRICS_FIELD = "return_stage_metrics"
|
||||
_IMAGE_STAGE_METRICS_BACKENDS = frozenset({"openai-image-edits-omni"})
|
||||
_IMAGE_STAGE_METRICS_BACKENDS = frozenset(
|
||||
{
|
||||
"/v1/images/generations",
|
||||
"/v1/images/edits",
|
||||
"openai-image-edits-omni",
|
||||
}
|
||||
)
|
||||
_PRINT_STAGE = False
|
||||
|
||||
|
||||
@@ -662,6 +669,11 @@ class MixRequestFuncOutput(RequestFuncOutput):
|
||||
image_generation_time_ms: float = 0.0
|
||||
image_pixels: int = 0
|
||||
denoise_step_latency_ms: float = 0.0
|
||||
video_duration: float = 0.0
|
||||
video_rtf: float = 0.0
|
||||
video_frames: int = 0
|
||||
video_generation_time_ms: float = 0.0
|
||||
peak_memory_mb: float = 0.0
|
||||
text_latency: float = 0.0
|
||||
tpot_measured: bool = True
|
||||
#: Worst-case streaming-audio underrun (wall-clock seconds the player
|
||||
@@ -849,7 +861,7 @@ def _record_text_token_stream_intervals(
|
||||
|
||||
def _update_output_stage_metrics_from_payload(
|
||||
output: MixRequestFuncOutput,
|
||||
data: dict[str, Any],
|
||||
data: Mapping[str, object],
|
||||
*,
|
||||
update_output_tokens: bool = True,
|
||||
) -> None:
|
||||
@@ -897,7 +909,55 @@ def _apply_chat_stage0_token_timings(output: MixRequestFuncOutput) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _image_metrics_from_stage_metrics(metrics: dict[str, Any] | None) -> tuple[int, float, int, float]:
|
||||
def _peak_memory_mb_from_payload(data: Mapping[str, object]) -> float:
|
||||
peak_memory_mb = coerce_positive_float_scalar(data.get(defs.PEAK_MEMORY_MB))
|
||||
if peak_memory_mb is not None:
|
||||
return peak_memory_mb
|
||||
|
||||
for key in ("metrics", "usage"):
|
||||
nested = data.get(key)
|
||||
if isinstance(nested, dict):
|
||||
peak_memory_mb = coerce_positive_float_scalar(nested.get(defs.PEAK_MEMORY_MB))
|
||||
if peak_memory_mb is not None:
|
||||
return peak_memory_mb
|
||||
|
||||
response_data = data.get("data")
|
||||
if isinstance(response_data, list):
|
||||
for item in response_data:
|
||||
if isinstance(item, dict):
|
||||
peak_memory_mb = coerce_positive_float_scalar(item.get(defs.PEAK_MEMORY_MB))
|
||||
if peak_memory_mb is not None:
|
||||
return peak_memory_mb
|
||||
|
||||
choices = data.get("choices")
|
||||
if isinstance(choices, list):
|
||||
for choice in choices:
|
||||
if not isinstance(choice, dict):
|
||||
continue
|
||||
contents = []
|
||||
message = choice.get("message")
|
||||
if isinstance(message, dict):
|
||||
contents.append(message.get("content"))
|
||||
delta = choice.get("delta")
|
||||
if isinstance(delta, dict):
|
||||
contents.append(delta.get("content"))
|
||||
for content in contents:
|
||||
if isinstance(content, list):
|
||||
for item in content:
|
||||
if isinstance(item, dict):
|
||||
peak_memory_mb = coerce_positive_float_scalar(item.get(defs.PEAK_MEMORY_MB))
|
||||
if peak_memory_mb is not None:
|
||||
return peak_memory_mb
|
||||
return 0.0
|
||||
|
||||
|
||||
def _update_output_peak_memory_from_payload(output: MixRequestFuncOutput, data: Mapping[str, object]) -> None:
|
||||
peak_memory_mb = _peak_memory_mb_from_payload(data)
|
||||
if peak_memory_mb > output.peak_memory_mb:
|
||||
output.peak_memory_mb = peak_memory_mb
|
||||
|
||||
|
||||
def _image_metrics_from_stage_metrics(metrics: object) -> tuple[int, float, int, float]:
|
||||
if not isinstance(metrics, dict):
|
||||
return 0, 0.0, 0, 0.0
|
||||
stage_snapshot = metrics.get("stage_metrics")
|
||||
@@ -924,7 +984,7 @@ def _image_metrics_from_stage_metrics(metrics: dict[str, Any] | None) -> tuple[i
|
||||
return image_count, image_generation_ms, image_pixels, denoise_step_latency_ms
|
||||
|
||||
|
||||
def _image_generation_ms_from_content(content: Any) -> float:
|
||||
def _image_generation_ms_from_content(content: object) -> float:
|
||||
if not isinstance(content, list):
|
||||
return 0.0
|
||||
for item in content:
|
||||
@@ -943,6 +1003,263 @@ def _image_generation_ms_from_content(content: Any) -> float:
|
||||
return 0.0
|
||||
|
||||
|
||||
def _image_info_from_response_data(content: object) -> tuple[int, int]:
|
||||
if not isinstance(content, list):
|
||||
return 0, 0
|
||||
image_count = 0
|
||||
total_pixels = 0
|
||||
for item in content:
|
||||
if not isinstance(item, dict):
|
||||
continue
|
||||
b64_json = item.get("b64_json")
|
||||
if not isinstance(b64_json, str) or not b64_json:
|
||||
continue
|
||||
try:
|
||||
with Image.open(io.BytesIO(base64.b64decode(b64_json, validate=True))) as img:
|
||||
width, height = img.size
|
||||
img.verify()
|
||||
image_count += 1
|
||||
total_pixels += int(width) * int(height)
|
||||
except Exception:
|
||||
logger.debug("Failed to decode generated image payload", exc_info=True)
|
||||
return image_count, total_pixels
|
||||
|
||||
|
||||
def _apply_image_metrics_from_payload(output: MixRequestFuncOutput, data: Mapping[str, object]) -> int:
|
||||
"""Populate image benchmark fields from an OpenAI-compatible image payload."""
|
||||
_update_output_stage_metrics_from_payload(output, data, update_output_tokens=False)
|
||||
_update_output_peak_memory_from_payload(output, data)
|
||||
|
||||
payload_image_count = 0
|
||||
response_data = data.get("data")
|
||||
if isinstance(response_data, list):
|
||||
payload_image_count, content_image_pixels = _image_info_from_response_data(response_data)
|
||||
output.image_count = max(output.image_count, payload_image_count)
|
||||
content_image_ms = _image_generation_ms_from_content(response_data)
|
||||
if content_image_ms > 0:
|
||||
output.image_generation_time_ms = max(output.image_generation_time_ms, content_image_ms)
|
||||
if content_image_pixels > 0:
|
||||
output.image_pixels = max(output.image_pixels, content_image_pixels)
|
||||
|
||||
(
|
||||
metrics_image_count,
|
||||
metrics_image_ms,
|
||||
metrics_image_pixels,
|
||||
metrics_denoise_step_ms,
|
||||
) = _image_metrics_from_stage_metrics(data.get("metrics"))
|
||||
if metrics_image_count > output.image_count:
|
||||
output.image_count = metrics_image_count
|
||||
if metrics_image_ms > output.image_generation_time_ms:
|
||||
output.image_generation_time_ms = metrics_image_ms
|
||||
if metrics_image_pixels > output.image_pixels:
|
||||
output.image_pixels = metrics_image_pixels
|
||||
if metrics_denoise_step_ms > output.denoise_step_latency_ms:
|
||||
output.denoise_step_latency_ms = metrics_denoise_step_ms
|
||||
return payload_image_count
|
||||
|
||||
|
||||
_VIDEO_FORM_FIELDS = (
|
||||
"seconds",
|
||||
"num_frames",
|
||||
"fps",
|
||||
"num_inference_steps",
|
||||
"seed",
|
||||
"negative_prompt",
|
||||
"guidance_scale",
|
||||
"guidance_scale_2",
|
||||
"boundary_ratio",
|
||||
"flow_shift",
|
||||
"true_cfg_scale",
|
||||
"generate_sound",
|
||||
"sound_duration",
|
||||
"enable_frame_interpolation",
|
||||
"frame_interpolation_exp",
|
||||
"frame_interpolation_scale",
|
||||
"frame_interpolation_model_path",
|
||||
"lora",
|
||||
"extra_params",
|
||||
)
|
||||
|
||||
|
||||
def _video_generation_ms_from_stage_durations(stage_durations: object) -> float:
|
||||
if not isinstance(stage_durations, dict):
|
||||
return 0.0
|
||||
gen_values = [
|
||||
float(value)
|
||||
for key, value in stage_durations.items()
|
||||
if str(key).endswith("_gen_ms") and isinstance(value, (int, float))
|
||||
]
|
||||
return max(gen_values) if gen_values else 0.0
|
||||
|
||||
|
||||
def _video_duration_from_payload(data: Mapping[str, object], request_body: Mapping[str, object]) -> float:
|
||||
duration_s = coerce_positive_float_scalar(data.get("duration_s"))
|
||||
if duration_s is not None and duration_s > 0:
|
||||
return duration_s
|
||||
|
||||
num_frames = coerce_positive_float_scalar(data.get("num_frames"))
|
||||
fps = coerce_positive_float_scalar(data.get("fps"))
|
||||
if num_frames is not None and fps is not None and num_frames > 0 and fps > 0:
|
||||
return num_frames / fps
|
||||
|
||||
seconds = coerce_positive_float_scalar(request_body.get("seconds"))
|
||||
if seconds is not None and seconds > 0:
|
||||
return seconds
|
||||
|
||||
num_frames = coerce_positive_float_scalar(request_body.get("num_frames"))
|
||||
fps = coerce_positive_float_scalar(request_body.get("fps"))
|
||||
if num_frames is not None and fps is not None and num_frames > 0 and fps > 0:
|
||||
return num_frames / fps
|
||||
|
||||
return 0.0
|
||||
|
||||
|
||||
def _video_frames_from_payload(data: Mapping[str, object], request_body: Mapping[str, object]) -> int:
|
||||
for key in ("num_frames", "video_frames", "frames"):
|
||||
value = data.get(key)
|
||||
if isinstance(value, list):
|
||||
return len(value)
|
||||
num_frames = coerce_positive_int_scalar(value)
|
||||
if num_frames is not None:
|
||||
return num_frames
|
||||
|
||||
duration_s = coerce_positive_float_scalar(data.get("duration_s"))
|
||||
fps = coerce_positive_float_scalar(data.get("fps"))
|
||||
if duration_s is not None and fps is not None and duration_s > 0 and fps > 0:
|
||||
return int(round(duration_s * fps))
|
||||
|
||||
num_frames = coerce_positive_int_scalar(request_body.get("num_frames"))
|
||||
if num_frames is not None:
|
||||
return num_frames
|
||||
|
||||
seconds = coerce_positive_float_scalar(request_body.get("seconds"))
|
||||
fps = coerce_positive_float_scalar(request_body.get("fps"))
|
||||
if seconds is not None and fps is not None and seconds > 0 and fps > 0:
|
||||
return int(round(seconds * fps))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def _is_structured_image_reference(reference: Mapping[str, object]) -> bool:
|
||||
"""True for API image_reference objects ({image_url}/{file_id})."""
|
||||
image_url = reference.get("image_url")
|
||||
file_id = reference.get("file_id")
|
||||
has_url = isinstance(image_url, str) and bool(image_url)
|
||||
has_file_id = isinstance(file_id, str) and bool(file_id)
|
||||
return has_url or has_file_id
|
||||
|
||||
|
||||
def _add_video_reference_to_form(form: aiohttp.FormData, reference: object) -> bool:
|
||||
if isinstance(reference, dict) and "bytes" in reference:
|
||||
form.add_field(
|
||||
"input_reference",
|
||||
reference["bytes"],
|
||||
filename="benchmark-reference",
|
||||
content_type=reference.get("content_type", "application/octet-stream"),
|
||||
)
|
||||
return True
|
||||
|
||||
if isinstance(reference, Mapping) and _is_structured_image_reference(reference):
|
||||
form.add_field("image_reference", json.dumps(dict(reference)))
|
||||
return True
|
||||
|
||||
if isinstance(reference, list):
|
||||
if reference and all(isinstance(item, Mapping) and _is_structured_image_reference(item) for item in reference):
|
||||
form.add_field("image_reference", json.dumps([dict(item) for item in reference]))
|
||||
return True
|
||||
raise ValueError(
|
||||
"Unsupported image_reference list; expected non-empty list of "
|
||||
'{"image_url": "..."} and/or {"file_id": "..."} objects.'
|
||||
)
|
||||
|
||||
if isinstance(reference, str):
|
||||
if reference.startswith(("data:image", "http://", "https://")):
|
||||
form.add_field("image_reference", json.dumps({"image_url": reference}))
|
||||
return True
|
||||
local_path = reference.removeprefix("file://")
|
||||
if os.path.exists(local_path):
|
||||
with open(local_path, "rb") as f:
|
||||
reference_bytes = f.read()
|
||||
form.add_field(
|
||||
"input_reference",
|
||||
reference_bytes,
|
||||
filename=os.path.basename(local_path),
|
||||
content_type=_guess_mime_type(local_path),
|
||||
)
|
||||
return True
|
||||
raise ValueError(f"Unsupported image_reference path or URL: {reference!r}")
|
||||
|
||||
raise ValueError(
|
||||
"Unsupported image_reference; expected upload bytes, local path/URL string, "
|
||||
'or {"image_url": "..."} / {"file_id": "..."} object '
|
||||
f"(got {type(reference).__name__})."
|
||||
)
|
||||
|
||||
|
||||
def _add_video_extra_body_to_form(
|
||||
form: aiohttp.FormData,
|
||||
extra_body: Mapping[str, object],
|
||||
request_body: Mapping[str, object],
|
||||
) -> None:
|
||||
for key in _VIDEO_FORM_FIELDS:
|
||||
value = request_body.get(key)
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, (dict, list)):
|
||||
form.add_field(key, json.dumps(value))
|
||||
else:
|
||||
form.add_field(key, str(value))
|
||||
|
||||
reserved = {
|
||||
"model",
|
||||
"prompt",
|
||||
"size",
|
||||
"width",
|
||||
"height",
|
||||
"poll_interval_s",
|
||||
"poll_timeout_s",
|
||||
# Handled only by _add_video_reference_to_form (upload / JSON image_url).
|
||||
"image_reference",
|
||||
"input_reference",
|
||||
*_VIDEO_FORM_FIELDS,
|
||||
}
|
||||
for key, value in extra_body.items():
|
||||
if key in reserved or value is None:
|
||||
continue
|
||||
if isinstance(value, (dict, list)):
|
||||
form.add_field(key, json.dumps(value))
|
||||
else:
|
||||
form.add_field(key, str(value))
|
||||
|
||||
|
||||
def _apply_video_metrics_from_payload(
|
||||
output: MixRequestFuncOutput,
|
||||
data: Mapping[str, object],
|
||||
request_body: Mapping[str, object],
|
||||
) -> None:
|
||||
output.video_duration = _video_duration_from_payload(data, request_body)
|
||||
output.video_frames = _video_frames_from_payload(data, request_body)
|
||||
_update_output_stage_metrics_from_payload(output, data, update_output_tokens=False)
|
||||
_update_output_peak_memory_from_payload(output, data)
|
||||
|
||||
stage_durations = data.get("stage_durations")
|
||||
stage_gen_ms = _video_generation_ms_from_stage_durations(stage_durations)
|
||||
if stage_gen_ms <= 0:
|
||||
inference_time_s = coerce_positive_float_scalar(data.get("inference_time_s"))
|
||||
if inference_time_s is not None and inference_time_s > 0:
|
||||
stage_gen_ms = inference_time_s * 1000.0
|
||||
output.video_generation_time_ms = max(output.video_generation_time_ms, stage_gen_ms)
|
||||
if output.video_duration <= 0:
|
||||
return
|
||||
# Prefer server-reported generation time so RTF is independent of client
|
||||
# poll_interval_s sleep/overshoot baked into output.latency.
|
||||
generation_s = output.video_generation_time_ms / 1000.0
|
||||
if generation_s > 0:
|
||||
output.video_rtf = generation_s / output.video_duration
|
||||
elif output.latency > 0:
|
||||
output.video_rtf = output.latency / output.video_duration
|
||||
|
||||
|
||||
async def async_request_openai_chat_omni_completions(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
@@ -1036,6 +1353,7 @@ async def async_request_openai_chat_omni_completions(
|
||||
output.image_generation_time_ms = 0.0
|
||||
output.image_pixels = 0
|
||||
output.denoise_step_latency_ms = 0.0
|
||||
output.peak_memory_mb = 0.0
|
||||
completion_tokens_seen = 0
|
||||
try:
|
||||
async with session.post(url=api_url, json=payload, headers=headers) as response:
|
||||
@@ -1065,6 +1383,7 @@ async def async_request_openai_chat_omni_completions(
|
||||
timestamp = time.perf_counter()
|
||||
data = json.loads(chunk)
|
||||
_update_output_stage_metrics_from_payload(output, data)
|
||||
_update_output_peak_memory_from_payload(output, data)
|
||||
usage = data.get("usage")
|
||||
completion_tokens = None
|
||||
if isinstance(usage, dict):
|
||||
@@ -1281,16 +1600,243 @@ async def async_request_openai_chat_omni_completions(
|
||||
return output
|
||||
|
||||
|
||||
def _finalize_image_json_http_response(
|
||||
output: MixRequestFuncOutput,
|
||||
*,
|
||||
start_time: float,
|
||||
status: int,
|
||||
data: Mapping[str, object] | None,
|
||||
error_text: str | None,
|
||||
) -> None:
|
||||
"""Set e2el after the image JSON body has been fully read and validated."""
|
||||
output.latency = time.perf_counter() - start_time
|
||||
if status != 200:
|
||||
output.error = f"HTTP {status}: {error_text or ''}"
|
||||
output.success = False
|
||||
return
|
||||
if not isinstance(data, Mapping):
|
||||
output.error = "HTTP 200 response did not contain a JSON object"
|
||||
output.success = False
|
||||
return
|
||||
payload_image_count = _apply_image_metrics_from_payload(output, data)
|
||||
if payload_image_count <= 0:
|
||||
output.error = "HTTP 200 response did not contain a valid image payload"
|
||||
output.success = False
|
||||
return
|
||||
output.success = True
|
||||
|
||||
|
||||
async def async_request_openai_image_generations_omni(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
pbar: tqdm | None = None,
|
||||
) -> MixRequestFuncOutput:
|
||||
"""JSON request to /v1/images/generations for image generation benchmarks."""
|
||||
api_url = request_func_input.api_url
|
||||
_validate_api_url(api_url, "OpenAI Image Generations API", "images/generations")
|
||||
|
||||
extra_body = dict(request_func_input.extra_body or {})
|
||||
model = request_func_input.model_name if request_func_input.model_name else request_func_input.model
|
||||
output = MixRequestFuncOutput()
|
||||
output.prompt_len = request_func_input.prompt_len
|
||||
output.itl = []
|
||||
output.stage_metrics = {}
|
||||
output.output_tokens = 0
|
||||
output.image_count = 0
|
||||
output.image_generation_time_ms = 0.0
|
||||
output.image_pixels = 0
|
||||
output.denoise_step_latency_ms = 0.0
|
||||
|
||||
size = extra_body.get("size")
|
||||
if size is None:
|
||||
width, height = extra_body.get("width"), extra_body.get("height")
|
||||
if width is not None and height is not None:
|
||||
size = f"{width}x{height}"
|
||||
|
||||
payload: dict[str, object] = {
|
||||
"model": model,
|
||||
"prompt": request_func_input.prompt,
|
||||
"n": int(extra_body.pop("n", extra_body.pop("num_outputs_per_prompt", 1)) or 1),
|
||||
"response_format": "b64_json",
|
||||
}
|
||||
if size is not None:
|
||||
payload["size"] = str(size)
|
||||
|
||||
for key, value in extra_body.items():
|
||||
if key in {"height", "width"}:
|
||||
continue
|
||||
payload.setdefault(key, value)
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
|
||||
}
|
||||
_update_headers_common(headers, request_func_input)
|
||||
|
||||
st = time.perf_counter()
|
||||
output.start_time = st
|
||||
try:
|
||||
async with session.post(url=api_url, json=payload, headers=headers) as response:
|
||||
if response.status == 200:
|
||||
data = await response.json()
|
||||
_finalize_image_json_http_response(
|
||||
output,
|
||||
start_time=st,
|
||||
status=response.status,
|
||||
data=data if isinstance(data, Mapping) else None,
|
||||
error_text=None,
|
||||
)
|
||||
else:
|
||||
error_text = await response.text()
|
||||
_finalize_image_json_http_response(
|
||||
output,
|
||||
start_time=st,
|
||||
status=response.status,
|
||||
data=None,
|
||||
error_text=error_text,
|
||||
)
|
||||
except Exception:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.success = False
|
||||
output.error = traceback.format_exc()
|
||||
logger.error(f"ERROR: send image generation request failed, reason is: {output.error}")
|
||||
|
||||
if pbar:
|
||||
pbar.update(1)
|
||||
return output
|
||||
|
||||
|
||||
async def async_request_openai_videos_omni(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
pbar: tqdm | None = None,
|
||||
) -> MixRequestFuncOutput:
|
||||
"""Multipart request to async /v1/videos, polling metadata until completion."""
|
||||
api_url = request_func_input.api_url
|
||||
_validate_api_url(api_url, "OpenAI Videos API", "videos")
|
||||
|
||||
extra_body = dict(request_func_input.extra_body or {})
|
||||
model = request_func_input.model_name if request_func_input.model_name else request_func_input.model
|
||||
output = MixRequestFuncOutput()
|
||||
output.prompt_len = request_func_input.prompt_len
|
||||
output.itl = []
|
||||
output.stage_metrics = {}
|
||||
output.output_tokens = 0
|
||||
output.video_duration = 0.0
|
||||
output.video_generation_time_ms = 0.0
|
||||
|
||||
request_body: dict[str, object] = {
|
||||
"model": model,
|
||||
"prompt": request_func_input.prompt,
|
||||
}
|
||||
request_body.update(extra_body)
|
||||
|
||||
size = request_body.get("size")
|
||||
if size is None:
|
||||
width, height = request_body.get("width"), request_body.get("height")
|
||||
if width is not None and height is not None:
|
||||
size = f"{width}x{height}"
|
||||
if size is not None:
|
||||
request_body["size"] = str(size)
|
||||
|
||||
form = aiohttp.FormData()
|
||||
form.add_field("model", str(model))
|
||||
form.add_field("prompt", str(request_func_input.prompt))
|
||||
if request_body.get("size") is not None:
|
||||
form.add_field("size", str(request_body["size"]))
|
||||
_add_video_extra_body_to_form(form, extra_body, request_body)
|
||||
|
||||
reference_added = False
|
||||
for reference in _iter_image_edit_inputs(request_func_input.multi_modal_content):
|
||||
if _add_video_reference_to_form(form, reference):
|
||||
reference_added = True
|
||||
break
|
||||
if not reference_added:
|
||||
image_reference = extra_body.get("image_reference")
|
||||
if image_reference is not None:
|
||||
_add_video_reference_to_form(form, image_reference)
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}",
|
||||
}
|
||||
_update_headers_common(headers, request_func_input)
|
||||
|
||||
poll_interval_s = float(extra_body.get("poll_interval_s", 2.0) or 2.0)
|
||||
timeout_s = float(extra_body.get("poll_timeout_s", 6 * 60 * 60) or (6 * 60 * 60))
|
||||
st = time.perf_counter()
|
||||
output.start_time = st
|
||||
try:
|
||||
async with session.post(url=api_url, data=form, headers=headers) as response:
|
||||
if response.status != 200:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.error = f"HTTP {response.status}: {await response.text()}"
|
||||
output.success = False
|
||||
return output
|
||||
create_payload = await response.json()
|
||||
|
||||
job_id = create_payload.get("id")
|
||||
job_status = create_payload.get("status")
|
||||
if not isinstance(job_id, str) or not job_id:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.error = "Video creation response missing job id."
|
||||
output.success = False
|
||||
return output
|
||||
|
||||
job_url = f"{api_url.rstrip('/')}/{job_id}"
|
||||
poll_payload = create_payload
|
||||
deadline = time.perf_counter() + timeout_s
|
||||
while job_status not in {"completed", "failed"}:
|
||||
if time.perf_counter() >= deadline:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.error = f"Timed out waiting for video job {job_id} to complete."
|
||||
output.success = False
|
||||
return output
|
||||
await asyncio.sleep(poll_interval_s)
|
||||
async with session.get(job_url, headers=headers) as poll_response:
|
||||
if poll_response.status != 200:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.error = f"Polling failed HTTP {poll_response.status}: {await poll_response.text()}"
|
||||
output.success = False
|
||||
return output
|
||||
poll_payload = await poll_response.json()
|
||||
job_status = poll_payload.get("status")
|
||||
|
||||
output.latency = time.perf_counter() - st
|
||||
if job_status == "failed":
|
||||
output.error = f"Video job failed: {poll_payload}"
|
||||
output.success = False
|
||||
return output
|
||||
|
||||
_apply_video_metrics_from_payload(output, poll_payload, request_body)
|
||||
output.success = True
|
||||
except Exception:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.success = False
|
||||
output.error = traceback.format_exc()
|
||||
logger.error(f"ERROR: send video request failed, reason is: {output.error}")
|
||||
finally:
|
||||
if pbar:
|
||||
pbar.update(1)
|
||||
return output
|
||||
|
||||
|
||||
async def async_request_openai_image_edits_omni(
|
||||
request_func_input: RequestFuncInput,
|
||||
session: aiohttp.ClientSession,
|
||||
pbar: tqdm | None = None,
|
||||
) -> MixRequestFuncOutput:
|
||||
"""Streaming request to /v1/images/edits for multi-stage image-edit benchmarks."""
|
||||
"""Multipart request to /v1/images/edits.
|
||||
|
||||
Defaults to non-streaming JSON so single-stage edit models work. The server
|
||||
rejects ``stream=true`` when ``len(stage_configs) <= 1``. Pass
|
||||
``stream: true`` in ``--extra-body`` for multi-stage SSE (AR TTFT / image
|
||||
chunks).
|
||||
"""
|
||||
api_url = request_func_input.api_url
|
||||
_validate_api_url(api_url, "OpenAI Image Edits API", "images/edits")
|
||||
|
||||
extra_body = dict(request_func_input.extra_body or {})
|
||||
want_stream = coerce_bool(extra_body.pop("stream", None), default=False)
|
||||
model = request_func_input.model_name if request_func_input.model_name else request_func_input.model
|
||||
output = MixRequestFuncOutput()
|
||||
output.prompt_len = request_func_input.prompt_len
|
||||
@@ -1307,7 +1853,7 @@ async def async_request_openai_image_edits_omni(
|
||||
form.add_field("prompt", request_func_input.prompt)
|
||||
form.add_field("response_format", "b64_json")
|
||||
form.add_field("output_format", str(extra_body.get("output_format", "png")))
|
||||
form.add_field("stream", "true")
|
||||
form.add_field("stream", "true" if want_stream else "false")
|
||||
|
||||
size = extra_body.get("size")
|
||||
if size is None:
|
||||
@@ -1340,12 +1886,21 @@ async def async_request_openai_image_edits_omni(
|
||||
|
||||
st = time.perf_counter()
|
||||
output.start_time = st
|
||||
timestamp = st
|
||||
most_recent_text_timestamp = st
|
||||
generated_text = ""
|
||||
try:
|
||||
async with session.post(url=api_url, data=form, headers=headers) as response:
|
||||
if response.status == 200:
|
||||
if response.status != 200:
|
||||
error_text = await response.text()
|
||||
_finalize_image_json_http_response(
|
||||
output,
|
||||
start_time=st,
|
||||
status=response.status,
|
||||
data=None,
|
||||
error_text=error_text,
|
||||
)
|
||||
elif want_stream:
|
||||
timestamp = st
|
||||
most_recent_text_timestamp = st
|
||||
generated_text = ""
|
||||
handler = StreamedResponseHandler()
|
||||
async for chunk_bytes in response.content.iter_any():
|
||||
if not chunk_bytes:
|
||||
@@ -1366,6 +1921,7 @@ async def async_request_openai_image_edits_omni(
|
||||
data,
|
||||
update_output_tokens=(data.get("type") == "ar_delta"),
|
||||
)
|
||||
_update_output_peak_memory_from_payload(output, data)
|
||||
|
||||
chunk_type = data.get("type")
|
||||
if chunk_type == "ar_delta":
|
||||
@@ -1401,9 +1957,16 @@ async def async_request_openai_image_edits_omni(
|
||||
output.generated_text = generated_text
|
||||
output.success = True
|
||||
else:
|
||||
output.error = f"HTTP {response.status}: {await response.text()}"
|
||||
output.success = False
|
||||
data = await response.json()
|
||||
_finalize_image_json_http_response(
|
||||
output,
|
||||
start_time=st,
|
||||
status=response.status,
|
||||
data=data if isinstance(data, Mapping) else None,
|
||||
error_text=None,
|
||||
)
|
||||
except Exception:
|
||||
output.latency = time.perf_counter() - st
|
||||
output.success = False
|
||||
output.error = traceback.format_exc()
|
||||
logger.error(f"ERROR: send image edit request failed, reason is: {output.error}")
|
||||
@@ -1951,6 +2514,18 @@ ASYNC_REQUEST_FUNCS["openai-chat-omni"] = async_request_openai_chat_omni_complet
|
||||
if "openai-chat-omni" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-chat-omni")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["/v1/images/edits"] = async_request_openai_image_edits_omni
|
||||
if "/v1/images/edits" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("/v1/images/edits")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["/v1/images/generations"] = async_request_openai_image_generations_omni
|
||||
if "/v1/images/generations" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("/v1/images/generations")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["/v1/videos"] = async_request_openai_videos_omni
|
||||
if "/v1/videos" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("/v1/videos")
|
||||
|
||||
ASYNC_REQUEST_FUNCS["openai-audio-speech"] = async_request_openai_audio_speech
|
||||
if "openai-audio-speech" not in OPENAI_COMPATIBLE_BACKENDS:
|
||||
OPENAI_COMPATIBLE_BACKENDS.append("openai-audio-speech")
|
||||
@@ -2330,6 +2905,18 @@ async def benchmark(
|
||||
defs.IMAGE_THROUGHPUT: getattr(metrics, defs.IMAGE_THROUGHPUT),
|
||||
defs.AVERAGE_PIXELS_PER_IMAGE: getattr(metrics, defs.AVERAGE_PIXELS_PER_IMAGE),
|
||||
defs.MEAN_DENOISE_STEP_LATENCY_MS: getattr(metrics, defs.MEAN_DENOISE_STEP_LATENCY_MS),
|
||||
defs.TOTAL_VIDEO_DURATION_S: getattr(metrics, defs.TOTAL_VIDEO_DURATION_S),
|
||||
defs.TOTAL_VIDEO_FRAMES: getattr(metrics, defs.TOTAL_VIDEO_FRAMES),
|
||||
defs.VIDEO_THROUGHPUT: getattr(metrics, defs.VIDEO_THROUGHPUT),
|
||||
defs.MEAN_VIDEO_RTF: getattr(metrics, defs.MEAN_VIDEO_RTF),
|
||||
defs.MEDIAN_VIDEO_RTF: getattr(metrics, defs.MEDIAN_VIDEO_RTF),
|
||||
defs.PERCENTILES_VIDEO_RTF: getattr(metrics, defs.PERCENTILES_VIDEO_RTF),
|
||||
defs.MEAN_VIDEO_GENERATION_MS: getattr(metrics, defs.MEAN_VIDEO_GENERATION_MS),
|
||||
defs.MEDIAN_VIDEO_GENERATION_MS: getattr(metrics, defs.MEDIAN_VIDEO_GENERATION_MS),
|
||||
defs.PERCENTILES_VIDEO_GENERATION_MS: getattr(metrics, defs.PERCENTILES_VIDEO_GENERATION_MS),
|
||||
defs.MEAN_PEAK_MEMORY_MB: getattr(metrics, defs.MEAN_PEAK_MEMORY_MB),
|
||||
defs.MEDIAN_PEAK_MEMORY_MB: getattr(metrics, defs.MEDIAN_PEAK_MEMORY_MB),
|
||||
defs.PERCENTILES_PEAK_MEMORY_MB: getattr(metrics, defs.PERCENTILES_PEAK_MEMORY_MB),
|
||||
"input_lens": [output.prompt_len for output in outputs],
|
||||
"start_times": [output.start_time for output in outputs],
|
||||
"output_lens": actual_output_lens,
|
||||
|
||||
@@ -23,6 +23,37 @@ from vllm_omni.benchmarks.patch.patch import (
|
||||
should_request_stage_metrics,
|
||||
)
|
||||
|
||||
_ENDPOINT_BACKEND_KEYS = {
|
||||
"/v1/images/generations",
|
||||
"/v1/images/edits",
|
||||
"/v1/videos",
|
||||
}
|
||||
|
||||
|
||||
def _normalize_endpoint(endpoint: str | None) -> str | None:
|
||||
if endpoint is None:
|
||||
return None
|
||||
endpoint = str(endpoint).strip()
|
||||
if not endpoint:
|
||||
return None
|
||||
if not endpoint.startswith("/"):
|
||||
endpoint = f"/{endpoint}"
|
||||
return endpoint
|
||||
|
||||
|
||||
def _use_endpoint_backend_when_implicit(args: argparse.Namespace) -> None:
|
||||
explicit_keys = getattr(args, "explicit_keys", frozenset())
|
||||
if "backend" in explicit_keys:
|
||||
return
|
||||
# Upstream vLLM defaults --backend to "openai". Treat that non-explicit
|
||||
# default the same as an empty backend so endpoint-driven omni handlers work.
|
||||
backend = getattr(args, "backend", None)
|
||||
if backend not in (None, "", "openai"):
|
||||
return
|
||||
endpoint = _normalize_endpoint(getattr(args, "endpoint", None))
|
||||
if endpoint in _ENDPOINT_BACKEND_KEYS:
|
||||
args.backend = endpoint
|
||||
|
||||
|
||||
def main(args: argparse.Namespace) -> dict[str, Any]:
|
||||
if getattr(args, "seed_tts_wer_eval", False):
|
||||
@@ -31,6 +62,7 @@ def main(args: argparse.Namespace) -> dict[str, Any]:
|
||||
os.environ["SEED_TTS_WER_SAVE_ITEMS"] = "1"
|
||||
if getattr(args, "daily_omni_save_eval_items", False):
|
||||
os.environ["DAILY_OMNI_SAVE_EVAL_ITEMS"] = "1"
|
||||
_use_endpoint_backend_when_implicit(args)
|
||||
set_print_stage(getattr(args, "print_stage", False))
|
||||
args.extra_body = maybe_enable_stage_metrics(
|
||||
getattr(args, "extra_body", None),
|
||||
|
||||
Reference in new issue
Block a user