{"record":{"id":"d3c690b955de8fda","repo":"Stability-AI/generative-models","slug":"rearranging-not-available-for-len-in-shape-dime","errorCode":null,"errorMessage":"rearranging not available for {len(in_shape)}-dimensional input.","messagePattern":"rearranging not available for (.+?)-dimensional input\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sgm/modules/autoencoding/regularizers/quantize.py","lineNumber":483,"sourceCode":"        rearr = False\n        in_shape = z.shape\n\n        if z.ndim > 3:\n            rearr = self.output_dim is not None\n            z = rearrange(z, \"b c ... -> b (...) c\")\n        z = self.proj_in(z)\n        z_q, loss_dict = super().forward(z)\n\n        z_q = self.proj_out(z_q)\n        if rearr:\n            if len(in_shape) == 4:\n                z_q = rearrange(z_q, \"b (h w) c -> b c h w \", w=in_shape[-1])\n            elif len(in_shape) == 5:\n                z_q = rearrange(\n                    z_q, \"b (t h w) c -> b c t h w \", w=in_shape[-1], h=in_shape[-2]\n                )\n            else:\n                raise NotImplementedError(\n                    f\"rearranging not available for {len(in_shape)}-dimensional input.\"\n                )\n\n        return z_q, loss_dict\n","sourceCodeStart":465,"sourceCodeEnd":488,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/autoencoding/regularizers/quantize.py#L465-L488","documentation":"The quantizer's output was flattened to a token sequence and must be rearranged back to spatial form. Only 4D (b,h,w,c tokens) and 5D (b,t,h,w) inputs are supported; any other rank raises NotImplementedError.","triggerScenarios":"Calling the quantizer's forward with z whose shape has neither 4 nor 5 dimensions, e.g. a 2D (b,c) or 3D (b,c,l) latent tensor with an in_shape other than len 4 or 5.","commonSituations":"Feeding an audio/1D-signal autoencoder into a video/image VQ model, custom encoder producing extra/missing dims, or passing unbatched tensors.","solutions":["Reshape the latent so it has 4D (image) or 5D (video) form before calling forward","Check the model config: use a regularizer variant matching your data dimensionality","Extend the else-branch with a rearrange pattern for your specific rank"],"exampleFix":"// before: passing a 3D latent (b c l) into the video quantizer\nz_q, loss = quantizer(z, image_only_indicator)\n// after: unsqueeze to 5D video layout (b c t h w)\nz = z.unsqueeze(2).unsqueeze(3)  # give l a t/h/w interpretation as appropriate","handlingStrategy":"validation","validationCode":"def validate_quantizer_input(z):\n    if z.dim() not in (4, 5):\n        raise ValueError(f\"quantizer expects 4D or 5D latent, got {z.dim()}D\")\nvalidate_quantizer_input(z)","typeGuard":"def is_spatial_latent(z) -> bool:\n    return z.dim() in (4, 5)","tryCatchPattern":"try:\n    z_q, loss = quantizer(z)\nexcept NotImplementedError as e:\n    raise RuntimeError(f\"latent rank {z.dim()} unsupported: reshape to 4D/5D\") from e","preventionTips":["Check z.dim() before every quantizer call","Use model-specific wrappers that encode/decode with the correct rank","Never feed audio/1D latents into image/video VQ models without reshaping"],"tags":["python","not-implemented","shape-mismatch"],"backgroundTag":"unsupported-tensor-rank","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}