{"record":{"id":"df3689e1eb484daa","repo":"sgl-project/sglang","slug":"unsupported-dims-self-dims","errorCode":null,"errorMessage":"Unsupported dims: {self.dims}","messagePattern":"Unsupported dims: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/upsampler/latent_upsampler.py","lineNumber":92,"sourceCode":"                p1=self.upscale_factors[0],\n                p2=self.upscale_factors[1],\n                p3=self.upscale_factors[2],\n            )\n        elif self.dims == 2:\n            return rearrange(\n                x,\n                \"b (c p1 p2) h w -> b c (h p1) (w p2)\",\n                p1=self.upscale_factors[0],\n                p2=self.upscale_factors[1],\n            )\n        elif self.dims == 1:\n            return rearrange(\n                x,\n                \"b (c p1) f h w -> b c (f p1) h w\",\n                p1=self.upscale_factors[0],\n            )\n        else:\n            raise ValueError(f\"Unsupported dims: {self.dims}\")\n\n\nclass ResBlock(torch.nn.Module):\n    \"\"\"Residual block with two conv layers, group norm, and SiLU activation.\"\"\"\n\n    def __init__(\n        self, channels: int, mid_channels: Optional[int] = None, dims: int = 3\n    ):\n        super().__init__()\n        if mid_channels is None:\n            mid_channels = channels\n        conv = torch.nn.Conv2d if dims == 2 else torch.nn.Conv3d\n        self.conv1 = conv(channels, mid_channels, kernel_size=3, padding=1)\n        self.norm1 = torch.nn.GroupNorm(32, mid_channels)\n        self.conv2 = conv(mid_channels, channels, kernel_size=3, padding=1)\n        self.norm2 = torch.nn.GroupNorm(32, channels)\n        self.activation = torch.nn.SiLU()\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/upsampler/latent_upsampler.py#L74-L110","documentation":"LatentUpsampler.forward only supports 3D (video: b c f h w) and modified-4D/5D rearrange paths keyed by self.dims and upscale_factors; any other dims value falls through to this ValueError. The module is built for a fixed spatial/temporal upsampling geometry.","triggerScenarios":"Instantiating LatentUpsampler with dims not equal to the supported values (e.g. dims=2 for plain 2D image latents) and calling forward(), or feeding tensors whose rank does not match the configured path.","commonSituations":"Reusing the video latent upsampler for 2D image latents, changing dims in config, or passing incorrectly rearranged tensors from a different pipeline stage.","solutions":["Set dims to the supported value matching your data (5 for video latents b c f h w)","For plain 2D image latent upsampling use a different module (e.g. a VAE decoder-side upsampler or interpolate)","Verify tensor shape before forward: x.ndim should equal self.dims + 2"],"exampleFix":"// before\nups = LatentUpsampler(..., dims=2)\ny = ups(x)  # x: b c h w\n// after\nups = LatentUpsampler(..., dims=5)\ny = ups(x)  # x: b c f h w video latents","handlingStrategy":"type-guard","validationCode":"assert x.ndim == ups.dims + 2 or (x.ndim == ups.dims and ups.dims in (3, 4)), f\"unexpected rank {x.ndim} for dims={ups.dims}\"","typeGuard":"def is_supported_upsampler_input(x: torch.Tensor, ups) -> bool:\n    return x.ndim in (ups.dims, ups.dims + 1, ups.dims + 2) and ups.dims in (3, 5)","tryCatchPattern":"try:\n    y = ups(x)\nexcept ValueError as e:\n    if \"Unsupported dims\" in str(e):\n        raise ValueError(f\"feed {ups.dims + 2}-D latents to LatentUpsampler\") from e\n    raise","preventionTips":["Check tensor rank against module dims before forward","Use the video latent upsampler only for video latents; pick another path for 2D images"],"tags":["upsampler","multimodal","video","tensor-shape"],"backgroundTag":"unsupported-tensor-rank","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}