[multimodal] Make PyNvVideoCodec decoder concurrency configurable (#49753)
Signed-off-by: Brandon Pelfrey <bpelfrey@nvidia.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
0ba2aa35a8
commit
94682b79f4
@@ -16,7 +16,6 @@ from transformers.video_utils import VideoMetadata
|
||||
from vllm.assets.base import get_vllm_public_assets
|
||||
from vllm.multimodal.video import (
|
||||
PYNVVIDEOCODEC_DECODER_CACHE_SIZE,
|
||||
PYNVVIDEOCODEC_MAX_RETAINED_DECODERS,
|
||||
PYNVVIDEOCODEC_VIDEO_BACKEND,
|
||||
VIDEO_LOADER_REGISTRY,
|
||||
DynamicVideoBackend,
|
||||
@@ -26,6 +25,7 @@ from vllm.multimodal.video import (
|
||||
PyNvVideoCodecVideoBackend,
|
||||
Qwen2VLVideoBackend,
|
||||
Qwen3VLVideoBackend,
|
||||
VideoBackend,
|
||||
VideoLoader,
|
||||
VideoSourceMetadata,
|
||||
VideoTargetMetadata,
|
||||
@@ -199,7 +199,11 @@ def test_pynvvideocodec_codec_uses_dynamic_sampling_strategy(
|
||||
assert metadata["frames_indices"] == [0, 9]
|
||||
|
||||
|
||||
def test_pynvvideocodec_decoder_slots_are_bounded(monkeypatch: pytest.MonkeyPatch):
|
||||
@pytest.mark.parametrize("hw_decoders", [1, 3])
|
||||
def test_pynvvideocodec_decoder_slots_are_bounded(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
hw_decoders: int,
|
||||
):
|
||||
class FakeSlot:
|
||||
pass
|
||||
|
||||
@@ -207,10 +211,13 @@ def test_pynvvideocodec_decoder_slots_are_bounded(monkeypatch: pytest.MonkeyPatc
|
||||
old_slots = PyNvVideoCodecVideoBackend._decoder_slots
|
||||
old_active_slots = PyNvVideoCodecVideoBackend._active_decoder_slots
|
||||
old_cond = PyNvVideoCodecVideoBackend._decoder_slot_cond
|
||||
old_max_slots = PyNvVideoCodecVideoBackend._max_decoder_slots
|
||||
try:
|
||||
PyNvVideoCodecVideoBackend._decoder_slots = []
|
||||
PyNvVideoCodecVideoBackend._active_decoder_slots = 0
|
||||
PyNvVideoCodecVideoBackend._decoder_slot_cond = threading.Condition()
|
||||
PyNvVideoCodecVideoBackend._max_decoder_slots = None
|
||||
PyNvVideoCodecVideoBackend._configure_decoder_slots(hw_decoders)
|
||||
|
||||
def fake_create_slot(cls):
|
||||
nonlocal create_count
|
||||
@@ -229,7 +236,7 @@ def test_pynvvideocodec_decoder_slots_are_bounded(monkeypatch: pytest.MonkeyPatc
|
||||
with ExitStack() as stack:
|
||||
retained_slots = [
|
||||
stack.enter_context(PyNvVideoCodecVideoBackend._borrow_decoder_slot())
|
||||
for _ in range(PYNVVIDEOCODEC_MAX_RETAINED_DECODERS)
|
||||
for _ in range(hw_decoders)
|
||||
]
|
||||
|
||||
def borrow_extra_slot():
|
||||
@@ -246,11 +253,34 @@ def test_pynvvideocodec_decoder_slots_are_bounded(monkeypatch: pytest.MonkeyPatc
|
||||
assert not thread.is_alive()
|
||||
|
||||
assert seen_slots[0] in retained_slots
|
||||
assert create_count == PYNVVIDEOCODEC_MAX_RETAINED_DECODERS
|
||||
assert create_count == hw_decoders
|
||||
finally:
|
||||
PyNvVideoCodecVideoBackend._decoder_slots = old_slots
|
||||
PyNvVideoCodecVideoBackend._active_decoder_slots = old_active_slots
|
||||
PyNvVideoCodecVideoBackend._decoder_slot_cond = old_cond
|
||||
PyNvVideoCodecVideoBackend._max_decoder_slots = old_max_slots
|
||||
|
||||
|
||||
def test_pynvvideocodec_decoder_slots_are_configured_once(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
monkeypatch.setattr(PyNvVideoCodecVideoBackend, "_max_decoder_slots", None)
|
||||
|
||||
PyNvVideoCodecVideoBackend._configure_decoder_slots(2)
|
||||
PyNvVideoCodecVideoBackend._configure_decoder_slots(2)
|
||||
|
||||
with pytest.raises(RuntimeError, match="already configured as 2, got 3"):
|
||||
PyNvVideoCodecVideoBackend._configure_decoder_slots(3)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("hw_decoders", [0, -1, 1.5, True, "2"])
|
||||
def test_pynvvideocodec_rejects_invalid_hw_decoders(hw_decoders: object):
|
||||
with pytest.raises(ValueError, match="hw_decoders must be a positive integer"):
|
||||
VideoBackend.load_bytes(
|
||||
b"fake video",
|
||||
backend=PYNVVIDEOCODEC_VIDEO_BACKEND,
|
||||
hw_decoders=hw_decoders, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
|
||||
def test_pynvvideocodec_decoder_slot_retains_simple_decoder():
|
||||
|
||||
Reference in New Issue
Block a user