{"record":{"id":"8dd4020540a1fee9","repo":"Comfy-Org/ComfyUI","slug":"unknown-patch-method-self-patch-method","errorCode":null,"errorMessage":"Unknown patch method: {self.patch_method}","messagePattern":"Unknown patch method: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"comfy/ldm/cosmos/cosmos_tokenizer/patching.py","lineNumber":71,"sourceCode":"        self.register_buffer(\n            \"wavelets\", _WAVELETS[patch_method], persistent=_PERSISTENT\n        )\n        self.range = range(int(torch.log2(torch.tensor(self.patch_size)).item()))\n        self.register_buffer(\n            \"_arange\",\n            torch.arange(_WAVELETS[patch_method].shape[0]),\n            persistent=_PERSISTENT,\n        )\n        for param in self.parameters():\n            param.requires_grad = False\n\n    def forward(self, x):\n        if self.patch_method == \"haar\":\n            return self._haar(x)\n        elif self.patch_method == \"rearrange\":\n            return self._arrange(x)\n        else:\n            raise ValueError(\"Unknown patch method: \" + self.patch_method)\n\n    def _dwt(self, x, mode=\"reflect\", rescale=False):\n        dtype = x.dtype\n        h = self.wavelets.to(device=x.device)\n\n        n = h.shape[0]\n        g = x.shape[1]\n        hl = h.flip(0).reshape(1, 1, -1).repeat(g, 1, 1)\n        hh = (h * ((-1) ** self._arange.to(device=x.device))).reshape(1, 1, -1).repeat(g, 1, 1)\n        hh = hh.to(dtype=dtype)\n        hl = hl.to(dtype=dtype)\n\n        x = F.pad(x, pad=(n - 2, n - 1, n - 2, n - 1), mode=mode).to(dtype)\n        xl = F.conv2d(x, hl.unsqueeze(2), groups=g, stride=(1, 2))\n        xh = F.conv2d(x, hh.unsqueeze(2), groups=g, stride=(1, 2))\n        xll = F.conv2d(xl, hl.unsqueeze(3), groups=g, stride=(2, 1))\n        xlh = F.conv2d(xl, hh.unsqueeze(3), groups=g, stride=(2, 1))\n        xhl = F.conv2d(xh, hl.unsqueeze(3), groups=g, stride=(2, 1))","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/cosmos/cosmos_tokenizer/patching.py#L53-L89","documentation":"Patcher (forward patchify) in the Cosmos tokenizer supports two methods: 'haar' (learned-free Haar wavelet via _haar) and 'rearrange' (space-to-depth via _arrange). The method is fixed from the patch_method config string at construction; any other value raises 'Unknown patch method' on the first forward call. The valid names are keys of the _WAVELETS table ( haar wavelet) plus the plain rearrange path.","triggerScenarios":"Constructing cosmos_tokenizer Patcher with patch_method like 'db2', 'haar-learned', or 'space2depth' - e.g. loading a Cosmos tokenizer checkpoint variant that stores a different wavelet name in its config.","commonSituations":"Loading Cosmos-Predict2 or custom VAE/tokenizer checkpoints with wavelet configs beyond haar; porting configs from NVIDIA's cosmos repo where more wavelets exist in _WAVELETS; typos in custom configs.","solutions":["Set patch_method to 'haar' or 'rearrange' exactly","Verify the tokenizer checkpoint config; if it names another wavelet, use a ComfyUI version that maps it","For custom wavelets, add the wavelet to _WAVELETS and a matching forward branch in a fork"],"exampleFix":"# before\nPatcher(patch_method=\"db2\", patch_size=patch_size)\n\n# after\nPatcher(patch_method=\"haar\", patch_size=patch_size)","handlingStrategy":"validation","validationCode":"if patch_method not in {\"haar\", \"rearrange\"}:\n    raise ValueError(f\"patch_method {patch_method!r} unsupported; use 'haar' or 'rearrange'\")","typeGuard":"def is_supported_patch_method(m: str) -> bool:\n    return m in {\"haar\", \"rearrange\"}","tryCatchPattern":null,"preventionTips":["Use the tokenizer checkpoint's stored patch_method unmodified","Check the _WAVELETS keys in cosmos_tokenizer/patching.py before choosing a wavelet name"],"tags":["cosmos","tokenizer","wavelet","config"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}