3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 61ecb098d6 Improve error handling and logging for AudioMediaIO compatibility
- Add warnings to inform users which compatibility mode is being used
- Handle both AttributeError and ImportError for better coverage
- Add __init__ method to inherited class for consistency
- Provide clear diagnostic messages when patching fails

Co-authored-by: donglixp <1070872+donglixp@users.noreply.github.com>
2026-01-29 02:24:53 +00:00
copilot-swe-agent[bot] b4cd7c479f Fix vLLM AudioMediaIO compatibility issue
Add try-except blocks to handle both old and new vLLM versions where AudioMediaIO may not exist or may have been moved. This fixes the AttributeError when using newer vLLM versions.

- Handle missing AudioMediaIO by creating standalone implementation
- Add fallback for utils module patching
- Maintain backward compatibility with older vLLM versions

Co-authored-by: donglixp <1070872+donglixp@users.noreply.github.com>
2026-01-29 02:22:47 +00:00
copilot-swe-agent[bot] 11dd7420ec Initial plan 2026-01-29 02:19:04 +00:00
+66 -16
View File
@@ -73,26 +73,76 @@ def _ffmpeg_load_file(filepath) -> tuple[np.ndarray, int]:
# Register FFmpeg-based audio loader
import vllm.multimodal.audio as _vllm_audio_module
_OriginalAudioMediaIO = _vllm_audio_module.AudioMediaIO
import warnings
class _PatchedAudioMediaIO(_OriginalAudioMediaIO):
"""AudioMediaIO implementation using FFmpeg for audio decoding."""
# Handle both old and new vLLM versions
# In newer versions, AudioMediaIO may not exist or may have been moved
try:
_OriginalAudioMediaIO = _vllm_audio_module.AudioMediaIO
def load_bytes(self, data: bytes) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(data, media_type=None)
class _PatchedAudioMediaIO(_OriginalAudioMediaIO):
"""AudioMediaIO implementation using FFmpeg for audio decoding."""
def __init__(self, **kwargs):
# Call parent constructor if it exists
if hasattr(super(), '__init__'):
super().__init__(**kwargs)
def load_bytes(self, data: bytes) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(data, media_type=None)
def load_base64(self, media_type: str, data: str) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(base64.b64decode(data), media_type=media_type)
def load_file(self, filepath) -> tuple[np.ndarray, int]:
return _ffmpeg_load_file(filepath)
def load_base64(self, media_type: str, data: str) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(base64.b64decode(data), media_type=media_type)
# Replace globally
_vllm_audio_module.AudioMediaIO = _PatchedAudioMediaIO
def load_file(self, filepath) -> tuple[np.ndarray, int]:
return _ffmpeg_load_file(filepath)
# Replace globally
_vllm_audio_module.AudioMediaIO = _PatchedAudioMediaIO
# Also patch in utils module where it's imported
import vllm.multimodal.utils as _vllm_utils_module
_vllm_utils_module.AudioMediaIO = _PatchedAudioMediaIO
# Also patch in utils module where it's imported
try:
import vllm.multimodal.utils as _vllm_utils_module
_vllm_utils_module.AudioMediaIO = _PatchedAudioMediaIO
except (ImportError, AttributeError) as e:
warnings.warn(f"Could not patch AudioMediaIO in vllm.multimodal.utils: {e}", UserWarning)
except (AttributeError, ImportError) as e:
# AudioMediaIO doesn't exist in this vLLM version
# Define our own standalone implementation
warnings.warn(
f"AudioMediaIO not found in vllm.multimodal.audio ({e}). "
"Using standalone FFmpeg-based implementation for compatibility.",
UserWarning
)
class _PatchedAudioMediaIO:
"""Standalone AudioMediaIO implementation using FFmpeg for audio decoding.
This is used when vLLM doesn't provide AudioMediaIO or it's been moved/removed.
"""
def __init__(self, **kwargs):
pass
def load_bytes(self, data: bytes) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(data, media_type=None)
def load_base64(self, media_type: str, data: str) -> tuple[np.ndarray, int]:
return _ffmpeg_load_bytes(base64.b64decode(data), media_type=media_type)
def load_file(self, filepath) -> tuple[np.ndarray, int]:
return _ffmpeg_load_file(filepath)
# Try to register it in the module if possible
try:
_vllm_audio_module.AudioMediaIO = _PatchedAudioMediaIO
except (AttributeError, TypeError) as e:
warnings.warn(
f"Could not register AudioMediaIO in vllm.multimodal.audio: {e}. "
"Audio loading will use FFmpeg functions directly.",
UserWarning
)
# ============================================================================