sgl-project/sglang · error · ValueError
audio must be a 2D tensor, but got {self.audio.ndim}D tensor
Error message
audio must be a 2D tensor, but got {self.audio.ndim}D tensor What it means
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__.
Source
Thrown at python/sglang/srt/multimodal/processors/mimo_audio.py:71
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]}"
)
if isinstance(self.audio, torch.Tensor) and self.audio.ndim != 2:
raise ValueError(
f"audio must be a 2D tensor, but got {self.audio.ndim}D tensor"
)
class MiMoAudioPipeline:
"""Stateful audio preprocessing pipeline.
Composable: held by both MiMoProcessor (multimodal) and MiMoV2ASRProcessor.
Owns the mel spectrogram, resampler cache, http session, and the special
token ids for ``<|sosp|> <|empty|>* <|eosp|>`` placeholders.
"""
def __init__(
self,
*,
audio_token_id: int,
audio_start_token_id: int,
audio_end_token_id: int,View on GitHub (pinned to 0132848349)
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
Example fix
# before audio = waveform_1d # ndim == 1 -> error # after audio = (waveform_1d, 16000) # tuple form accepts 1D waveform
Defensive patterns
Strategy: validation
Validate before calling
import torch
if isinstance(audio, torch.Tensor):
assert audio.ndim == 2, f"tensor audio must be 2D, got {audio.ndim}D" Type guard
def is_valid_tensor_audio(a) -> bool:
import torch
return not isinstance(a, torch.Tensor) or a.ndim == 2 Prevention
- Use the tuple form for 1D waveforms; keep bare tensors 2D
- Document the two accepted shapes in your ingestion layer
When it happens
Trigger: Constructing the audio input with a 1D tensor of shape (T,) or a 3D tensor instead of the required 2D layout.
Common situations: 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.
Related errors
- waveform must be a 1D tensor, but got {self.audio[0].ndim}D
- audio must be a str, bytes, tuple, torch.Tensor, or np.ndarr
- audio must be a tuple of (waveform-T, original_sr-int/float)
- original_sr must be a positive number, but got {self.audio[1
- torchaudio is required for audio inputs; install torchaudio
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/6cc14557d986558e.
Report an issue: GitHub.