lllyasviel/Fooocus · error · ValueError

scale {scale} is not supported. Supported scales: 2^n and 3.

Error message

scale {scale} is not supported. Supported scales: 2^n and 3.

What it means

Swin2SR.Upsample supports only power-of-two scales (via repeated 2x conv+PixelShuffle) or exactly 3; any other scale raises ValueError. This is the standard BasicSR upsampling tail, so Swin2SR models can only be built for 2x/4x/8x/... or 3x upscaling.

Source

Thrown at ldm_patched/pfn/architecture/Swin2SR.py:801

class Upsample(nn.Sequential):
    """Upsample module.

    Args:
        scale (int): Scale factor. Supported scales: 2^n and 3.
        num_feat (int): Channel number of intermediate features.
    """

    def __init__(self, scale, num_feat):
        m = []
        if (scale & (scale - 1)) == 0:  # scale = 2^n
            for _ in range(int(math.log(scale, 2))):
                m.append(nn.Conv2d(num_feat, 4 * num_feat, 3, 1, 1))
                m.append(nn.PixelShuffle(2))
        elif scale == 3:
            m.append(nn.Conv2d(num_feat, 9 * num_feat, 3, 1, 1))
            m.append(nn.PixelShuffle(3))
        else:
            raise ValueError(
                f"scale {scale} is not supported. " "Supported scales: 2^n and 3."
            )
        super(Upsample, self).__init__(*m)


class Upsample_hf(nn.Sequential):
    """Upsample module.

    Args:
        scale (int): Scale factor. Supported scales: 2^n and 3.
        num_feat (int): Channel number of intermediate features.
    """

    def __init__(self, scale, num_feat):
        m = []
        if (scale & (scale - 1)) == 0:  # scale = 2^n
            for _ in range(int(math.log(scale, 2))):
                m.append(nn.Conv2d(num_feat, 4 * num_feat, 3, 1, 1))

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Use upscale 2, 4, 8 or 3
  2. Compose passes (2x then 3x) for 6x output
  3. Validate the scale in config loading: assert upscale == 3 or (upscale & (upscale-1)) == 0

Example fix

# before
m = Swin2SR(upscale=6, ...)  # -> ValueError: scale 6 is not supported

# after
m2 = Swin2SR(upscale=2, ...); m3 = Swin2SR(upscale=3, ...)
out = m3(m2(lr))
Defensive patterns

Strategy: validation

Validate before calling

def valid_sr_scale(scale) -> bool:
    return scale == 3 or (isinstance(scale, int) and scale > 1 and (scale & (scale - 1)) == 0)

if not valid_sr_scale(cfg['upscale']):
    raise ConfigError(f"Swin2SR upscale must be 2^n or 3, got {cfg['upscale']}")

Type guard

def is_supported_swin2sr_scale(scale) -> bool:
    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)

Prevention

When it happens

Trigger: Creating Swin2SR with upscale not in {2,4,8,...,3} - e.g. 5, 6, or a value derived from a mismatched training config; commonly the 'upscale' argument is read from an upscaler metadata dict without validation.

Common situations: Custom Swin2SR upscaler YAMLs with scale: 6; scripts computing upscale = ceil(target/lr); reusing Real-ESRGAN config blocks across architectures.

Related errors


AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15). Data as JSON: /api/errors/17722c56cc459820. Report an issue: GitHub.