{"record":{"id":"4eed2c7bccdd47c5","repo":"sgl-project/sglang","slug":"expected-decoded-audio-with-1-2-or-3-dims-got-s","errorCode":null,"errorMessage":"Expected decoded audio with 1, 2, or 3 dims, got shape={tuple(waveform.shape)}","messagePattern":"Expected decoded audio with 1, 2, or 3 dims, got shape=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/joy_echo/memory.py","lineNumber":557,"sourceCode":"        if waveform.shape[0] != 1:\n            raise ValueError(\n                f\"Expected batch size 1 for decoded audio, got shape={tuple(waveform.shape)}\"\n            )\n        waveform = waveform[0]\n    if waveform.ndim == 1:\n        waveform = waveform.unsqueeze(0)\n    elif (\n        waveform.ndim == 2\n        and waveform.shape[0] not in {1, 2}\n        and waveform.shape[1]\n        in {\n            1,\n            2,\n        }\n    ):\n        waveform = waveform.transpose(0, 1)\n    elif waveform.ndim != 2:\n        raise ValueError(\n            f\"Expected decoded audio with 1, 2, or 3 dims, got shape={tuple(waveform.shape)}\"\n        )\n\n    if waveform.shape[0] == 1:\n        waveform = waveform.repeat(2, 1)\n    elif waveform.shape[0] > 2:\n        waveform = waveform[:2]\n    return waveform.contiguous()\n\n\nclass PairedAudioVideoMemoryBank:\n    def __init__(self, max_size: int, num_fix_frames: int = 0) -> None:\n        self.max_size = int(max_size)\n        self.num_fix_frames = max(0, int(num_fix_frames))\n        self.memory: list[MemoryEntry] = []\n\n    @staticmethod\n    def _prepare_audio_latent(","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/joy_echo/memory.py#L539-L575","documentation":"After the 3-D and 1-D cases, the waveform must end up 2-D [C, T] (channels-first) or be transposable to it; anything with ndim not in {1,2,3} (e.g. 0-D scalar, 4-D+) is rejected because mel-spectrogram computation needs a [C, T] layout.","triggerScenarios":"Calling normalize_audio_waveform_for_media with a 0-D tensor, a 4-D batched-window tensor, or a numpy array coerced to an unexpected rank via torch.as_tensor on nested data.","commonSituations":"Passing already-windowed/framed audio of shape [B, C, F, T]; passing nested lists or a scalar; double-wrapping a waveform (e.g. stacking already-2-D tensors).","solutions":["Squeeze to a single waveform: pass waveform.view(-1) for 1-D PCM or [C,T] for multi-channel","If you have framed audio [B,C,F,T], flatten frames back to time: waveform.reshape(C, -1) after selecting the item","Log waveform.ndim and shape before calling to identify the offending upstream stage"],"exampleFix":"# before\nsave_memory_slot(..., audio_waveform=framed)  # framed is [1, 1, F, T]\n# after\nwave = framed[0, 0].reshape(framed.shape[-2], -1)  # [C, T]\nsave_memory_slot(..., audio_waveform=wave)","handlingStrategy":"validation","validationCode":"if waveform.ndim not in (1, 2, 3):\n    raise ValueError(f\"unsupported audio rank {waveform.ndim}: pass 1-D PCM or [C,T]/[B,T,C]\")","typeGuard":"def is_supported_waveform(t: torch.Tensor) -> bool:\n    return 1 <= t.ndim <= 3","tryCatchPattern":null,"preventionTips":["Flatten framed/windowed audio back to [C,T] before passing","Add a shape-print debug hook at the audio boundary of your pipeline"],"tags":["joy-echo","audio","waveform","tensor-shape"],"backgroundTag":"invalid-tensor-shape","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}