{"record":{"id":"37a9f9d53c9fc325","repo":"lllyasviel/Fooocus","slug":"scale-scale-is-not-supported-supported-scales","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/DAT.py","lineNumber":867,"sourceCode":"\nclass Upsample(nn.Sequential):\n    \"\"\"Upsample module.\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":849,"sourceCodeEnd":885,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/DAT.py#L849-L885","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set scale to a power of two (2/4/8) or exactly 3","If you need another factor (e.g. 6x), chain two models (2x then 3x) instead of one DAT instance","Validate/round the scale value in your config before model construction"],"exampleFix":"# before\nmodel = DAT(upscale=6, ...)  # -> ValueError: scale 6 is not supported\n\n# after\nmodel_2x = DAT(upscale=2, ...)\nmodel_3x = DAT(upscale=3, ...)\nout = model_3x(model_2x(lr))  # 6x via 2x3 chain","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\nassert valid_sr_scale(cfg['scale']), f\"DAT scale must be 2^n or 3, got {cfg['scale']}\"","typeGuard":"def is_supported_dat_scale(scale: int) -> bool:\n    \"\"\"Type/narrowing guard: True for 2,4,8,16,... and 3.\"\"\"\n    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)","tryCatchPattern":null,"preventionTips":["Assert scale is 2^n or 3 in the upscaler config loader, not at model build","Chain 2x and 3x models for 6x instead of one model","Never derive scale from arbitrary image-size ratios without rounding to a supported value"],"tags":["super-resolution","dat","upscale","config","valueerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}