From 488869c2d0f3321299488bcf221934df40b06454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bernl=C3=B6hr?= Date: Thu, 1 Oct 2026 00:28:16 +0200 Subject: [PATCH] [Fix] Keep MiMo-V2 processor available without TorchCodec (#41667) Co-authored-by: jbernloehr --- python/sglang/srt/multimodal/processors/mimo_audio.py | 7 +++++-- python/sglang/srt/multimodal/processors/mimo_v2.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/multimodal/processors/mimo_audio.py b/python/sglang/srt/multimodal/processors/mimo_audio.py index 909c9965b1..bb53d98641 100644 --- a/python/sglang/srt/multimodal/processors/mimo_audio.py +++ b/python/sglang/srt/multimodal/processors/mimo_audio.py @@ -17,9 +17,12 @@ from sglang.utils import logger try: from torchcodec.decoders import AudioDecoder -except ImportError: +except (ImportError, OSError, RuntimeError) as e: + # TorchCodec may be installed but unable to load its FFmpeg libraries. logger.warning( - "torchcodec is not installed; audio inputs will fail at request time" + "torchcodec is unavailable; video audio-track detection and " + "audio decoding via AudioDecoder are disabled: %s", + e, ) AudioDecoder = None diff --git a/python/sglang/srt/multimodal/processors/mimo_v2.py b/python/sglang/srt/multimodal/processors/mimo_v2.py index e914f00b1a..b6951b0acb 100644 --- a/python/sglang/srt/multimodal/processors/mimo_v2.py +++ b/python/sglang/srt/multimodal/processors/mimo_v2.py @@ -16,7 +16,6 @@ import torch import torch.nn.functional as F from fastapi import HTTPException from PIL import Image -from torchcodec.decoders import AudioDecoder from transformers.models.qwen2_5_vl.configuration_qwen2_5_vl import ( Qwen2_5_VLVisionConfig, ) @@ -33,6 +32,7 @@ from sglang.srt.multimodal.processors.base_processor import ( MultimodalSpecialTokens, ) from sglang.srt.multimodal.processors.mimo_audio import ( + AudioDecoder, AudioInput, MiMoAudioPipeline, ) @@ -452,6 +452,11 @@ class MiMoProcessor: @staticmethod def has_audio_track(path_or_data) -> bool: + if AudioDecoder is None: + raise ValueError( + "torchcodec is required to detect audio tracks in video inputs; " + "install torchcodec and its FFmpeg dependencies." + ) # Never hand a client-supplied URL to ffprobe: its internal HTTP client # would bypass the shared domain and redirect policy. Resolve it through # the guarded downloader first, then probe the resulting bytes in-process.