invoke-ai/InvokeAI · warning

HiDiffusion Warning: The feature size is {(H, W)} and cannot

Error message

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.

What it means

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)`.

Source

Thrown at invokeai/backend/hidiffusion/hidiffusion.py:1341

            timestep: Optional[torch.LongTensor] = None,
            cross_attention_kwargs: Dict[str, Any] = None,
            class_labels: Optional[torch.LongTensor] = None,
            added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,
        ) -> torch.FloatTensor:
            # reference: https://github.com/microsoft/Swin-Transformer
            def window_partition(x, window_size, shift_size, H, W):
                """
                Args:
                    x: (B, H, W, C)
                    window_size (int): window size

                Returns:
                    windows: (num_windows*B, window_size, window_size, C)
                """
                B, N, C = x.shape
                x = x.view(B, H, W, C)
                if H % 2 != 0 or W % 2 != 0:
                    warnings.warn(
                        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)} "
                        f"to enable the window partition. Even though the generation is OK, the image quality would be largely decreased. "
                        f"We suggest removing window attention by setting apply_hidiffusion(pipe, apply_window_attn=False) for better image quality.",
                        stacklevel=2,
                    )
                    x = (
                        F.interpolate(
                            x.permute(0, 3, 1, 2).contiguous(),
                            size=(window_size[0] * 2, window_size[1] * 2),
                            mode="bicubic",
                        )
                        .permute(0, 2, 3, 1)
                        .contiguous()
                    )
                if type(shift_size) is list or type(shift_size) is tuple:
                    if shift_size[0] > 0:
                        x = torch.roll(x, shifts=(-shift_size[0], -shift_size[1]), dims=(1, 2))
                else:

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Call `apply_hidiffusion(pipe, apply_window_attn=False)` to disable window attention
  2. Choose a resolution whose feature maps stay even (dimensions that are multiples of the stride/window size, e.g. 64)
  3. Adjust the upscaling/downsampling factors in the HiDiffusion config so intermediate H and W remain even

Example fix

# before
pipe = apply_hidiffusion(pipe, apply_window_attn=True)  # warns on odd feature sizes
# after
pipe = apply_hidiffusion(pipe, apply_window_attn=False)
Defensive patterns

Strategy: try-catch

Validate before calling

def feature_sizes_ok(image_size, downscale_factor):
    h = image_size[0] // downscale_factor
    w = image_size[1] // downscale_factor
    return h % 2 == 0 and w % 2 == 0

assert feature_sizes_ok((height, width), downscale_factor), "choose even feature-map dimensions or disable window attention"

Try / catch

import warnings
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    run_hidiffusion_pipeline(pipe)
    if any("cannot be directly partitioned" in str(w.message) for w in caught):
        print("HiDiffusion window attention degraded quality; rerun with apply_window_attn=False")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/63c829c4a3b6124f. Report an issue: GitHub.