{"record":{"id":"322a2494bfc3ba65","repo":"Comfy-Org/ComfyUI","slug":"must-flatten-output","errorCode":null,"errorMessage":"Must flatten output.","messagePattern":"Must flatten output\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/genmo/joint_model/layers.py","lineNumber":149,"sourceCode":"        )\n\n    def forward(self, x):\n        B, _C, T, H, W = x.shape\n        if not self.dynamic_img_pad:\n            assert H % self.patch_size[0] == 0, f\"Input height ({H}) should be divisible by patch size ({self.patch_size[0]}).\"\n            assert W % self.patch_size[1] == 0, f\"Input width ({W}) should be divisible by patch size ({self.patch_size[1]}).\"\n        else:\n            pad_h = (self.patch_size[0] - H % self.patch_size[0]) % self.patch_size[0]\n            pad_w = (self.patch_size[1] - W % self.patch_size[1]) % self.patch_size[1]\n            x = F.pad(x, (0, pad_w, 0, pad_h))\n\n        x = rearrange(x, \"B C T H W -> (B T) C H W\", B=B, T=T)\n        x = comfy.ldm.common_dit.pad_to_patch_size(x, self.patch_size, padding_mode='circular')\n        x = self.proj(x)\n\n        # Flatten temporal and spatial dimensions.\n        if not self.flatten:\n            raise NotImplementedError(\"Must flatten output.\")\n        x = rearrange(x, \"(B T) C H W -> B (T H W) C\", B=B, T=T)\n\n        x = self.norm(x)\n        return x\n","sourceCodeStart":131,"sourceCodeEnd":154,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/genmo/joint_model/layers.py#L131-L154","documentation":"The Mochi patch embedder only implements the flatten=True path: after patch projection it rearranges tokens to (B, T*H*W, C). The flatten=False branch deliberately raises NotImplementedError, so any construction with flatten=False cannot run a forward pass.","triggerScenarios":"Building PatchEmbed/joint-model patchify layer with flatten=False (e.g. copying upstream genmo code that exposes the option) and then calling forward(). The upstream repo defaults to flatten=True, so this arises almost only via manual construction.","commonSituations":"Porting Mochi tooling that passes an explicit flatten flag; experiment code that wants unflattened spatial tokens (B,C,T,H,W) out of the patch embed.","solutions":["Construct the patch embedder with flatten=True (the default and only supported path).","If you need spatial tokens, take the flattened (B, THC, C) output and rearrange it yourself afterwards.","Patch the module locally to implement the unflattened return if your research code truly needs it."],"exampleFix":"# before\nPatchEmbed(..., flatten=False)\n\n# after\nPatchEmbed(..., flatten=True)  # then rearrange downstream if spatial layout is needed","handlingStrategy":"validation","validationCode":"assert flatten is True, \"Mochi PatchEmbed only supports flatten=True\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not pass flatten=False when constructing the genmo patch embedder.","Rearrange the flattened output downstream if a spatial layout is needed."],"tags":["mochi","genmo","not-implemented","patch-embed"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}