Skip to content

Unsloth Studio (AMD/ROCm): don't turn on cudnn.benchmark for image and video generation - #11732

Merged
oobabooga merged 3 commits into
unslothai:mainfrom
LeoBorcherding:fix/rocm-no-cudnn-benchmark
Sep 24, 2026
Merged

oobabooga merged 3 commits into
unslothai:mainfrom
LeoBorcherding:fix/rocm-no-cudnn-benchmark

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Fixes #11636.

apply_speed_optims sets torch.backends.cudnn.benchmark = True for any load on device "cuda", which includes ROCm. There the flag makes MIOpen run its exhaustive search for every new conv shape, and a VAE decode is a run of large, unseen conv shapes, so the first image at a resolution sits in tuning after the last denoise step. On Windows that was 9.5 minutes on an R9700 and 23 minutes followed by a device crash on a gfx1030 (#11636 has both logs).

The flag is now skipped when torch.version.hip is set. MIOpen's default find mode still picks a kernel, just without the exhaustive trial runs. CUDA is unchanged. Image and video both go through this path.

Verification

check result, at 9f1e5fd
tests/test_diffusion_speed.py 62 passed, including a new test that a HIP torch leaves the flag off
first decode, Qwen-Image-2.1 GGUF Q4_K_M, 1280x736, R9700 (gfx1201), Windows 11, ROCm 7.13 before: 9.5 min. After: not run yet
gfx1030 crash not reproduced; no gfx1030 here

Not in scope: diffusion LoRA training sets the same flag in diffusion_train_common.py:1695; whether it costs the same on ROCm is untested.

…d video generation

On ROCm the flag makes MIOpen run its exhaustive search for every new conv
shape, so the first VAE decode at a resolution tuned for 10 to 23 minutes
and crashed a gfx1030. CUDA is unchanged.
@oobabooga

Copy link
Copy Markdown
Member

@codex review

@oobabooga

Copy link
Copy Markdown
Member

I added one commit, c3ffacd. It uses the repo's shared ROCm check, which also catches AMD builds that only mark ROCm in the torch version string.

Tested on a Strix Halo machine (Linux and Windows):

  • Before this PR, the image decode took about 4 to 5 minutes after every Studio restart.
  • With this PR, it takes about 4 seconds after a restart.
  • Once warmed up, decodes run at the same speed either way.

The first decode on a fresh install, before MIOpen has cached anything, still takes about 4 to 5 minutes, so #11636 is only partly fixed. A new image size after that was not tested, and neither was an R9700 or a gfx1030.

CI on the same commit is green on Linux, Mac and Windows: https://github.com/oobabooga/unsloth/pull/295/checks

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

ran the after on the R9700 row from #11636, one generation each, Qwen-Image-2.1 GGUF Q4_K_M, 1024x1024, 20 steps, seed 1, group offload, fp8 text encoder. torch 2.11.0+rocm7.13.0, Windows 11.

code speed end to end MIOpen user db
main at 89ed32d, before this PR Off 41 s, image returned not written
this PR at c3ffacd default (channels_last, fp16_accum, compiled_dequant engaged) 54 s, image returned not written

the db check is the one that matters: ~/.miopen/db/gfx1201_32.HIP.3_5_1_02d4f738fc.ufdb.txt kept its mtime from the earlier tuned run through both, so no search happened on either. same box that took 9.5 min in the decode at default speed on 0.1.813-beta (1280x736, in the issue body).

not re-run: default speed on the pre-fix code at this resolution. it would start the search on fresh shapes and the last one of those reset the gpu on the reporter's card. the Speed Off row is also the first run of the released-build workaround on any of the affected cards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

3 participants