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
SwinIR.Upsample: the BasicSR-style tail accepts power-of-two scales (repeated 2x PixelShuffle) or scale 3; all other values raise ValueError. SwinIR SR models therefore only exist for 2x/3x/4x/8x.
Source
Thrown at ldm_patched/pfn/architecture/SwinIR.py:758
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_resolutionView on GitHub (pinned to ae05379cc9)
Solutions
- Use upscale 2, 4, 8 or 3
- Chain 2x + 3x passes for 6x
- Validate scale early in config loading
Example fix
# before m = SwinIR(upscale=6, ...) # -> ValueError # after m = SwinIR(upscale=4, ...)
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)
upscale = int(cfg.get('upscale', 4))
if not valid_sr_scale(upscale):
cfg['upscale'] = 4 # or raise a config error with context Type guard
def is_supported_swinir_scale(scale) -> bool:
return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0) Prevention
- Validate the scale field of every SR model config at load time
- For 6x output chain a 2x and a 3x SwinIR pass
When it happens
Trigger: Instantiating SwinIR with upscale outside {2,4,8,...,3}; e.g. porting a config with scale 6, or passing a computed ratio like 5 when registering a custom upscaler.
Common situations: Custom upscaler YAML copied from another arch; scripts deriving upscale from image sizes; typos in scale fields (e.g. 2.5).
Related errors
- scale {scale} is not supported. Supported scales: 2^n and 3.
- scale {scale} is not supported. Supported scales: 2^n and 3.
- scale {scale} is not supported. Supported scales: 2^n and 3.
- Upsample mode [{self.upsampler}] is not found
- upsample mode [{upsampler}] is not found
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/7bc75a53d343514e.
Report an issue: GitHub.