{"record":{"id":"17722c56cc459820","repo":"lllyasviel/Fooocus","slug":"scale-scale-is-not-supported-supported-scales-17722c","errorCode":null,"errorMessage":"scale {scale} is not supported. Supported scales: 2^n and 3.","messagePattern":"scale (.+?) is not supported\\. Supported scales: 2\\^n and 3\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ldm_patched/pfn/architecture/Swin2SR.py","lineNumber":801,"sourceCode":"class Upsample(nn.Sequential):\n    \"\"\"Upsample module.\n\n    Args:\n        scale (int): Scale factor. Supported scales: 2^n and 3.\n        num_feat (int): Channel number of intermediate features.\n    \"\"\"\n\n    def __init__(self, scale, num_feat):\n        m = []\n        if (scale & (scale - 1)) == 0:  # scale = 2^n\n            for _ in range(int(math.log(scale, 2))):\n                m.append(nn.Conv2d(num_feat, 4 * num_feat, 3, 1, 1))\n                m.append(nn.PixelShuffle(2))\n        elif scale == 3:\n            m.append(nn.Conv2d(num_feat, 9 * num_feat, 3, 1, 1))\n            m.append(nn.PixelShuffle(3))\n        else:\n            raise ValueError(\n                f\"scale {scale} is not supported. \" \"Supported scales: 2^n and 3.\"\n            )\n        super(Upsample, self).__init__(*m)\n\n\nclass Upsample_hf(nn.Sequential):\n    \"\"\"Upsample module.\n\n    Args:\n        scale (int): Scale factor. Supported scales: 2^n and 3.\n        num_feat (int): Channel number of intermediate features.\n    \"\"\"\n\n    def __init__(self, scale, num_feat):\n        m = []\n        if (scale & (scale - 1)) == 0:  # scale = 2^n\n            for _ in range(int(math.log(scale, 2))):\n                m.append(nn.Conv2d(num_feat, 4 * num_feat, 3, 1, 1))","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/Swin2SR.py#L783-L819","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom Swin2SR upscaler YAMLs with scale: 6; scripts computing upscale = ceil(target/lr); reusing Real-ESRGAN config blocks across architectures.","solutions":["Use upscale 2, 4, 8 or 3","Compose passes (2x then 3x) for 6x output","Validate the scale in config loading: assert upscale == 3 or (upscale & (upscale-1)) == 0"],"exampleFix":"# before\nm = Swin2SR(upscale=6, ...)  # -> ValueError: scale 6 is not supported\n\n# after\nm2 = Swin2SR(upscale=2, ...); m3 = Swin2SR(upscale=3, ...)\nout = m3(m2(lr))","handlingStrategy":"validation","validationCode":"def valid_sr_scale(scale) -> bool:\n    return scale == 3 or (isinstance(scale, int) and scale > 1 and (scale & (scale - 1)) == 0)\n\nif not valid_sr_scale(cfg['upscale']):\n    raise ConfigError(f\"Swin2SR upscale must be 2^n or 3, got {cfg['upscale']}\")","typeGuard":"def is_supported_swin2sr_scale(scale) -> bool:\n    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)","tryCatchPattern":null,"preventionTips":["Restrict upscale to {2,3,4,8} in upscaler registration code","Round computed scales to the nearest supported factor or chain passes"],"tags":["super-resolution","swin2sr","upscale","config","valueerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}