[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
@@ -404,6 +404,23 @@ class TestMergeKwargsGpuBackendPolicy:
|
||||
)
|
||||
assert result["backend"] == "pynvvideocodec"
|
||||
|
||||
def test_strips_request_level_hw_decoders_when_not_static(self):
|
||||
result = VideoMediaIO.merge_kwargs(
|
||||
default_kwargs={"video_backend": "pynvvideocodec"},
|
||||
runtime_kwargs={"hw_decoders": 4},
|
||||
)
|
||||
assert "hw_decoders" not in result
|
||||
|
||||
def test_prevents_request_level_hw_decoders_override(self):
|
||||
result = VideoMediaIO.merge_kwargs(
|
||||
default_kwargs={
|
||||
"video_backend": "pynvvideocodec",
|
||||
"hw_decoders": 2,
|
||||
},
|
||||
runtime_kwargs={"hw_decoders": 4},
|
||||
)
|
||||
assert result["hw_decoders"] == 2
|
||||
|
||||
@pytest.mark.parametrize("backend", ["opencv", "pyav", "torchcodec"])
|
||||
def test_software_video_backend_passes_through(self, backend: str):
|
||||
result = VideoMediaIO.merge_kwargs(
|
||||
|
||||
@@ -18,7 +18,6 @@ from vllm.multimodal.gpu_ipc_memory import (
|
||||
from vllm.multimodal.video import (
|
||||
PYNVVIDEOCODEC_CUDA_CONTEXT_BYTES,
|
||||
PYNVVIDEOCODEC_DECODER_GPU_MEMORY_BYTES,
|
||||
PYNVVIDEOCODEC_MAX_RETAINED_DECODERS,
|
||||
PYNVVIDEOCODEC_VIDEO_BACKEND,
|
||||
)
|
||||
from vllm.utils.mem_constants import GiB_bytes
|
||||
@@ -28,17 +27,26 @@ def _mm_config(
|
||||
*,
|
||||
mm_ipc_gpu_memory_gb: float = 0,
|
||||
video_backend: str | None = None,
|
||||
hw_decoders: int | None = None,
|
||||
) -> MultiModalConfig:
|
||||
video_kwargs = {} if video_backend is None else {"video_backend": video_backend}
|
||||
video_kwargs: dict[str, object] = (
|
||||
{} if video_backend is None else {"video_backend": video_backend}
|
||||
)
|
||||
if hw_decoders is not None:
|
||||
video_kwargs["hw_decoders"] = hw_decoders
|
||||
|
||||
return MultiModalConfig(
|
||||
mm_ipc_gpu_memory_gb=mm_ipc_gpu_memory_gb,
|
||||
media_io_kwargs={"video": video_kwargs} if video_kwargs else {},
|
||||
)
|
||||
|
||||
|
||||
def _pynvvideocodec_decoder_budget(api_process_count: int = 1) -> int:
|
||||
def _pynvvideocodec_decoder_budget(
|
||||
api_process_count: int = 1,
|
||||
hw_decoders: int = 2,
|
||||
) -> int:
|
||||
return api_process_count * (
|
||||
PYNVVIDEOCODEC_DECODER_GPU_MEMORY_BYTES * PYNVVIDEOCODEC_MAX_RETAINED_DECODERS
|
||||
PYNVVIDEOCODEC_DECODER_GPU_MEMORY_BYTES * hw_decoders
|
||||
+ PYNVVIDEOCODEC_CUDA_CONTEXT_BYTES
|
||||
)
|
||||
|
||||
@@ -240,3 +248,22 @@ def test_reserve_mm_ipc_gpu_memory_scales_decoder_budget_by_api_servers(
|
||||
_mm_config(),
|
||||
api_process_count=3,
|
||||
) == available_bytes - _pynvvideocodec_decoder_budget(api_process_count=3)
|
||||
|
||||
|
||||
def test_reserve_mm_ipc_gpu_memory_uses_configured_hw_decoders(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
):
|
||||
monkeypatch.setattr(
|
||||
multimodal_config_module.envs,
|
||||
"VLLM_VIDEO_LOADER_BACKEND",
|
||||
"opencv",
|
||||
)
|
||||
available_bytes = 4 * GiB_bytes
|
||||
mm_config = _mm_config(
|
||||
video_backend=PYNVVIDEOCODEC_VIDEO_BACKEND,
|
||||
hw_decoders=3,
|
||||
)
|
||||
|
||||
assert reserve_mm_ipc_gpu_memory(available_bytes, mm_config) == (
|
||||
available_bytes - _pynvvideocodec_decoder_budget(hw_decoders=3)
|
||||
)
|
||||
|
||||
@@ -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