Stability-AI/generative-models · error · NotImplementedError
rearranging not available for {len(in_shape)}-dimensional in
Error message
rearranging not available for {len(in_shape)}-dimensional input. What it means
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.
Source
Thrown at sgm/modules/autoencoding/regularizers/quantize.py:483
rearr = False
in_shape = z.shape
if z.ndim > 3:
rearr = self.output_dim is not None
z = rearrange(z, "b c ... -> b (...) c")
z = self.proj_in(z)
z_q, loss_dict = super().forward(z)
z_q = self.proj_out(z_q)
if rearr:
if len(in_shape) == 4:
z_q = rearrange(z_q, "b (h w) c -> b c h w ", w=in_shape[-1])
elif len(in_shape) == 5:
z_q = rearrange(
z_q, "b (t h w) c -> b c t h w ", w=in_shape[-1], h=in_shape[-2]
)
else:
raise NotImplementedError(
f"rearranging not available for {len(in_shape)}-dimensional input."
)
return z_q, loss_dict
View on GitHub (pinned to e8cd657656)
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
Example fix
// before: passing a 3D latent (b c l) into the video quantizer z_q, loss = quantizer(z, image_only_indicator) // after: unsqueeze to 5D video layout (b c t h w) z = z.unsqueeze(2).unsqueeze(3) # give l a t/h/w interpretation as appropriate
Defensive patterns
Strategy: validation
Validate before calling
def validate_quantizer_input(z):
if z.dim() not in (4, 5):
raise ValueError(f"quantizer expects 4D or 5D latent, got {z.dim()}D")
validate_quantizer_input(z) Type guard
def is_spatial_latent(z) -> bool:
return z.dim() in (4, 5) Try / catch
try:
z_q, loss = quantizer(z)
except NotImplementedError as e:
raise RuntimeError(f"latent rank {z.dim()} unsupported: reshape to 4D/5D") from e Prevention
- 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
When it happens
Trigger: 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.
Common situations: Feeding an audio/1D-signal autoencoder into a video/image VQ model, custom encoder producing extra/missing dims, or passing unbatched tensors.
Related errors
- NotImplementedError
- Unknown loss type {self.loss_type}
- provide num_res_blocks either as an int (globally constant)
- NotImplementedError
- unknown merge strategy {self.merge_strategy}
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/d3c690b955de8fda.
Report an issue: GitHub.