sgl-project/sglang · error · ValueError

audio must be a str, bytes, tuple, torch.Tensor, or np.ndarr

Error message

audio must be a str, bytes, tuple, torch.Tensor, or np.ndarray, but got {type(self.audio)}

What it means

MiMo audio preprocessing only accepts audio as a str path/URL, raw bytes, a (waveform, sample_rate) tuple, a torch.Tensor, or a numpy ndarray. Any other Python type is rejected at dataclass construction time.

Source

Thrown at python/sglang/srt/multimodal/processors/mimo_audio.py:50

    )
    torchaudio = None
    MelSpectrogram = None


@dataclass
class AudioInput:
    """
    if audio is str or bytes, only load it as mel spectrogram.
    if audio is tuple, it is (waveform, original_sr)
    if audio is torch.Tensor, it is tokenized input ids with shape (T, n_vq+).
    if audio is np.ndarray, it is a pre-loaded waveform (1D, already resampled).
    """

    audio: str | bytes | tuple | torch.Tensor | np.ndarray

    def __post_init__(self):
        if not isinstance(self.audio, (str, bytes, tuple, torch.Tensor, np.ndarray)):
            raise ValueError(
                f"audio must be a str, bytes, tuple, torch.Tensor, or np.ndarray, but got {type(self.audio)}"
            )
        if isinstance(self.audio, tuple):
            if (
                len(self.audio) != 2
                or not isinstance(self.audio[0], torch.Tensor)
                or not isinstance(self.audio[1], (int, float))
            ):
                raise ValueError(
                    f"audio must be a tuple of (waveform-T, original_sr-int/float), but got {len(self.audio)} elements and {type(self.audio[0])} and {type(self.audio[1])}"
                )
            if self.audio[0].ndim != 1:
                raise ValueError(
                    f"waveform must be a 1D tensor, but got {self.audio[0].ndim}D tensor"
                )
            if self.audio[1] <= 0:
                raise ValueError(
                    f"original_sr must be a positive number, but got {self.audio[1]}"

View on GitHub (pinned to 0132848349)

Solutions

  1. Pass the audio as a file path string, bytes, (Tensor, sr) tuple, Tensor, or ndarray
  2. If you have a file-like object, read it to bytes first
  3. Guard against None by checking the download succeeded before constructing the input

Example fix

# before
item = MiMoAudioInput(audio={"path": "a.wav"})
# after
item = MiMoAudioInput(audio="a.wav")
Defensive patterns

Strategy: type-guard

Validate before calling

import torch, numpy as np
assert isinstance(audio, (str, bytes, tuple, torch.Tensor, np.ndarray)), type(audio)

Type guard

def is_valid_audio(a) -> bool:
    import torch, numpy as np
    return isinstance(a, (str, bytes, tuple, torch.Tensor, np.ndarray))

Prevention

When it happens

Trigger: Constructing the MiMo audio input dataclass with e.g. an int, dict, list, or None as the audio field.

Common situations: Client code passes a file object, a dict like {"audio": ..., "sr": ...}, or None from a failed download instead of one of the accepted representations.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/7f8db6b7cbe6ad6f. Report an issue: GitHub.