Comfy-Org/ComfyUI · error · ValueError

Unsupported spatial_scale {scale}. Choose from {list(mapping

Error message

Unsupported spatial_scale {scale}. Choose from {list(mapping.keys())}

What it means

The LTX latent upsampler maps each supported spatial scale to a rational upsample factor (0.75->3/4, 1.5->3/2, 2.0->2, 4.0->4) and only those exact floats are implemented. A scale outside this set has no resampling math, so _rational_for_scale refuses it.

Source

Thrown at comfy/ldm/lightricks/latent_upsampler.py:11

from typing import Optional, Tuple
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange


def _rational_for_scale(scale: float) -> Tuple[int, int]:
    mapping = {0.75: (3, 4), 1.5: (3, 2), 2.0: (2, 1), 4.0: (4, 1)}
    if float(scale) not in mapping:
        raise ValueError(
            f"Unsupported spatial_scale {scale}. Choose from {list(mapping.keys())}"
        )
    return mapping[float(scale)]


class PixelShuffleND(nn.Module):
    def __init__(self, dims, upscale_factors=(2, 2, 2)):
        super().__init__()
        assert dims in [1, 2, 3], "dims must be 1, 2, or 3"
        self.dims = dims
        self.upscale_factors = upscale_factors

    def forward(self, x):
        if self.dims == 3:
            return rearrange(
                x,
                "b (c p1 p2 p3) d h w -> b c (d p1) (h p2) (w p3)",
                p1=self.upscale_factors[0],

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Use one of the supported scales: 0.75, 1.5, 2.0, 4.0
  2. Snap near-miss floats: scale = min(mapping, key=lambda k: abs(k - scale)) before validating
  3. Chain two supported stages if you need e.g. 3x (2x then 1.5x)

Example fix

# before
upsampler = LatentUpsampler(spatial_scale=1.0)  # ValueError
# after
upsampler = LatentUpsampler(spatial_scale=2.0)
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {0.75, 1.5, 2.0, 4.0}
assert float(spatial_scale) in SUPPORTED, spatial_scale

Type guard

def is_supported_scale(s: float) -> bool:
    return float(s) in {0.75, 1.5, 2.0, 4.0}

Prevention

When it happens

Trigger: Constructing the upsampler (or an upsample node) with spatial_scale=1.0, 2.5, 3.0, or a scale passed as a string that does not float-compare equal to a key; also 0.75 written as 3/4 arithmetic that yields 0.7499999.

Common situations: UI dropdowns allowing arbitrary numeric input, users typing custom scales, or float rounding when the value crosses layers (JSON round-trip).

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/e0e200f157fbb49a. Report an issue: GitHub.