sgl-project/sglang · error · ValueError
waveform must be a 1D tensor, but got {self.audio[0].ndim}D
Error message
waveform must be a 1D tensor, but got {self.audio[0].ndim}D tensor What it means
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.
Source
Thrown at python/sglang/srt/multimodal/processors/mimo_audio.py:63
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]}"
)
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.View on GitHub (pinned to 0132848349)
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
Example fix
# before
waveform, sr = torchaudio.load("a.wav") # (channels, T)
audio = (waveform, sr)
# after
waveform, sr = torchaudio.load("a.wav")
audio = (waveform.mean(dim=0), sr) # mono 1D Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(audio[0], torch.Tensor) and audio[0].ndim == 1, f"got {audio[0].ndim}D" Type guard
def is_1d_waveform(w) -> bool:
import torch
return isinstance(w, torch.Tensor) and w.ndim == 1 Prevention
- Squeeze mono audio after torchaudio.load before passing downstream
- Add a shape assertion in your audio loading helper
When it happens
Trigger: Passing a tensor of shape (1, T) or (B, C, T) as the waveform element of the audio tuple.
Common situations: Loading audio via torchaudio.load which returns shape (channels, T); forgetting to squeeze mono audio to 1D.
Related errors
- audio must be a 2D tensor, but got {self.audio.ndim}D tensor
- 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/8e7d334fd27c96de.
Report an issue: GitHub.