{"record":{"id":"74b341fe33e130f1","repo":"Comfy-Org/ComfyUI","slug":"unknown-x-format-self-blocks-0-x-format","errorCode":null,"errorMessage":"Unknown x_format {self.blocks[0].x_format}","messagePattern":"Unknown x_format (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/cosmos/model.py","lineNumber":410,"sourceCode":"            crossattn_mask = crossattn_mask[:, None, None, :]  # .to(dtype=torch.bool)  # [B, 1, 1, length]\n        else:\n            crossattn_mask = None\n\n        if self.blocks[\"block0\"].x_format == \"THWBD\":\n            x = rearrange(x_B_T_H_W_D, \"B T H W D -> T H W B D\")\n            if extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D is not None:\n                extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D = rearrange(\n                    extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D, \"B T H W D -> T H W B D\"\n                )\n            crossattn_emb = rearrange(crossattn_emb, \"B M D -> M B D\")\n\n            if crossattn_mask:\n                crossattn_mask = rearrange(crossattn_mask, \"B M -> M B\")\n\n        elif self.blocks[\"block0\"].x_format == \"BTHWD\":\n            x = x_B_T_H_W_D\n        else:\n            raise ValueError(f\"Unknown x_format {self.blocks[0].x_format}\")\n        output = {\n            \"x\": x,\n            \"affline_emb_B_D\": affline_emb_B_D,\n            \"crossattn_emb\": crossattn_emb,\n            \"crossattn_mask\": crossattn_mask,\n            \"rope_emb_L_1_1_D\": rope_emb_L_1_1_D,\n            \"adaln_lora_B_3D\": adaln_lora_B_3D,\n            \"original_shape\": original_shape,\n            \"extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D\": extra_pos_emb_B_T_H_W_D_or_T_H_W_B_D,\n        }\n        return output\n\n    def forward(\n        self,\n        x: torch.Tensor,\n        timesteps: torch.Tensor,\n        context: torch.Tensor,\n        attention_mask: Optional[torch.Tensor] = None,","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/cosmos/model.py#L392-L428","documentation":"After per-block processing, the Cosmos forward reshapes x back according to the x_format attribute of block0, which must be either 'THWBD' or 'BTHWD'. Any other string raises ValueError. The value is set by the block classes themselves, so this error indicates a custom/incompatible block implementation was injected into self.blocks.","triggerScenarios":"Replacing the transformer blocks list with custom blocks whose x_format attribute is neither 'THWBD' nor 'BTHWD' (e.g. a ported block using a different layout label), then running forward(). Note the format check reads self.blocks[\"block0\"].x_format while the error message formats self.blocks[0].x_format — a custom dict-like blocks object without integer indexing would itself fail first.","commonSituations":"Custom nodes that patch or replace Cosmos blocks for attention modifications; forks that add a new layout variant without updating this dispatch; inconsistent block sets where block0 differs from later blocks.","solutions":["Ensure every block in self.blocks uses x_format 'THWBD' or 'BTHWD' consistently with block0.","If you introduce a new layout in a custom block, also add a matching branch in the forward() reshape dispatch.","Use ComfyUI's model patcher hooks instead of swapping block classes, so stock block implementations are preserved."],"exampleFix":"# before (custom block)\nclass MyBlock(CrossAttention): x_format = \"BTDHW\"\n\n# after\nclass MyBlock(CrossAttention): x_format = \"BTHWD\"  # keep a layout the dispatch knows","handlingStrategy":"validation","validationCode":"fmt = model.blocks[\"block0\"].x_format\nassert fmt in (\"THWBD\", \"BTHWD\"), f\"block x_format {fmt!r} unsupported by Cosmos forward\"","typeGuard":"def blocks_use_known_layout(model) -> bool:\n    return model.blocks[\"block0\"].x_format in (\"THWBD\", \"BTHWD\")","tryCatchPattern":null,"preventionTips":["Prefer ComfyUI patcher hooks over replacing model block classes.","If you add a block layout, extend the forward dispatch in the same change.","Keep block sets homogeneous — all blocks should share block0's layout."],"tags":["cosmos","tensor-layout","custom-nodes","forward"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}