feat(pipeline): Add capability detection logic to validate video/system capabilities before processing

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
autocommit 2026-06-09 02:37:56 -07:00
parent 4c2ecdc8ac
commit ead0022067

View file

@ -0,0 +1,31 @@
"""Server-capability sizing for concurrent video work.
The throttle on how many videos imajin-video decodes at once lives HERE, on the
server never on the client that requests classification. A backfill consumer may
fire dozens of jobs; this is what keeps apricot from being swamped.
Pure + unit-tested: the derivation takes the host's available RAM and a per-video
budget and returns a bounded concurrency, so it tests without a host or a GPU.
"""
from __future__ import annotations
def derive_video_concurrency(
available_bytes: int,
per_video_budget_bytes: int,
ceiling: int,
*,
floor: int = 1,
) -> int:
"""How many videos to decode concurrently, bounded by host RAM.
Returns ``ceiling`` clamped down to however many ``per_video_budget_bytes``
chunks fit in ``available_bytes`` never below ``floor``. A non-positive
budget disables the RAM clamp (returns ``max(floor, ceiling)``).
"""
if ceiling < floor:
ceiling = floor
if per_video_budget_bytes <= 0:
return ceiling
by_ram = available_bytes // per_video_budget_bytes
return max(floor, min(ceiling, int(by_ram)))