{"record":{"id":"a38877df1197b641","repo":"lllyasviel/Fooocus","slug":"scale-scale-is-not-supported-supported-scales-a38877","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/HAT.py","lineNumber":841,"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 HAT(nn.Module):\n    r\"\"\"Hybrid Attention Transformer\n        A PyTorch implementation of : `Activating More Pixels in Image Super-Resolution Transformer`.\n        Some codes are based on SwinIR.\n    Args:\n        img_size (int | tuple(int)): Input image size. Default 64\n        patch_size (int | tuple(int)): Patch size. Default: 1\n        in_chans (int): Number of input image channels. Default: 3\n        embed_dim (int): Patch embedding dimension. Default: 96\n        depths (tuple(int)): Depth of each Swin Transformer layer.\n        num_heads (tuple(int)): Number of attention heads in different layers.\n        window_size (int): Window size. Default: 7\n        mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4","sourceCodeStart":823,"sourceCodeEnd":859,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/HAT.py#L823-L859","documentation":"HAT.Upsample has the same tail logic as the other BasicSR-derived transformers: power-of-two scales via repeated 2x PixelShuffle, one 3x branch, everything else rejected. The HAT (Hybrid Attention Transformer) architecture cannot be built for any other upscale factor.","triggerScenarios":"Constructing HAT with upscale outside {2,4,8,...,3}, e.g. 5 or 7; most often the 'upscale' value comes from an upscaler registration dict or model YAML and is not sanity-checked before __init__.","commonSituations":"Custom upscaler YAMLs copied between architectures; computed scales like upscale = target_size // input_size landing on 6; scripts registering HAT for arbitrary x-values.","solutions":["Use upscale=2, 4, 8 or 3 for HAT","Chain a 2x and a 3x HAT pass for 6x output","Add an upfront assert on the config value so the failure is caught at config-load time, not model build time"],"exampleFix":"# before\nm = HAT(upscale=5, ...)  # -> ValueError: scale 5 is not supported\n\n# after\nassert upscale == 3 or (upscale & (upscale - 1)) == 0, 'HAT needs scale 2^n or 3'\nm = HAT(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 = cfg.get('upscale', 4)\nif not valid_sr_scale(upscale):\n    cfg['upscale'] = 4  # or reject the config","typeGuard":"def is_supported_hat_scale(scale) -> bool:\n    return isinstance(scale, int) and (scale == 3 or (scale & (scale - 1)) == 0)","tryCatchPattern":null,"preventionTips":["Constrain upscale to {2,3,4,8} at config load time","Reject or clamp computed scale values before HAT construction"],"tags":["super-resolution","hat","upscale","config","valueerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}