Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix: hand MIOpen contiguous conv2d inputs in the ROCm conv3d decompositions
Lincoln Stein6c259bb249e9
diff --git a/invokeai/backend/minimax_h3/rocm_causal_conv3d.py b/invokeai/backend/minimax_h3/rocm_causal_conv3d.pyindex 7caac3eabf..84fd82868b 100644--- a/invokeai/backend/minimax_h3/rocm_causal_conv3d.py+++ b/invokeai/backend/minimax_h3/rocm_causal_conv3d.py@@ -37,7 +37,14 @@ def _decomposed_conv3d(module: torch.nn.Conv3d, x: torch.Tensor) -> torch.Tensort_out = t - k_t + 1out = Nonefor k in range(k_t):- xs = x[:, :, k : k + t_out].transpose(1, 2).reshape(b * t_out, c, h, w)+ # The conv2d input MUST be standard-NCHW contiguous. At B=1 (every real encode) the+ # reshape below is satisfiable as a zero-copy VIEW whose channel stride (T*H*W) exceeds+ # its batch stride (H*W) — a legal but exotic layout. Old MIOpen copied such inputs+ # internally; the MIOpen shipped with torch's rocm7.2 wheels consumes the strides+ # directly and mis-addresses rows whenever H != W (observed as horizontal line/tearing+ # artifacts in the Wan VAE's identical decomposition; this encoder shares the bug for+ # non-square canvases). The explicit copy costs a small fraction of the conv itself.+ xs = x[:, :, k : k + t_out].transpose(1, 2).reshape(b * t_out, c, h, w).contiguous()o = F.conv2d(xs, module.weight[:, :, k], None)out = o if out is None else out + oassert out is not Nonediff --git a/invokeai/backend/wan/rocm_causal_conv3d.py b/invokeai/backend/wan/rocm_causal_conv3d.pyindex 77d30f4548..ea5a3833d6 100644--- a/invokeai/backend/wan/rocm_causal_conv3d.py+++ b/invokeai/backend/wan/rocm_causal_conv3d.py@@ -34,7 +34,15 @@ def _decomposed_conv3d(module: torch.nn.Conv3d, x: torch.Tensor) -> torch.Tensort_out = t - k_t + 1out = Nonefor k in range(k_t):- xs = x[:, :, k : k + t_out].transpose(1, 2).reshape(b * t_out, c, h, w)+ # The conv2d input MUST be standard-NCHW contiguous. At B=1 (every real decode) the+ # reshape below is satisfiable as a zero-copy VIEW whose channel stride (T*H*W) exceeds+ # its batch stride (H*W) — a legal but exotic layout. Old MIOpen copied such inputs+ # internally; the MIOpen shipped with torch's rocm7.2 wheels consumes the strides+ # directly and mis-addresses rows whenever H != W, producing horizontal line/tearing+ # artifacts in decoded images. (At B > 1 the reshape is forced to copy, which is why+ # the corruption never appeared in batched paths.) The explicit copy costs a small+ # fraction of the conv itself.+ xs = x[:, :, k : k + t_out].transpose(1, 2).reshape(b * t_out, c, h, w).contiguous()o = F.conv2d(xs, module.weight[:, :, k], None)out = o if out is None else out + oassert out is not Nonediff --git a/tests/backend/minimax_h3/test_rocm_causal_conv3d.py b/tests/backend/minimax_h3/test_rocm_causal_conv3d.pyindex bb2fdbb115..159ad4f94d 100644--- a/tests/backend/minimax_h3/test_rocm_causal_conv3d.py+++ b/tests/backend/minimax_h3/test_rocm_causal_conv3d.py@@ -80,3 +80,25 @@ def test_class_patch_is_idempotent_and_preserves_behavior() -> None:MiniMaxH3VideoCausalConv3d.forward = stock_forwardif hasattr(MiniMaxH3VideoCausalConv3d, "_invokeai_rocm_conv2d_decomposition"):delattr(MiniMaxH3VideoCausalConv3d, "_invokeai_rocm_conv2d_decomposition")+++def test_decomposed_conv3d_feeds_contiguous_conv2d_inputs(monkeypatch) -> None:+ """At B=1 (every real encode) the tap reshape can be satisfied as a zero-copy view whose+ channel stride exceeds its batch stride. The MIOpen shipped with torch's rocm7.2 wheels+ mis-addresses rows of such inputs when H != W (observed as horizontal tearing via the Wan+ VAE's identical decomposition), so conv2d must receive standard-contiguous tensors."""+ import invokeai.backend.minimax_h3.rocm_causal_conv3d as mod++ seen: list[bool] = []+ original_conv2d = mod.F.conv2d++ def checked_conv2d(x: torch.Tensor, *args, **kwargs) -> torch.Tensor:+ seen.append(x.is_contiguous())+ return original_conv2d(x, *args, **kwargs)++ monkeypatch.setattr(mod.F, "conv2d", checked_conv2d)+ conv = torch.nn.Conv3d(6, 10, kernel_size=(3, 3, 3))+ x = torch.randn(1, 6, 5, 12, 16) # B=1 and H != W: the exotic-view case+ _decomposed_conv3d(conv, x)+ assert seen, "decomposition never called conv2d"+ assert all(seen), "conv2d received a non-contiguous input"diff --git a/tests/backend/wan/test_rocm_causal_conv3d.py b/tests/backend/wan/test_rocm_causal_conv3d.pyindex 9bb533706d..cae7673cbd 100644--- a/tests/backend/wan/test_rocm_causal_conv3d.py+++ b/tests/backend/wan/test_rocm_causal_conv3d.py@@ -87,3 +87,25 @@ def test_class_patch_is_idempotent_and_preserves_behavior() -> None:WanCausalConv3d.forward = stock_forwardif hasattr(WanCausalConv3d, "_invokeai_rocm_conv2d_decomposition"):delattr(WanCausalConv3d, "_invokeai_rocm_conv2d_decomposition")+++def test_decomposed_conv3d_feeds_contiguous_conv2d_inputs(monkeypatch: pytest.MonkeyPatch) -> None:+ """At B=1 (every real decode) the tap reshape can be satisfied as a zero-copy view whose+ channel stride exceeds its batch stride. The MIOpen shipped with torch's rocm7.2 wheels+ mis-addresses rows of such inputs when H != W (horizontal tearing in decoded images), so+ the decomposition must hand conv2d standard-contiguous tensors."""+ import invokeai.backend.wan.rocm_causal_conv3d as mod++ seen: list[bool] = []+ original_conv2d = mod.F.conv2d++ def checked_conv2d(x: torch.Tensor, *args, **kwargs) -> torch.Tensor:+ seen.append(x.is_contiguous())+ return original_conv2d(x, *args, **kwargs)++ monkeypatch.setattr(mod.F, "conv2d", checked_conv2d)+ conv = torch.nn.Conv3d(6, 10, kernel_size=(3, 3, 3))+ x = torch.randn(1, 6, 5, 12, 16) # B=1 and H != W: the exotic-view case+ _decomposed_conv3d(conv, x)+ assert seen, "decomposition never called conv2d"+ assert all(seen), "conv2d received a non-contiguous input"