sgl-project/sglang · error · ValueError

audio must be a tuple of (waveform-T, original_sr-int/float)

Error message

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])}

What it means

When audio is given as a tuple, it must be exactly a 2-tuple of (1D waveform Tensor, int/float original sample rate). The supplied tuple has the wrong arity or element types.

Source

Thrown at python/sglang/srt/multimodal/processors/mimo_audio.py:59

    if audio is tuple, it is (waveform, original_sr)
    if audio is torch.Tensor, it is tokenized input ids with shape (T, n_vq+).
    if audio is np.ndarray, it is a pre-loaded waveform (1D, already resampled).
    """

    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.

View on GitHub (pinned to 0132848349)

Solutions

  1. Convert the waveform to a torch.Tensor and pass a numeric sample rate: (torch.Tensor, int)
  2. Drop extra tuple elements — keep only waveform and sample_rate
  3. Verify len(tuple) == 2 before construction

Example fix

# before
audio = (np_waveform, "16000")
# after
audio = (torch.from_numpy(np_waveform), 16000)
Defensive patterns

Strategy: validation

Validate before calling

import torch
assert len(audio) == 2 and isinstance(audio[0], torch.Tensor) and isinstance(audio[1], (int, float))

Type guard

def is_valid_audio_tuple(a) -> bool:
    import torch
    return (isinstance(a, tuple) and len(a) == 2
            and isinstance(a[0], torch.Tensor)
            and isinstance(a[1], (int, float)))

Prevention

When it happens

Trigger: Constructing the audio input with a 3-element tuple, a tuple whose first element is a list/ndarray instead of torch.Tensor, or whose second element is a string/non-numeric sample rate.

Common situations: Client builds (waveform, sr, text) triples, uses numpy waveform without converting to Tensor, or passes sr as a string parsed from a header.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/19e28c4d1b987c93. Report an issue: GitHub.