[Bugfix] Avoid blocking model launching when no system ffmpeg available for TorchCodec (#47888)

Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
Isotr0py
2026-07-08 10:52:25 +08:00
committed by GitHub
parent f7fc0ca993
commit 5e975eae1a
2 changed files with 21 additions and 2 deletions
+3 -2
View File
@@ -15,7 +15,7 @@ import torch
from vllm import envs
from vllm.logger import init_logger
from vllm.utils.import_utils import PlaceholderModule
from vllm.utils.import_utils import PlaceholderModule, check_torchcodec_available
from vllm.utils.mem_constants import MiB_bytes
from vllm.utils.registry import ExtensionManager
@@ -33,7 +33,7 @@ except ImportError:
try:
from torchcodec.decoders import VideoDecoder
except ImportError:
except (ImportError, RuntimeError):
VideoDecoder = PlaceholderModule("torchcodec").placeholder_attr( # type: ignore[assignment]
"decoders.VideoDecoder"
)
@@ -956,6 +956,7 @@ class VideoBackend(
assert not frame_recovery, (
"frame_recovery is only available for `opencv` backend"
)
check_torchcodec_available()
decoder = cls.make_torchcodec_decoder(
data,
num_ffmpeg_threads=num_ffmpeg_threads,
+18
View File
@@ -552,3 +552,21 @@ def has_cutedsl() -> bool:
def has_humming() -> bool:
"""Whether the optional `humming` package is available."""
return _has_module("humming")
def check_torchcodec_available():
"""Whether the optional `torchcodec` package is available."""
try:
import torchcodec # noqa: F401
except RuntimeError as e:
# torchcodec will raise RuntimeError during import instead
# of ImportError when system ffmpeg unavailable, with a
# message that can leak sensitive system information.
# Trim it down to avoid it.
marker = (
"The following exceptions were raised as we tried to load libtorchcodec:"
)
message = str(e)
if marker in message:
raise RuntimeError(message.split(marker, 1)[0].rstrip()) from None
raise e