{"record":{"id":"7bc75a53d343514e","repo":"lllyasviel/Fooocus","slug":"scale-scale-is-not-supported-supported-scales-7bc75a","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/SwinIR.py","lineNumber":758,"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 UpsampleOneStep(nn.Sequential):\n    \"\"\"UpsampleOneStep module (the difference with Upsample is that it always only has 1conv + 1pixelshuffle)\n       Used in lightweight SR to save parameters.\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\n    def __init__(self, scale, num_feat, num_out_ch, input_resolution=None):\n        self.num_feat = num_feat\n        self.input_resolution = input_resolution","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/SwinIR.py#L740-L776","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom upscaler YAML copied from another arch; scripts deriving upscale from image sizes; typos in scale fields (e.g. 2.5).","solutions":["Use upscale 2, 4, 8 or 3","Chain 2x + 3x passes for 6x","Validate scale early in config loading"],"exampleFix":"# before\nm = SwinIR(upscale=6, ...)  # -> ValueError\n\n# after\nm = SwinIR(upscale=4, ...)","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\nupscale = int(cfg.get('upscale', 4))\nif not valid_sr_scale(upscale):\n    cfg['upscale'] = 4  # or raise a config error with context","typeGuard":"def is_supported_swinir_scale(scale) -> bool:\n    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)","tryCatchPattern":null,"preventionTips":["Validate the scale field of every SR model config at load time","For 6x output chain a 2x and a 3x SwinIR pass"],"tags":["super-resolution","swinir","upscale","config","valueerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}