{"record":{"id":"63c829c4a3b6124f","repo":"invoke-ai/InvokeAI","slug":"hidiffusion-warning-the-feature-size-is-h-w","errorCode":null,"errorMessage":"HiDiffusion Warning: The feature size is {(H, W)} and cannot be directly partitioned into windows. We interpolate the size to {(window_size[0] * 2, window_size[1] * 2)} to enable the window partition. Even though the generation is OK, the image quality would be largely decreased. We suggest removing window attention by setting apply_hidiffusion(pipe, apply_window_attn=False) for better image quality.","messagePattern":"HiDiffusion Warning: The feature size is (.+?) and cannot be directly partitioned into windows\\. We interpolate the size to (.+?) to enable the window partition\\. Even though the generation is OK, the image quality would be largely decreased\\. We suggest removing window attention by setting apply_hidiffusion\\(pipe, apply_window_attn=False\\) for better image quality\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"invokeai/backend/hidiffusion/hidiffusion.py","lineNumber":1341,"sourceCode":"            timestep: Optional[torch.LongTensor] = None,\n            cross_attention_kwargs: Dict[str, Any] = None,\n            class_labels: Optional[torch.LongTensor] = None,\n            added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,\n        ) -> torch.FloatTensor:\n            # reference: https://github.com/microsoft/Swin-Transformer\n            def window_partition(x, window_size, shift_size, H, W):\n                \"\"\"\n                Args:\n                    x: (B, H, W, C)\n                    window_size (int): window size\n\n                Returns:\n                    windows: (num_windows*B, window_size, window_size, C)\n                \"\"\"\n                B, N, C = x.shape\n                x = x.view(B, H, W, C)\n                if H % 2 != 0 or W % 2 != 0:\n                    warnings.warn(\n                        f\"HiDiffusion Warning: The feature size is {(H, W)} and cannot be directly partitioned into windows. We interpolate the size to {(window_size[0] * 2, window_size[1] * 2)} \"\n                        f\"to enable the window partition. Even though the generation is OK, the image quality would be largely decreased. \"\n                        f\"We suggest removing window attention by setting apply_hidiffusion(pipe, apply_window_attn=False) for better image quality.\",\n                        stacklevel=2,\n                    )\n                    x = (\n                        F.interpolate(\n                            x.permute(0, 3, 1, 2).contiguous(),\n                            size=(window_size[0] * 2, window_size[1] * 2),\n                            mode=\"bicubic\",\n                        )\n                        .permute(0, 2, 3, 1)\n                        .contiguous()\n                    )\n                if type(shift_size) is list or type(shift_size) is tuple:\n                    if shift_size[0] > 0:\n                        x = torch.roll(x, shifts=(-shift_size[0], -shift_size[1]), dims=(1, 2))\n                else:","sourceCodeStart":1323,"sourceCodeEnd":1359,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/backend/hidiffusion/hidiffusion.py#L1323-L1359","documentation":"HiDiffusion's window attention partitions feature maps into fixed windows; when the feature height or width is odd it cannot be evenly partitioned, so the code warns, resizes to the nearest even size (window_size*2), and proceeds. The generation still runs but image quality degrades, so the warning recommends disabling window attention via `apply_hidiffusion(pipe, apply_window_attn=False)`.","triggerScenarios":"Calling `window_partition` (through attention forward) with an intermediate feature map whose H or W is odd — typically caused by a generated image resolution whose downsampling chain produces odd-sized feature maps under HiDiffusion.","commonSituations":"Using an unusual output resolution (e.g. non-multiple-of-64 dimensions) with HiDiffusion enabled; enabling window attention (`apply_window_attn=True`, the default) on a model/resolution combination that yields odd feature sizes; changing resolution or up/downscale factors mid-pipeline.","solutions":["Call `apply_hidiffusion(pipe, apply_window_attn=False)` to disable window attention","Choose a resolution whose feature maps stay even (dimensions that are multiples of the stride/window size, e.g. 64)","Adjust the upscaling/downsampling factors in the HiDiffusion config so intermediate H and W remain even"],"exampleFix":"# before\npipe = apply_hidiffusion(pipe, apply_window_attn=True)  # warns on odd feature sizes\n# after\npipe = apply_hidiffusion(pipe, apply_window_attn=False)","handlingStrategy":"try-catch","validationCode":"def feature_sizes_ok(image_size, downscale_factor):\n    h = image_size[0] // downscale_factor\n    w = image_size[1] // downscale_factor\n    return h % 2 == 0 and w % 2 == 0\n\nassert feature_sizes_ok((height, width), downscale_factor), \"choose even feature-map dimensions or disable window attention\"","typeGuard":null,"tryCatchPattern":"import warnings\nwith warnings.catch_warnings(record=True) as caught:\n    warnings.simplefilter(\"always\")\n    run_hidiffusion_pipeline(pipe)\n    if any(\"cannot be directly partitioned\" in str(w.message) for w in caught):\n        print(\"HiDiffusion window attention degraded quality; rerun with apply_window_attn=False\")","preventionTips":["Use resolutions that are multiples of the stride/window size (e.g. multiples of 64)","Set apply_hidiffusion(pipe, apply_window_attn=False) when using unusual resolutions","Treat this warning as a quality bug, not noise — fix resolution instead of ignoring it","Log warnings in CI when generating at new resolutions to catch odd feature sizes early"],"tags":["warning","hidiffusion","resolution","window-attention","image-quality"],"backgroundTag":"resolution-not-divisible","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}