{"record":{"id":"bfe49fdcdda249ef","repo":"lllyasviel/Fooocus","slug":"padding-layer-s-is-not-implemented","errorCode":null,"errorMessage":"padding layer [{:s}] is not implemented","messagePattern":"padding layer \\[(.+?)\\] is not implemented","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"ldm_patched/pfn/architecture/block.py","lineNumber":63,"sourceCode":"    else:\n        raise NotImplementedError(\n            \"normalization layer [{:s}] is not found\".format(norm_type)\n        )\n    return layer\n\n\ndef pad(pad_type: str, padding):\n    # helper selecting padding layer\n    # if padding is 'zero', do by conv layers\n    pad_type = pad_type.lower()\n    if padding == 0:\n        return None\n    if pad_type == \"reflect\":\n        layer = nn.ReflectionPad2d(padding)\n    elif pad_type == \"replicate\":\n        layer = nn.ReplicationPad2d(padding)\n    else:\n        raise NotImplementedError(\n            \"padding layer [{:s}] is not implemented\".format(pad_type)\n        )\n    return layer\n\n\ndef get_valid_padding(kernel_size, dilation):\n    kernel_size = kernel_size + (kernel_size - 1) * (dilation - 1)\n    padding = (kernel_size - 1) // 2\n    return padding\n\n\nclass ConcatBlock(nn.Module):\n    # Concat the output of a submodule to its input\n    def __init__(self, submodule):\n        super(ConcatBlock, self).__init__()\n        self.sub = submodule\n\n    def forward(self, x):","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/block.py#L45-L81","documentation":"block.pad() creates the padding layer: 'reflect' -> ReflectionPad2d, 'replicate' -> ReplicationPad2d, and anything else raises NotImplementedError. Zero padding is deliberately not handled here (the comment says 'if padding is zero, do by conv layers') - conv blocks are expected to carry the padding themselves, so pad_type='zero' is also rejected.","triggerScenarios":"Calling pad('zero', 1), pad('symmetric', 2), or pad('', 3) - any pad_type outside {'reflect','replicate'} with a non-zero padding amount. Note: if padding == 0 the function returns None before the check, so the error only fires when actual padding is requested with an unsupported type.","commonSituations":"Real-ESRGAN configs commonly specify pad_type: zero - porting them into this vendored code without changing the value; configs requesting 'symmetric' padding available in other forks.","solutions":["Use 'reflect' or 'replicate', or set padding=0 so the function returns None and lets conv layers handle zero padding","For 'zero' configs: drop the explicit pad layer and put the padding into the following nn.Conv2d(padding=...)"],"exampleFix":"# before\np = B.pad('zero', 1)  # -> NotImplementedError\n\n# after: zero pad via the conv itself\nconv = nn.Conv2d(64, 64, 3, 1, 1)  # padding=1 IS the zero padding\nblock = nn.Sequential(conv)","handlingStrategy":"validation","validationCode":"def sanitize_pad(pad_type, padding):\n    if padding == 0:\n        return None\n    p = pad_type.lower()\n    assert p in ('reflect', 'replicate'), f\"pad_type must be reflect/replicate (zero padding belongs in the conv), got {pad_type!r}\"\n    return p\n\n# Real-ESRGAN configs often say 'zero': translate instead of failing\nif cfg.get('pad_type') == 'zero':\n    cfg['pad_type'] = 'reflect'; cfg['padding'] = 0  # conv supplies zero pad","typeGuard":"def is_supported_pad(pad_type: str) -> bool:\n    return pad_type.lower() in ('reflect', 'replicate')","tryCatchPattern":null,"preventionTips":["Zero padding is handled by the conv layer, not pad(): use padding=0 for the pad helper","Translate Real-ESRGAN 'pad_type: zero' configs before passing them to this code"],"tags":["super-resolution","padding","block","config","notimplementederror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}