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

DAT.Upsample builds the pixel-shuffle upsampling tail: scales that are powers of two get repeated 2x PixelShuffle blocks, scale 3 gets one 3x block, and anything else raises ValueError. So the DAT super-resolution model only supports upscale factors 2, 4, 8, ... and 3.

Source

Thrown at ldm_patched/pfn/architecture/DAT.py:867

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 UpsampleOneStep(nn.Sequential):
    """UpsampleOneStep module (the difference with Upsample is that it always only has 1conv + 1pixelshuffle)
       Used in lightweight SR to save parameters.

    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, num_out_ch, input_resolution=None):
        self.num_feat = num_feat
        self.input_resolution = input_resolution

View on GitHub (pinned to ae05379cc9)

Solutions

  1. Set scale to a power of two (2/4/8) or exactly 3
  2. If you need another factor (e.g. 6x), chain two models (2x then 3x) instead of one DAT instance
  3. Validate/round the scale value in your config before model construction

Example fix

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

# after
model_2x = DAT(upscale=2, ...)
model_3x = DAT(upscale=3, ...)
out = model_3x(model_2x(lr))  # 6x via 2x3 chain
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)

assert valid_sr_scale(cfg['scale']), f"DAT scale must be 2^n or 3, got {cfg['scale']}"

Type guard

def is_supported_dat_scale(scale: int) -> bool:
    """Type/narrowing guard: True for 2,4,8,16,... and 3."""
    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)

Prevention

When it happens

Trigger: Instantiating DAT (or a model wiring DAT's Upsample) with scale not in {2,4,8,16,...,3}: e.g. scale=5, 6, 7, or a float like 2.5 (bitwise check (scale & (scale-1)) == 0 also misbehaves for non-integers). Typically the scale arrives from an upscaler YAML/config or is computed from img_size ratios.

Common situations: Registering a DAT upscaler with a custom scale; config files copied from Real-ESRGAN with scale: 6; passing an odd 'scale' parameter when creating the model programmatically.

Related errors


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