Comfy-Org/ComfyUI · critical · ValueError
Unknown patch method: {self.patch_method}
Error message
Unknown patch method: {self.patch_method} What it means
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.
Source
Thrown at comfy/ldm/cosmos/cosmos_tokenizer/patching.py:71
self.register_buffer(
"wavelets", _WAVELETS[patch_method], persistent=_PERSISTENT
)
self.range = range(int(torch.log2(torch.tensor(self.patch_size)).item()))
self.register_buffer(
"_arange",
torch.arange(_WAVELETS[patch_method].shape[0]),
persistent=_PERSISTENT,
)
for param in self.parameters():
param.requires_grad = False
def forward(self, x):
if self.patch_method == "haar":
return self._haar(x)
elif self.patch_method == "rearrange":
return self._arrange(x)
else:
raise ValueError("Unknown patch method: " + self.patch_method)
def _dwt(self, x, mode="reflect", rescale=False):
dtype = x.dtype
h = self.wavelets.to(device=x.device)
n = h.shape[0]
g = x.shape[1]
hl = h.flip(0).reshape(1, 1, -1).repeat(g, 1, 1)
hh = (h * ((-1) ** self._arange.to(device=x.device))).reshape(1, 1, -1).repeat(g, 1, 1)
hh = hh.to(dtype=dtype)
hl = hl.to(dtype=dtype)
x = F.pad(x, pad=(n - 2, n - 1, n - 2, n - 1), mode=mode).to(dtype)
xl = F.conv2d(x, hl.unsqueeze(2), groups=g, stride=(1, 2))
xh = F.conv2d(x, hh.unsqueeze(2), groups=g, stride=(1, 2))
xll = F.conv2d(xl, hl.unsqueeze(3), groups=g, stride=(2, 1))
xlh = F.conv2d(xl, hh.unsqueeze(3), groups=g, stride=(2, 1))
xhl = F.conv2d(xh, hl.unsqueeze(3), groups=g, stride=(2, 1))View on GitHub (pinned to 1c6d8d45b3)
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
Example fix
# before Patcher(patch_method="db2", patch_size=patch_size) # after Patcher(patch_method="haar", patch_size=patch_size)
Defensive patterns
Strategy: validation
Validate before calling
if patch_method not in {"haar", "rearrange"}:
raise ValueError(f"patch_method {patch_method!r} unsupported; use 'haar' or 'rearrange'") Type guard
def is_supported_patch_method(m: str) -> bool:
return m in {"haar", "rearrange"} Prevention
- Use the tokenizer checkpoint's stored patch_method unmodified
- Check the _WAVELETS keys in cosmos_tokenizer/patching.py before choosing a wavelet name
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Normalization {name} not found
- Normalization mode {self.qkv_norm_mode} not found, only supp
- Unknown pos_emb_cls {self.pos_emb_cls}
- Unknown interpolation method {self.interpolation}
- Unknown pos_emb_cls {self.pos_emb_cls}
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/8dd4020540a1fee9.
Report an issue: GitHub.