[ROCm] Degenerate Conv3d (stride == kernel_size) on RDNA4 is ~70000x slower than the equivalent GEMM (vision tower patch_embed)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend, performance
Research direction
Start by reading comfy/model_management.py for the ROCm cuDNN setting and comfy/ops.py around Conv3d._conv_forward; the issue proposes a narrowly guarded path for degenerate Conv3d shapes. Check related issues #15895 and #14215, then compare the conv and linear outputs across the stated fp16 and fp32 cases. Done means the proposed shapes use the equivalent linear operation and other Conv3d cases retain their existing path.
Written by the indexing model from the issue text.
Description
Summary
On ROCm, ComfyUI sets torch.backends.cudnn.enabled = False for RDNA3+ GPUs (comfy/model_management.py), so torch conv falls back to MIOpen-less paths. For the degenerate Conv3d shapes used by Qwen-VL style vision towers (patch_embed with kernel_size == stride, no padding/dilation, groups == 1) this is catastrophic: cuDNN folds such a conv into a single GEMM, MIOpen does not, so it launches a few small kernels per output channel.
Measured on an RX 9070 XT: 28 695 ms → 0.401 ms for a single patch_embed call after dispatching the degenerate case to F.linear (mathematically identical, bit-exact).
Environment
- Radeon RX 9070 XT 16 GB (gfx1201 / RDNA4), Ryzen 7 5700X3D, 32 GB, Windows 11
- ComfyUI 0.46.0 · torch 2.14.0+rocm10.1.0 (HIP 7.16.26385) · comfy-kitchen 0.2.41
- MIOpen at ComfyUI default (disabled)
What is happening
The Qwen3-VL vision tower's patch_embed is
Conv3d(3 → C, kernel_size=(2,16,16), stride=(2,16,16)), and the reference image is fed as one sample per patch:
a 8 MP image becomes ~60 000 samples of shape (1, 16, 16), each producing exactly one output voxel.
So the conv is effectively a matrix multiply (N, in*kd*kh*kw) @ (in*kd*kh*kw, out).
cuDNN recognises this ("implicit GEMM" folding) — MIOpen on RDNA does not, and the cost explodes.
Minimal shape repro (sketch)
import torch, torch.nn.functional as F
torch.backends.cudnn.enabled = False # what ComfyUI does on RDNA3+
n, cin, cout, kd, kh, kw = 60000, 3, 1024, 2, 16, 16
x = torch.randn(n, cin, 1, kh, kw, device="cuda", dtype=torch.float16) # one sample per patch
w = torch.randn(cout, cin, kd, kh, kw, device="cuda", dtype=torch.float16)
b = torch.zeros(cout, device="cuda", dtype=torch.float16)
conv = torch.nn.Conv3d(cin, cout, kernel_size=(kd, kh, kw), stride=(kd, kh, kw), bias=True).cuda().half()
out_conv = conv(x) # ~28 s on gfx1201
out_lin = F.linear(x.reshape(n, -1), w.reshape(cout, -1), b) # ~0.4 ms
# out_conv.view(n, cout) and out_lin agree bit-exactly here
Proposed fix
A shape guard on Conv3d._conv_forward: when stride == kernel_size, padding == (0,0,0), dilation == (1,1,1),
groups == 1 and the output is a single voxel per sample, compute
F.linear(x.reshape(N, -1), w.reshape(K, -1), bias) and reshape back to (N, K, 1, 1, 1).
- Every other conv (all the VAE ones,
stride != kernel_size) keeps the existing path untouched. - Mathematically identical: measured
max|conv − matmul| == 0.0for both fp16 and fp32 (bit-exact). - Applies to any quantised / mixed-precision Conv3d subclass that inherits the base
_conv_forward. - CUDA is unaffected — this only fires on the exotic shapes, and on CUDA cuDNN already folds them.
Measurements (same box, same workflow, A/B)
Vision tower (patch_embed single call): 28 695 ms → 0.401 ms; whole vision tower 29.5 s → 0.15 s.
End-to-end, MiniMax H3 image workflow (8 MP output, two 3872×2176 reference images):
| configuration | node time |
|---|---|
| no patches | 101.840 s |
| this fix only | 62.191 s (−38.9 %, 1.64×) |
| VAE patch (#17906) only | 71.743 s |
| both | 33.428 s |
(The VAE side of that last row is Comfy-Org/ComfyUI#17906; this issue is only about the degenerate-conv dispatch.
More numbers, the MIOpen on/off cross-check and accuracy data are in my comment on #17906.)
Reference-image cost note: with this fix the vision tower stops dominating, and the panel-side reference short edge becomes the main lever
(736 px → 21.7 s, 1024 px → 40.6 s on the same workflow).
Related
- #15895 (H3 crashing on ROCm in this conv)
- #14215 (same idea upstream, but gated on fp16/bf16 — fp32 vision towers never hit it)
- pytorch #165141 / #169857 (AMD acknowledges incomplete MIOpen/CK implicit-GEMM support on Radeon)
- Comfy-Org/ComfyUI#17906 (the VAE-side counterpart; measured in the same session)
Availability
Working implementation (with check/apply/revert, guarded so it refuses to write on unknown code) is in
vae_conv_patch.py of my custom-node repo: https://github.com/lxmsqm/ComfyUI-BlackRin/blob/main/vae_conv_patch.py
(the same file also carries the #17906 changes; the degenerate-conv block is appended at the end of comfy/ops.py).
Happy to open a proper PR with just the degenerate-conv guard if the approach looks acceptable.
- Dominant language
- Python
- Stars
- 150k
- Forks
- 17.9k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 181
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Comfy-Org/ComfyUI
-
UnboundLocalError on a dangling symlink in custom_nodesPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Feature
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
ModelMergeSimple and all merge nodes are O(N²)Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Comfy-Org/ComfyUI#17823 · 1 reaction ·
Maintainers usually reply within 1 day
-
[Ascend NPU] Trellis2 shape stage aborts: aten::max.dim has no INT32 kernel (EZ1001)Possibly taken @harmehak0173 claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
All issues in Comfy-Org/ComfyUI
Similar issues
-
Test: to_hijri() accepts datetime.datetime and uses only the date partPossibly taken A pull request linked to this issue is open or already merged. Opengood first issue
Difficulty 1/5 Under an hour Newbie friendliness 95/100
omarelshamy25x/shamy-hijri#63 · 3 comments ·
Maintainers usually reply within 1 day
-
polish
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
521xueweihan/HelloGitHub#4729 ·
-
[Bug]: Score parser reads parts of scientific notation as valid scoresPossibly taken @AshutoshSingh840 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
UKGovernmentBEIS/control-arena#992 ·
Maintainers usually reply within 3 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
mvalentsev/awesome-free-ai-coding#70 ·
Maintainers usually reply within 1 day