{"record":{"id":"6cc14557d986558e","repo":"sgl-project/sglang","slug":"audio-must-be-a-2d-tensor-but-got-self-audio-ndi","errorCode":null,"errorMessage":"audio must be a 2D tensor, but got {self.audio.ndim}D tensor","messagePattern":"audio must be a 2D tensor, but got (.+?)D tensor","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/multimodal/processors/mimo_audio.py","lineNumber":71,"sourceCode":"        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.\n    \"\"\"\n\n    def __init__(\n        self,\n        *,\n        audio_token_id: int,\n        audio_start_token_id: int,\n        audio_end_token_id: int,","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/multimodal/processors/mimo_audio.py#L53-L89","documentation":"When audio is passed directly as a torch.Tensor (not a tuple), it must be 2D — typically shape (channels/batches, time). A 1D or 3D tensor is rejected in __post_init__.","triggerScenarios":"Constructing the audio input with a 1D tensor of shape (T,) or a 3D tensor instead of the required 2D layout.","commonSituations":"User loads mono audio as a 1D tensor and passes it directly; the intended form for raw 1D waveforms is the (waveform, sr) tuple, which is the common mix-up.","solutions":["For a 1D waveform with a sample rate, use the tuple form: (waveform_1d, original_sr)","Otherwise reshape the tensor to 2D with waveform.unsqueeze(0)","Check tensor.ndim == 2 before constructing the input"],"exampleFix":"# before\naudio = waveform_1d  # ndim == 1 -> error\n# after\naudio = (waveform_1d, 16000)  # tuple form accepts 1D waveform","handlingStrategy":"validation","validationCode":"import torch\nif isinstance(audio, torch.Tensor):\n    assert audio.ndim == 2, f\"tensor audio must be 2D, got {audio.ndim}D\"","typeGuard":"def is_valid_tensor_audio(a) -> bool:\n    import torch\n    return not isinstance(a, torch.Tensor) or a.ndim == 2","tryCatchPattern":null,"preventionTips":["Use the tuple form for 1D waveforms; keep bare tensors 2D","Document the two accepted shapes in your ingestion layer"],"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"}