[Frontend] Add omni benchmark support for image and video endpoints (#4728)

This commit is contained in:
ZacheryAU authored and GitHub committed 2026-09-08 09:28:21 +08:00
1 parent e1c59edec6
commit b1ec136bd7
21 files changed
+1626 -72

No files matched your search

+83
View File
@@ -163,6 +163,24 @@ def extract_diffusion_denoise_ms(output: Any) -> float | None:
return sum_diffusion_stage_durations_ms(output, ".diffuse")
def coerce_bool(value: object, *, default: bool = False) -> bool:
"""Coerce JSON / form / env-like values to bool.
Accepts ``bool``, numeric 0/1, and common truthy strings
(``\"1\"`` / ``\"true\"`` / ``\"yes\"`` / ``\"on\"``, case-insensitive).
``None`` and unrecognized types return ``default``.
"""
if value is None:
return default
if isinstance(value, bool):
return value
if isinstance(value, (int, float)):
return bool(value)
if isinstance(value, str):
return value.strip().lower() in {"1", "true", "yes", "on"}
return default
def coerce_positive_int_scalar(value: object) -> int | None:
"""Coerce a value to a positive int without importing tensor libs.
@@ -199,6 +217,34 @@ def coerce_positive_int_scalar(value: object) -> int | None:
return value if value > 0 else None
def coerce_positive_float_scalar(value: object) -> float | None:
"""Coerce a scalar-like value to a positive float.
Handles plain numeric values, one-element tensor/numpy-like values via
``.item()``, and list/tuple wrappers. Returns ``None`` when no positive
float can be extracted.
"""
if value is None:
return None
if isinstance(value, (list, tuple)):
for item in value:
coerced = coerce_positive_float_scalar(item)
if coerced is not None:
return coerced
return None
item = getattr(value, "item", None)
if callable(item):
try:
value = item()
except Exception:
return None
try:
value = float(value)
except (TypeError, ValueError):
return None
return value if value > 0 else None
def resolve_int_by_sequential_keys(
source: Mapping[str, object] | object | None,
keys: Sequence[str],
@@ -370,6 +416,43 @@ def count_image_pixels(value: object) -> int:
return dims[-2] * dims[-1]
def count_video_frames(video: object) -> int | None:
"""Return the frame count for common nested and tensor video layouts."""
if isinstance(video, Mapping):
for key in ("video", "frames", "images"):
if key in video:
return count_video_frames(video[key])
return None
if isinstance(video, (list, tuple)):
return len(video)
shape = getattr(video, "shape", None)
if shape is None:
return None
try:
dims = tuple(int(dim) for dim in shape)
except (TypeError, ValueError):
return None
if len(dims) == 5:
# Common layouts: [B, C, F, H, W] and [B, F, H, W, C].
if dims[-1] in (1, 3, 4):
return dims[1]
if dims[1] in (1, 3, 4):
return dims[2]
return dims[1]
if len(dims) == 4:
# Common layouts: [F, H, W, C] and [C, F, H, W].
if dims[-1] in (1, 3, 4):
return dims[0]
if dims[0] in (1, 3, 4):
return dims[1]
return dims[0]
return None
def _build_field_defs(
cls: type,
exclude: set[str],