[Multimodal] Use GPU NVDEC for EPD encoder-only instance video media IO (#53675)
Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
@@ -1736,6 +1736,7 @@ class VllmConfig:
|
||||
|
||||
self._resolve_mm_embedding_inputs()
|
||||
self._resolve_mm_processor_device()
|
||||
self._resolve_mm_video_decode_device()
|
||||
self._validate_mm_processor_device()
|
||||
|
||||
if self.use_v2_model_runner:
|
||||
@@ -2623,6 +2624,61 @@ class VllmConfig:
|
||||
device_type,
|
||||
)
|
||||
|
||||
def _resolve_mm_video_decode_device(self) -> None:
|
||||
"""Default video decoding to torchcodec GPU backend for EPD encoder-only
|
||||
instance if the mm processor runs on CUDA.
|
||||
|
||||
The processor consumes the decoded frames on-device in that case, so
|
||||
keeping the frames on the GPU skips the host round-trip through the
|
||||
CPU media path. An explicit codec/backend choice in
|
||||
`--media-io-kwargs` is left alone, and the default is skipped where
|
||||
torchcodec (or its FFmpeg runtime) is unavailable.
|
||||
"""
|
||||
if self.model_config is None or self.model_config.multimodal_config is None:
|
||||
return
|
||||
mm_config = self.model_config.multimodal_config
|
||||
|
||||
ec_config = self.ec_transfer_config
|
||||
# An EC producer that is not also a consumer runs no forward pass and
|
||||
# allocates no KV cache, so frontend accelerator work has the device to
|
||||
# itself.
|
||||
if ec_config is None or not ec_config.is_encode_only:
|
||||
return
|
||||
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
device_type = current_platform.device_type
|
||||
if (
|
||||
device_type != "cuda"
|
||||
or mm_config.get_mm_processor_device_type() != device_type
|
||||
):
|
||||
return
|
||||
|
||||
# User set video backend or device explicitly
|
||||
video_kwargs = mm_config.media_io_kwargs.setdefault("video", {})
|
||||
if "backend" in video_kwargs or "device" in video_kwargs:
|
||||
return
|
||||
|
||||
from vllm.utils.import_utils import check_torchcodec_available
|
||||
|
||||
try:
|
||||
check_torchcodec_available()
|
||||
except (ImportError, RuntimeError):
|
||||
# torchcodec is not installed, or is installed without a usable
|
||||
# FFmpeg runtime (it raises rather than returning False).
|
||||
logger.info_once(
|
||||
"EPD encoder instance: keeping CPU video decoding because "
|
||||
"torchcodec is not available (needs a CUDA build with FFmpeg)."
|
||||
)
|
||||
return
|
||||
|
||||
video_kwargs["backend"] = "torchcodec"
|
||||
video_kwargs["device"] = device_type
|
||||
logger.info_once(
|
||||
"EPD encoder instance: decoding video with NVDEC (torchcodec device=%s).",
|
||||
device_type,
|
||||
)
|
||||
|
||||
def _validate_mm_processor_device(self) -> None:
|
||||
"""Hand the EC config to `MultiModalConfig`, which owns the rule."""
|
||||
model_config = self.model_config
|
||||
|
||||
Reference in New Issue
Block a user