{"record":{"id":"a4e791b858063962","repo":"lllyasviel/Fooocus","slug":"wrong-sample-mode-self-sample-mode-supported-on","errorCode":null,"errorMessage":"Wrong sample mode {self.sample_mode}, supported ones are ['upsample', 'downsample', None].","messagePattern":"Wrong sample mode (.+?), supported ones are \\['upsample', 'downsample', None\\]\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ldm_patched/pfn/architecture/face/stylegan2_arch.py","lineNumber":255,"sourceCode":"\n        if self.sample_mode == \"upsample\":\n            self.smooth = UpFirDnSmooth(\n                resample_kernel,\n                upsample_factor=2,\n                downsample_factor=1,\n                kernel_size=kernel_size,\n            )\n        elif self.sample_mode == \"downsample\":\n            self.smooth = UpFirDnSmooth(\n                resample_kernel,\n                upsample_factor=1,\n                downsample_factor=2,\n                kernel_size=kernel_size,\n            )\n        elif self.sample_mode is None:\n            pass\n        else:\n            raise ValueError(\n                f\"Wrong sample mode {self.sample_mode}, \"\n                \"supported ones are ['upsample', 'downsample', None].\"\n            )\n\n        self.scale = 1 / math.sqrt(in_channels * kernel_size**2)\n        # modulation inside each modulated conv\n        self.modulation = EqualLinear(\n            num_style_feat,\n            in_channels,\n            bias=True,\n            bias_init_val=1,\n            lr_mul=1,\n            activation=None,\n        )\n\n        self.weight = nn.Parameter(\n            torch.randn(1, out_channels, in_channels, kernel_size, kernel_size)\n        )","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/ldm_patched/pfn/architecture/face/stylegan2_arch.py#L237-L273","documentation":"In the StyleGAN2 face architecture, the modulated-conv block accepts sample_mode of 'upsample', 'downsample', or None, which selects the UpFirDnSmooth resampling filter. The else branch raises ValueError when the constructor receives any other value, i.e. a typo'd or unsupported resampling mode.","triggerScenarios":"Constructing StyleGAN's conv/ResBlock with sample_mode='up'/'down'/'bilinear'/'' instead of the exact strings 'upsample'/'downsample'/None (note the check compares the whole string; even 'Upsample' fails).","commonSituations":"Hand-writing a StyleGAN2 layer stack or porting config from a repo that spells modes differently ('up' vs 'upsample'); passing a string 'None' instead of the Python None when loading YAML/JSON configs.","solutions":["Use exactly 'upsample', 'downsample', or None (case-sensitive) for sample_mode.","If the value arrives from config text, normalize it: strip/lower the string and convert 'none'/'' to the None object before passing.","Check the neighboring layer definitions in stylegan2_arch.py for which mode each block expects and copy those literals."],"exampleFix":"# before\nModulatedConv2x(..., sample_mode='up')\n# after\nModulatedConv2x(..., sample_mode='upsample')","handlingStrategy":"validation","validationCode":"SAMPLE_MODES = ('upsample', 'downsample', None)\nif sample_mode not in SAMPLE_MODES:\n    raise ValueError(f'sample_mode must be in {SAMPLE_MODES}')","typeGuard":"def is_sample_mode(v) -> bool:\n    return v is None or v in ('upsample', 'downsample')","tryCatchPattern":null,"preventionTips":["When loading configs from text, map 'none'/'' to None and lowercase strings before passing to the layer.","Use the exact literals from the neighboring layer definitions; avoid abbreviations like 'up'/'down'."],"tags":["pytorch","stylegan","face-restoration","constructor-validation","resampling"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}