SeedVR2 VAE on ROCm: the fp16 channels-last path is about 3x slower and 2-3x larger than the standard-layout path when MIOpen is off
Current behavior
- On ROCm with MIOpen off (the default on RDNA3 and newer) and without
--fast fp16_accumulation, the SeedVR2 VAE's fp16 path (_ck_eligibleincomfy/ldm/seedvr/vae.py) keeps activations inchannels_last_3dand convolves whole slices withF.conv3d. PyTorch's conv then builds a column buffer of about 24-27x the input for the whole slice: 16 GiB for a 0.7 GiB input, 32 GiB for 1.4 GiB. - The slice plan treats fp16 as that path with CUDA-fitted figures (
_eager_factorreturns 1 for fp16), so it plans about 6 GiB for a decode that peaks at 66 GiB. - The standard-layout path that other dtypes already take is faster and much smaller on the same GPU, because
memory_limit_convsplits any conv input above 0.5 GiB and so bounds the column buffer.
This is the same cause described in the comments on #17508 for a Radeon AI PRO R9700. I am filing it as an issue because nothing tracks it, and to add numbers from a second AMD GPU plus a small fallback that works without comfy-kitchen changes. Related: #17436.
Measurements
Strix Halo, Radeon 8060S (gfx1151), 105 GiB GPU-visible memory, Linux, ComfyUI v0.45.0, torch 2.14.0+rocm10.1.0, comfy-kitchen 0.2.41, MIOpen off. comfy.sd.VAE with seedvr2_ema_vae_fp16.safetensors, called standalone with autograd off (so without the memory compiler), second run of each. Peak is torch.cuda.max_memory_allocated().
| Clip | Path | Encode | Decode | Peak |
|---|---|---|---|---|
| 9 frames, 512x512 | stock | 4.5 s | 12.6 s | 35.4 GiB |
| 9 frames, 512x512 | standard layout | 2.1 s | 4.3 s | 15.3 GiB |
| 25 frames, 512x512 | stock | 12.2 s | 37.8 s | 66.4 GiB, after one failed 61.6 GiB allocation |
| 25 frames, 512x512 | standard layout | 5.3 s | 11.8 s | 20.7 GiB |
| 25 frames, 512x512 | stock with fp16 accumulation (kitchen HIP conv) | 2.8 s | 8.1 s | 31.7 GiB |
| 9 frames, 960x1024 | standard layout | 7.2 s | 16.3 s | 23.6 GiB |
| 9 frames, 960x1024 | stock with fp16 accumulation (kitchen HIP conv) | 3.6 s | 10.3 s | 43.1 GiB |
- "Standard layout" is
_ck_eligiblereturning False. Its output matches the stock path to fp16 rounding: latents agree to 81 dB and decodes of the same latent to 74-77 dB. - With
_eager_factorapplied to fp16 as well, the plan for the 25-frame decode is about 32 GiB, which covers the 20.7 GiB peak. - The kitchen conv is the fastest of the three, but two convs per pass still go to
F.conv3dand set the peak. That is consistent with the 3-channel convs being declined, as reported in #17508; I did not confirm which layers they are. - In the server, 1 s (24 frames) of a 540x720 clip upscaled 2x with the 3B INT8 model and
VAEEncodeTiled/VAEDecodeTiledat tile 1024, overlap 64 takes 127 s with the standard layout.
Workaround in use
Appended to comfy/ldm/seedvr/vae.py:
if torch.version.hip:
def _ck_eligible(x):
return False
def _eager_factor(dtype, factor):
return factor * dtype.itemsize / 2
As written this also turns the kitchen conv off, so it is not a patch for upstream.
Request
On ROCm, when the kitchen fp16 conv is not in use (no fp16 accumulation), take the standard-layout path for fp16 and plan it with the eager factors. The kitchen route can stay as it is for users who opt in.
Thanks for the detailed SeedVR2 performance measurements on ROCm/Strix Halo.
I've investigated this issue through NH Applied Doctor and developed a candidate source-level correction against ComfyUI v0.45.0.
Findings
The current SeedVR2 VAE code appears to have two related behaviours:
_ck_eligible()selects thechannels_last_3dFP16 convolution path on HIP even when FP16 accumulation has not been enabled._eager_factor()returns1for all FP16 tensors, including configurations where the standard-layout fallback requires a different memory-planning factor.
This may explain why the existing HIP FP16 path consumes substantially more memory than the standard-layout fallback reported here.
Proposed correction
Restrict the accelerated layout on HIP to configurations where FP16 accumulation is explicitly enabled:
def _ck_eligible(x):
return (
x.is_cuda
and x.dtype == torch.float16
and x.dim() == 5
and (
not torch.version.hip
or _fp16_accumulate_wanted(x)
)
)
Adjust the corresponding FP16 memory estimate:
def _eager_factor(dtype, factor):
if dtype == torch.float16:
if (
torch.version.hip
and not getattr(
torch.backends.cuda.matmul,
"allow_fp16_accumulation",
False,
)
):
return factor * dtype.itemsize / 2
return 1
return factor * dtype.itemsize / 2
Local qualification
The candidate has undergone controlled testing on AMD Strix Halo:
- 42/42 helper-function tests passed.
- 20/20 independent static diagnostic tests passed.
- Existing NVIDIA behaviour was preserved in the controlled tests.
- The HIP accelerated path remains available when FP16 accumulation is enabled.
- The patch changes only the two identified helper functions.
Important limitation: These results validate the proposed source-level behaviour. I have not yet completed a real SeedVR2 VAE GPU decode using the patched code, so I cannot independently confirm the reported memory reduction, performance improvement or numerical accuracy.
Maintainer feedback requested
Would this conditional HIP fallback be an acceptable direction for an upstream fix?
In particular, is preserving the existing NVIDIA path and the explicitly enabled HIP FP16-accumulation path the preferred approach?
I can provide the isolated patch and qualification evidence for review. Further GPU validation would be required before claiming the issue is resolved.
This investigation uses AI-assisted engineering with locally executed, independently checked tests.
Nigel Hutchinson
Independent AI Systems Research & Engineering
NH Applied — Software Compatibility Diagnosis, Repair & Qualification
Website: https://nhapplied.co.uk/
Contact: [email protected]
I ran the code from the comment above through real SeedVR2 VAE encodes and decodes, with fp16 accumulation off and on.
Setup, as in the issue: Radeon 8060S (gfx1151), Linux, ComfyUI v0.45.0, torch 2.14.0+rocm10.1.0, comfy-kitchen 0.2.41, MIOpen off, system power profile balanced. comfy.sd.VAE with seedvr2_ema_vae_fp16.safetensors, called standalone with autograd off (so without the memory compiler), one tile per clip, second run of each. Peak is torch.cuda.max_memory_allocated().
| Clip | fp16 accumulation | Encode | Decode | Peak | Output |
|---|---|---|---|---|---|
| 25 frames, 512x512 | off | 5.2 s | 11.7 s | 20.7 GiB | bit-identical to the workaround in the issue |
| 25 frames, 512x512 | on | 2.7 s | 8.0 s | 31.7 GiB | bit-identical to stock |
| 9 frames, 1024x1024 | off | 7.7 s | 17.2 s | 24.9 GiB | bit-identical to the workaround in the issue |
| 9 frames, 1024x1024 | on | 3.8 s | 11.0 s | 38.9 GiB | bit-identical to stock |
So both branches behave as intended, and the numbers in the issue hold for this code. I did not run it through the server.
It leaves one thing open with fp16 accumulation on: the plan still uses factor 1 there, 8.9 GiB and 13.8 GiB for the whole decode of these two clips, against peaks of 31.7 GiB and 38.9 GiB. The peak is set inside the one conv that still goes to F.conv3d, the decoder's final 128-to-3-channel conv, called twice per decode; every other conv goes to the kitchen kernel. That corrects the issue text, where I guessed two convs were declined.
Follow-up: full-model Windows ROCm 10.1 qualification of the proposed two-helper patch now passes, including a reversed-order repeat. This updates my earlier comment, which only had source-level tests at the time.
Setup: Radeon 8060S / gfx1151 (Strix Halo), Windows, pinned ComfyUI v0.45.0 (commit 989d93d0), PyTorch 2.14.0+rocm10.1.0, comfy-kitchen 0.2.41, MIOpen disabled, fp16 accumulation OFF. The test used the actual Comfy-Org/SeedVR2 seedvr2_ema_vae_fp16.safetensors (LFS SHA-256 20678548f420d98d26f11442d3528f8b8c94e57ee046ef93dbb7633da8612ca1), deterministic input, and separate original/patched source trees and Python processes. Peaks are torch.cuda.max_memory_allocated().
| Full VAE workload | Original | V38 candidate |
|---|---|---|
| 25 × 512² decode peak | 66.38 GiB | 20.71 GiB |
| Decode 1 | 47.23 s | 12.00 s |
| Decode 2 (reverse execution order) | 43.54 s | 12.01 s |
| Encode peak | 33.83 GiB | 15.30 GiB |
| Encode 1 / 2 | 13.78 / 13.47 s | 6.13 / 6.09 s |
| 9 × 512² decode peak | 35.40 GiB | 15.28 GiB |
| 9-frame decode | 12.82 s | 4.47 s |
This is a reproducible 68.8% reduction in 25-frame decode peak allocated GPU memory and 3.78× average decode speed-up across the two 25-frame runs. The full unpatched and patched output arrays were compared; 25-frame decode RMSE was 0.000846 and encode RMSE 0.000737 (close but not bit-identical). Within each variant, both 25-frame repeats gave identical output-file hashes and peak-memory figures. All runs used real model weights and real ROCm GPU kernels, not stubs or isolated conv3d microbenchmarks.
This independently matches @bogdan-d's published Linux ROCm 10.1 20.7 GiB fallback measurement. Their follow-up also verified the accumulation-ON branch and identified the remaining memory planner underestimate from the final decoder 128→3 F.conv3d; our Windows V39 runs did not test that accelerated branch.
Scope: one original/candidate pair at 9 frames and two pairs at 25 frames; local torch allocator peaks, not whole-system RAM; no production ComfyUI server test. The original installed ComfyUI and Doctor's qualified release were not modified.
I can provide the exact two-function unified diff and the hash-bound local GPU qualification receipts for review. Would a PR limited to the confirmed accumulation-OFF correction be welcome, with the accumulation-ON planner issue handled separately?
Nigel Hutchinson | NH Applied — https://nhapplied.co.uk | [email protected]
Further NH Applied follow-up — the remaining fp16-accumulation-ON memory spike now has an independently measured, bounded source fix (V40F).
Following @bogdan-d's Linux confirmation, I reproduced the residual high-memory path on Strix Windows, using the same pinned ComfyUI v0.45.0, PyTorch 2.14.0+rocm10.1.0, kitchen 0.2.41, Radeon 8060S/gfx1151, MIOpen off, actual seedvr2_ema_vae_fp16.safetensors weights and a 25-frame 512×512 clip.
Precise fallback: With fp16 accumulation ON, comfy_kitchen.backends.hip.fp16_conv3d_out declines the final RGB 128→3 output convolution because its kernel requires output channels divisible by 8. It then invokes whole-slice F.conv3d at comfy_kitchen/backends/hip/__init__.py:2158. An instrumented full VAE decode observed exactly two such calls, on inputs [1,128,19,514,514] and [1,128,10,514,514], with weights [3,128,3,3,3]. They set the 31.73 GiB allocator peak. The call stack reaches this fallback through fp16_conv3d_out from SeedVR2's InflatedCausalConv3d._ck_buffered (not _ck_conv).
Candidate: Inside _ck_buffered's for z0 in range(0, zt, chunk) loop, only for HIP with accumulation ON, no residual, exact [3,128,3,3,3] weight and unit stride, replace this declined kitchen call with bounded-width F.conv3d bands. Each band reads the appropriate two-column kernel halo and copies into the already allocated out[:, :, z0:z1, :, col:end]. Derive band width from a 256 MiB input-window budget. All other kitchen-accelerated convolutions retain the original code. This is an isolated V38-plus-V40F source candidate, not an installed ComfyUI or kitchen modification.
Full-model Windows GPU results (fp16 accumulation ON):
| 25 frames, 512×512 | Existing V38 code | V40F bounded final conv |
|---|---|---|
| Peak decode allocation | 31.73 GiB | 7.96 GiB |
| Decode time | 9.41 s | 8.88 s, repeat 8.92 s |
| Encode | Unchanged | Bit-identical output |
That's 74.9% less peak allocated GPU memory. The two V40F full-model runs had identical output hashes and peak memory. Full-array decode comparison to the existing accumulated path: RMSE 0.00000669; maximum absolute error 0.000244 over 19.7 million elements. It is numerically close, not bit-identical.
Compatibility check: With accumulation OFF, V40F produced bit-identical encode and decode output hashes and identical allocator peaks to the previously verified V38 fallback (20.71 GiB peak on this 25-frame workload). Source, model, device, seed and runtime were matched. All receipts and patch files are hash-bound and preserved in the NH Applied Doctor V40 lab.
I also tested simply padding the RGB output channels to 8/16/32; kitchen acceptance was shape-dependent, so that is not a safe generic substitute.
Would you be willing to verify this bounded _ck_buffered branch on Linux, especially when accumulation is enabled? I can provide the exact unified diff and test receipts. Maintainer guidance on whether this should be a separate PR from the original two-function V38 correction would also be valuable.
Nigel Hutchinson | NH Applied — https://nhapplied.co.uk — [email protected]
Scope: two 25-frame Windows GPU runs with accumulation ON and one compatibility run OFF; original installed ComfyUI, driver and Doctor release unchanged. No upstream merge or other-GPU qualification is claimed.
Yes, I can run it on Linux. Please post the diff against v0.45.0 (the second change on top of the first is fine). I will run it on the setup above with fp16 accumulation on and off, on the same two clips, and report peak, time and the difference from the current output.
One note for whoever picks this up: the whole-slice fallback is in comfy-kitchen's HIP backend (fp16_conv3d, the torch.nn.functional.conv3d call taken when the kernel declines a shape), so bounding it there would cover every caller, without a special case for this weight shape in vae.py.
@bogdan-d Thanks for offering to verify this on Linux. The complete diff against ComfyUI v0.45.0 is now in PR #17826 — Files changed, with the source pinned to commit 1250d05.
The PR includes the original _ck_eligible / _eager_factor correction and the additional bounded final-convolution change inside InflatedCausalConv3d._ck_buffered. That latter change is the one to evaluate with FP16 accumulation ON: for the exact HIP 128→3 RGB 3×3×3 output convolution (no residual, unit stride), it runs width bands with two-column halos instead of the declined kitchen operation's whole-slice F.conv3d. The most recent follow-up also corrects host-offload planning for standard-layout HIP FP16 tails when accumulation is OFF.
On Windows gfx1151 / PyTorch 2.14+ROCm 10.1 / kitchen 0.2.41 / MIOpen OFF, for 25 frames at 512×512 with the official SeedVR2 EMA VAE weights:
- Accumulation ON: 31.73 GiB → 7.96 GiB PyTorch peak allocated during decode with the bounded convolution; 9.41 s → ~8.9 s. The output is numerically close, not bit-identical (RMSE 6.69e-6, max absolute error 0.000244).
- Accumulation OFF: 20.71 GiB peak, and encode/decode output hashes and peak allocations were unchanged after the bounded-convolution change. A subsequent planner-only fix also passed another full 25-frame GPU encode/decode regression with both outputs bit-identical to the prior candidate.
It would be especially useful to run your same 25×512² and 9×1024² clips, both accumulation OFF and ON, measuring decode peak allocation, time, output differences versus your previous reference, and any OOM/error. Please include the exact commit, and feel free to avoid the larger case if resource limits make it unsafe. I have not reproduced the new bounded-convolution change on Linux or another GPU, so your independent result would be decisive.
Your ownership observation is valid: changing comfy-kitchen's declined-shape fallback could address more callers. The PR deliberately keeps this first repair limited to the specific SeedVR2 convolution whose shape and memory behaviour we reproduced; upstream maintainers can decide whether to generalise in kitchen.
Thanks again for the independent testing.
Nigel Hutchinson — NH Applied
https://nhapplied.co.uk
[email protected]