{"record":{"id":"8e7d334fd27c96de","repo":"sgl-project/sglang","slug":"waveform-must-be-a-1d-tensor-but-got-self-audio","errorCode":null,"errorMessage":"waveform must be a 1D tensor, but got {self.audio[0].ndim}D tensor","messagePattern":"waveform must be a 1D tensor, but got (.+?)D tensor","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/mimo_audio.py","lineNumber":63,"sourceCode":"\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]}\"\n                )\n        if isinstance(self.audio, torch.Tensor) and self.audio.ndim != 2:\n            raise ValueError(\n                f\"audio must be a 2D tensor, but got {self.audio.ndim}D tensor\"\n            )\n\n\nclass MiMoAudioPipeline:\n    \"\"\"Stateful audio preprocessing pipeline.\n\n    Composable: held by both MiMoProcessor (multimodal) and MiMoV2ASRProcessor.\n    Owns the mel spectrogram, resampler cache, http session, and the special\n    token ids for ``<|sosp|> <|empty|>* <|eosp|>`` placeholders.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/mimo_audio.py#L45-L81","documentation":"Inside the (waveform, sr) tuple form, the waveform must be a 1D tensor of shape (T,). A 2D/3D tensor (e.g. batched or channel-first audio) is rejected.","triggerScenarios":"Passing a tensor of shape (1, T) or (B, C, T) as the waveform element of the audio tuple.","commonSituations":"Loading audio via torchaudio.load which returns shape (channels, T); forgetting to squeeze mono audio to 1D.","solutions":["Reshape to 1D: waveform.squeeze(0) for mono, or mean over the channel dim for stereo","Use waveform.reshape(-1) when the audio is mono stored with a leading 1","Check waveform.ndim == 1 before constructing the input"],"exampleFix":"# before\nwaveform, sr = torchaudio.load(\"a.wav\")  # (channels, T)\naudio = (waveform, sr)\n# after\nwaveform, sr = torchaudio.load(\"a.wav\")\naudio = (waveform.mean(dim=0), sr)  # mono 1D","handlingStrategy":"validation","validationCode":"assert isinstance(audio[0], torch.Tensor) and audio[0].ndim == 1, f\"got {audio[0].ndim}D\"","typeGuard":"def is_1d_waveform(w) -> bool:\n    import torch\n    return isinstance(w, torch.Tensor) and w.ndim == 1","tryCatchPattern":null,"preventionTips":["Squeeze mono audio after torchaudio.load before passing downstream","Add a shape assertion in your audio loading helper"],"tags":["multimodal","audio","tensor-shape","mimo"],"backgroundTag":"audio-tensor-shape-mismatch","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}