{"record":{"id":"7f8db6b7cbe6ad6f","repo":"sgl-project/sglang","slug":"audio-must-be-a-str-bytes-tuple-torch-tensor-o","errorCode":null,"errorMessage":"audio must be a str, bytes, tuple, torch.Tensor, or np.ndarray, but got {type(self.audio)}","messagePattern":"audio must be a str, bytes, tuple, torch\\.Tensor, or np\\.ndarray, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/mimo_audio.py","lineNumber":50,"sourceCode":"    )\n    torchaudio = None\n    MelSpectrogram = None\n\n\n@dataclass\nclass AudioInput:\n    \"\"\"\n    if audio is str or bytes, only load it as mel spectrogram.\n    if audio is tuple, it is (waveform, original_sr)\n    if audio is torch.Tensor, it is tokenized input ids with shape (T, n_vq+).\n    if audio is np.ndarray, it is a pre-loaded waveform (1D, already resampled).\n    \"\"\"\n\n    audio: str | bytes | tuple | torch.Tensor | np.ndarray\n\n    def __post_init__(self):\n        if not isinstance(self.audio, (str, bytes, tuple, torch.Tensor, np.ndarray)):\n            raise ValueError(\n                f\"audio must be a str, bytes, tuple, torch.Tensor, or np.ndarray, but got {type(self.audio)}\"\n            )\n        if isinstance(self.audio, tuple):\n            if (\n                len(self.audio) != 2\n                or not isinstance(self.audio[0], torch.Tensor)\n                or not isinstance(self.audio[1], (int, float))\n            ):\n                raise ValueError(\n                    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])}\"\n                )\n            if self.audio[0].ndim != 1:\n                raise ValueError(\n                    f\"waveform must be a 1D tensor, but got {self.audio[0].ndim}D tensor\"\n                )\n            if self.audio[1] <= 0:\n                raise ValueError(\n                    f\"original_sr must be a positive number, but got {self.audio[1]}\"","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/mimo_audio.py#L32-L68","documentation":"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.","triggerScenarios":"Constructing the MiMo audio input dataclass with e.g. an int, dict, list, or None as the audio field.","commonSituations":"Client code passes a file object, a dict like {\"audio\": ..., \"sr\": ...}, or None from a failed download instead of one of the accepted representations.","solutions":["Pass the audio as a file path string, bytes, (Tensor, sr) tuple, Tensor, or ndarray","If you have a file-like object, read it to bytes first","Guard against None by checking the download succeeded before constructing the input"],"exampleFix":"# before\nitem = MiMoAudioInput(audio={\"path\": \"a.wav\"})\n# after\nitem = MiMoAudioInput(audio=\"a.wav\")","handlingStrategy":"type-guard","validationCode":"import torch, numpy as np\nassert isinstance(audio, (str, bytes, tuple, torch.Tensor, np.ndarray)), type(audio)","typeGuard":"def is_valid_audio(a) -> bool:\n    import torch, numpy as np\n    return isinstance(a, (str, bytes, tuple, torch.Tensor, np.ndarray))","tryCatchPattern":null,"preventionTips":["Convert file-like objects to bytes and paths to str before building the request","Unit-test your request builder against the accepted type list"],"tags":["multimodal","audio","type-validation","mimo"],"backgroundTag":"invalid-multimodal-input-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}