@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 18b1c77211
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 5, 04:45 UTC

fix: handle ImportError in load_audio (#39473)

Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Yiyang "Ian" Liu committed Apr 14, 2026 at 04:09 UTC 18b1c77211d8f6fe800bcfb89524d2b598708032
1 file changed +19 -8
vllm/multimodal/media/audio.py
+19 -8
@@ -9,11 +9,14 @@ import numpy.typing as npt
9 import pybase64
10 import torch
11
12 +from vllm.logger import init_logger
13 from vllm.utils.import_utils import PlaceholderModule
14 from vllm.utils.serial_utils import tensor2base64
15
16 from .base import MediaIO
17
18 +logger = init_logger(__name__)
19 +
20 try:
21 import av
22 except ImportError:
@@ -139,19 +142,27 @@ def load_audio(
142 ):
143 try:
144 return load_audio_soundfile(path, sr=sr, mono=mono)
145 + except ImportError as exc:
146 + # soundfile (or resampy) is not installed — fall through to pyav.
147 + # NOTE: this clause must stay BEFORE ``soundfile.LibsndfileError``
148 + # because when soundfile is a PlaceholderModule, evaluating
149 + # ``soundfile.LibsndfileError`` itself raises ImportError.
150 + logger.error("Failed to load audio via soundfile: %r", exc)
151 except soundfile.LibsndfileError as exc:
152 # Only fall back for known format-detection failures.
153 # Re-raise anything else (e.g. corrupt but recognised format).
154 if exc.code not in _BAD_SF_CODES:
155 raise
147 - # soundfile may have advanced the BytesIO seek position before failing;
148 - # reset it so PyAV can read from the beginning.
149 - if isinstance(path, BytesIO):
150 - path.seek(0)
151 - try:
152 - return load_audio_pyav(path, sr=sr, mono=mono)
153 - except Exception as pyav_exc:
154 - raise ValueError("Invalid or unsupported audio file.") from pyav_exc
156 + # soundfile may have advanced the BytesIO seek position before failing;
157 + # reset it so PyAV can read from the beginning.
158 + if isinstance(path, BytesIO):
159 + path.seek(0)
160 + try:
161 + return load_audio_pyav(path, sr=sr, mono=mono)
162 + except ImportError:
163 + raise # Let PlaceholderModule's message ("install vllm[audio]") propagate.
164 + except Exception as pyav_exc:
165 + raise ValueError("Invalid or unsupported audio file.") from pyav_exc
166
167
168 class AudioMediaIO(MediaIO[tuple[npt.NDArray, float]]):