ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

ComfyUI crashes the whole Linux OS (AMD GPU)

Open cavac opened this issue 8 months ago • 9 comments

Custom Node Testing

Expected Behavior

Not crashing

Actual Behavior

I run Ubuntu 24.04 with 64G RAM and an Radeon RX 7800 XT GPU. ComfyUI was installed yesterday, v0.18.0 and rocm7.1.

No matter which template i use, the system will eventually crash. Text-to-Image takes a few runs. Animating an image crashes the system within a minute.

For thermal testing, i ran the GPU fan at full speed. When the crash happens, the fan turns off for a few seconds (and the screen goes blank). Screen and fan come back, but the system is locked up.

ComfyUI also uses way to much RAM. I had to add 20GB of swap just to run through like 3 or 4 text-to-image runs before running into problems. This memory leak issue may or may not be a separate problem.

This does NOT seem to be a hardware issue. I can run both Easy Diffusion and many demanding games (Satisfactory, U-Boat, Skyrim "whatever the newest edition is", Minecraft with high end renderers, Hogwards, ...) for hours on end without any problems. I can also run long, CPU-demanding tasks as well without problems, like compiling.

Steps to Reproduce

See above

Debug Logs

I don't have them because the whole system crashes.

Other

ComfyUI seems to be pretty unusable (in any mode) on my system for now. I'm going back to EasyDiffusion for the moment.

cavac avatar Mar 22 '26 11:03 cavac

For what it's worth, similar setup here with 7900XTX, though the OS is spared most of the time. This is a new thing in the 0.17 and 0.18 releases for me, stuff used to work better in the past.

Sometimes Comfy does lock the whole thing up. I don't have swap at all (64GB should be plenty) and when a ~121 frame LTX gen nears completion, Comfy fills my RAM from ~70% to 99% and usually manages to just quit itself. Sometimes not, and the system becomes unresponsive entirely.

Try --reserve-vram 1.0 and --disable-smart-memory and see if it helps for you? This seems to allow me to run a few more image gens before having to restart Comfy. No idea why.

ghost avatar Mar 22 '26 16:03 ghost

Same here (7900 XTX, Linux Mint, 64GB system ram) : see #12762 When I run with --disable-smart-memory, then the flow still crashes, but it no longer locks up the computer, you get proper OOM handling.

Disabling MIOpen helps a little, but only to a point. export COMFYUI_ENABLE_MIOPEN=0 export MIOPEN_ENABLE_LOGGING=0 export MIOPEN_FIND_MODE=DYNAMIC_HYBRID export MIOPEN_DEBUG_CONV_DIRECT=0 export MIOPEN_DEBUG_CONV_DIRECT_NAIVE_CONV_FWD=0

For me, the cause is that the default settings (running comfyui without parameters) uses --use-pytorch-cross-attention When I run with --use-quad-cross-attention, then I no longer have issues, even when using high resolutions. But it does run a little bit slower than --use-pytorch-cross-attention.

AlfredSartan572 avatar Mar 22 '26 20:03 AlfredSartan572

Looking at the reports in this thread, the most effective combo for AMD on recent ComfyUI versions seems to be: python main.py --use-quad-cross-attention --disable-smart-memory

The key one is --use-quad-cross-attention. The default pytorch cross-attention path seems to hit something on RDNA GPUs that escalates to system-level crashes rather than just application errors. Quad attention avoids that path entirely, a bit slower but stable even at higher resolutions from what others have reported.

The memory spike you're seeing (needing 20GB swap) is probably related. --disable-smart-memory prevents ComfyUI from keeping multiple models in VRAM simultaneously, should help with that.

This looks like a regression introduced in the 0.17/0.18 range.

chejh-amd avatar Mar 25 '26 02:03 chejh-amd

I believe I have a related (if not the exact same) problem with my AMD Radeon RX 6700/6700 XT/6750. I do have a log for it.

When trying to generate higher resolution images: at what seems to be nearing the end of the process, I get a graphics reset due to GPU hang combined with a Python crash. --use-quad-cross-attention --disable-smart-memory does help slightly in the sense that instead of crashing on the first lag, it crashes on the fourth - but I do not get an entire system freeze, though that may be due to how my Linux distribution handles it (EndeavourOS).

Also I do not think this is necessarily a ComfyUI bug, because I moved to SwarmUI - which uses ComfyUI - 2 days ago because my Automatic 1111 suddenly had this same issue described above, although it worked fine before.

log.txt

Rodrigo22Borgia avatar Mar 26 '26 06:03 Rodrigo22Borgia

The Torch 2.13 nightly build fixed the issue for me. I just upgraded from the Torch 2.11 stable release and now everything works smoothly. I'm not sure exactly what changed, but Gnome desktop doesn't stutter anymore and doesn't freeze up or black screen requiring a hard reset. Here's the setup that currently works for me:

pytorch version: 2.13.0.dev20260420+rocm7.2
AMD arch: gfx1100
ROCm version: (7, 2)
Set vram state to: NORMAL_VRAM
Device: cuda:0 Radeon RX 7900 XTX : native
...
Python version: 3.13.7
ComfyUI version: 0.19.3
comfy-aimdo version: 0.2.12
comfy-kitchen version: 0.2.8
$ amd-smi version
AMDSMI Tool: 26.2.2+671d39a71e | AMDSMI Library version: 26.2.2 | ROCm version: 7.2.2 | amdgpu version: Linuxversion6.17.0-22-generic(buildd@lcy02-amd64-082)(x86_64-linux-gnu-gcc(Ubuntu15.2.0-4ubuntu4)15.2.0,GNUld(GNUBinutilsforUbuntu)2.45)#22-UbuntuSMPPREEMPT_DYNAMICFriMar1312:04:44UTC2026

Here are the only changes I made since my last desktop freeze.

  1. Install the latest ROCm version. I'm pretty sure this is not what fixed the issue because Torch has ROCm included, but maybe it helps somebody.
  2. Activate the Python environment for ComfyUI.
  3. Install the nightly torch packages and include --upgrade so it overwrites ComfyUI's default Torch version: pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm7.2 --upgrade
  4. Change to the ComfyUI directory: cd ./ComfyUI/
  5. Pull the latest ComfyUI changes from Git: git fetch && git pull
  6. Install the latest requirements: pip install -r requirements.txt

I was really surprised when I came back to my computer and found that my test job finished without freezing up my desktop. I tried every major version from Torch 2.8 with ROCm 6.4 all the way to Torch 2.11 with ROCm 7.2 and was never able to complete any jobs that pushed VRAM usage beyond 90%.

As part of previous fix attempts, I also use the environment variables listed here: https://gist.github.com/alexheretic/d868b340d1cef8664e1b4226fd17e0d0

I'm also using --disable-pinned-memory --use-quad-cross-attention but that might not be necessary anymore, so I'm going to try flash attention again and see if some of the environment variables can be changed or removed.

Here is the start script that currently works for me:

#!/bin/bash

. comfy-venv/bin/activate

export PYTORCH_NO_HIP_MEMORY_CACHING=1

export TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1
export FLASH_ATTENTION_TRITON_AMD_ENABLE=TRUE

export FLASH_ATTENTION_FWD_TRITON_AMD_CONFIG_JSON='{"BLOCK_M":128,"BLOCK_N":64,"waves_per_eu":1,"PRE_LOAD_V":false,"num_stages":1,"num_warps":8}'

export PYTORCH_MIOPEN_SUGGEST_NHWC=0

export COMFYUI_ENABLE_MIOPEN=1

export MIOPEN_FIND_MODE=FAST

python3 ComfyUI/main.py --enable-manager --disable-pinned-memory --use-quad-cross-attention

Update: Running ComfyUI with --use-flash-attention works but occasionally a job seems to get stuck on a node. At least the desktop isn't freezing and everything continues to run without a hard reset.

dwightjl avatar Apr 22 '26 06:04 dwightjl

The Torch 2.13 nightly build fixed the issue for me. I just upgraded from the Torch 2.11 stable release and now everything works smoothly. I'm not sure exactly what changed, but Gnome desktop doesn't stutter anymore and doesn't freeze up or black screen requiring a hard reset. Here's the setup that currently works for me:

pytorch version: 2.13.0.dev20260420+rocm7.2
AMD arch: gfx1100
ROCm version: (7, 2)
Set vram state to: NORMAL_VRAM
Device: cuda:0 Radeon RX 7900 XTX : native
...
Python version: 3.13.7
ComfyUI version: 0.19.3
comfy-aimdo version: 0.2.12
comfy-kitchen version: 0.2.8
$ amd-smi version
AMDSMI Tool: 26.2.2+671d39a71e | AMDSMI Library version: 26.2.2 | ROCm version: 7.2.2 | amdgpu version: Linuxversion6.17.0-22-generic(buildd@lcy02-amd64-082)(x86_64-linux-gnu-gcc(Ubuntu15.2.0-4ubuntu4)15.2.0,GNUld(GNUBinutilsforUbuntu)2.45)#22-UbuntuSMPPREEMPT_DYNAMICFriMar1312:04:44UTC2026

Here are the only changes I made since my last desktop freeze.

  1. Install the latest ROCm version. I'm pretty sure this is not what fixed the issue because Torch has ROCm included, but maybe it helps somebody.
  2. Activate the Python environment for ComfyUI.
  3. Install the nightly torch packages and include ---upgrade so it overwrites ComfyUI's default Torch version: pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm7.2 --upgrade
  4. Change to the ComfyUI directory: cd ./ComfyUI/
  5. Pull the latest ComfyUI changes from Git: git fetch && git pull
  6. Install the latest requirements and include the --upgrade flag so it doesn't roll Torch back to an older version: pip install -r requirements.txt --upgrade

I was really surprised when I came back to my computer and found that my test job finished without freezing up my desktop. I tried every major version from Torch 2.8 with ROCm 6.4 all the way to Torch 2.11 with ROCm 7.2 and was never able to complete any jobs that pushed VRAM usage beyond 90%.

As part of previous fix attempts, I also use the environment variables listed here: https://gist.github.com/alexheretic/d868b340d1cef8664e1b4226fd17e0d0

I'm also using --disable-pinned-memory --use-quad-cross-attention but that might not be necessary anymore, so I'm going to try flash attention again and see if some of the environment variables can be changed or removed.

Here is the start script that currently works for me:

#!/bin/bash

. comfy-venv/bin/activate

export PYTORCH_NO_HIP_MEMORY_CACHING=1

export TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1
export FLASH_ATTENTION_TRITON_AMD_ENABLE=TRUE

export FLASH_ATTENTION_FWD_TRITON_AMD_CONFIG_JSON='{"BLOCK_M":128,"BLOCK_N":64,"waves_per_eu":1,"PRE_LOAD_V":false,"num_stages":1,"num_warps":8}'

export PYTORCH_MIOPEN_SUGGEST_NHWC=0

export COMFYUI_ENABLE_MIOPEN=1

export MIOPEN_FIND_MODE=FAST

python3 ComfyUI/main.py --enable-manager --disable-pinned-memory --use-quad-cross-attention

Update: Running ComfyUI with --use-flash-attention works but occasionally a job seems to get stuck on a node. At least the desktop isn't freezing and everything continues to run without a hard reset.

Nice find, the fact that Torch 2.13 nightly alone got you past the freeze point is a strong hint the root cause was in the PyTorch ROCm attention path, not ComfyUI itself — lines up with what others saw when switching to quad attention as a workaround.

chejh-amd avatar Apr 23 '26 02:04 chejh-amd

My system is still stable and able to run batches of jobs for several hours without any issue. However, a few workloads and even specific loras still seem to cause desktop crashes. It's not a VRAM capacity issue because some workloads run fine bumping up against 100% usage. Sometimes smaller loras cause a crash and a larger lora from the same repository works fine.

I suspected my overclocked system memory might be the issue so I de-clocked it to default DDR5 4200 speeds, but that didn't help anything. At least my system handles the crashes more gracefully now; taking me back to my desktop login rather than completely freezing my screen or giving me a black screen.

I'm using the same environment variables as before, but my start command is now just: python3 ComfyUI/main.py --use-flash-attention --normalvram --async-offload

Update: Another tip is just never run Chrome or Chromium while using ComfyUI workloads. Even with GPU acceleration turned off in the browser settings, some workloads crash if the browser is running anything or even just sitting in the background with no tabs open. Brave browser is fine even though it is also Chromium-based. It's bizarre. Some workloads are perfectly stable while Chromium is open and others are not. I upgraded Ubuntu so I'm running torch-2.13.0.dev20260425+rocm7.2-cp314 now to work with Python 3.14. My start arguments are --use-flash-attention --async-offload --cache-ram 4 --normalvram with the same envrionment variables listed above. I added the --cache-ram argument just to help prevent some workloads from using swap space and slowing down to a crawl, but not for stability reasons.

dwightjl avatar Apr 24 '26 05:04 dwightjl

Hi everyone, I am having the same issues with Linux Ubuntu 26.04 and AMD Radeon RX 7800 XT GPU. Is anyone aware if there will be any fixes for this issue in the future?

Thanks.

dzambasbale avatar May 12 '26 10:05 dzambasbale

Hi everyone, I am having the same issues with Linux Ubuntu 26.04 and AMD Radeon RX 7800 XT GPU. Is anyone aware if there will be any fixes for this issue in the future?

Thanks.

I'm also on 26.04 now with the 7900XTX and I've managed to make ComfyUI run mostly stable. It is more likely to fail gracefully with an OOM message rather than completely crash, but it seems to be workload-specific. I suspect ComfyUI or Pytorch has trouble estimating how much VRAM it needs and sometimes it fails poorly rather than giving an OOM message and just kills the whole desktop.

The best advice I can give you for now is:

  1. Follow the steps I suggested earlier: https://github.com/Comfy-Org/ComfyUI/issues/13109#issuecomment-4294103158 I've been running well with torch-2.13.0.dev20260425+rocm7.2-cp314 specifically, but I would expect the newer nightly builds from May to also work fine.
  2. Try this startup script. I've found the newer Pytorch and ROCm versions don't require many environment variables or start arguments. Sage attention works well if you install the sageattention 1.0.6 package, but it will cook your VRAM. Flash attention also works.
    export FLASH_ATTENTION_TRITON_AMD_ENABLE=TRUE
    export COMFYUI_ENABLE_MIOPEN=1
    export MIOPEN_FIND_MODE=FAST
    export PYTORCH_TUNABLEOP_ENABLED=1
    
    python3 ComfyUI/main.py --enable-manager --disable-smart-memory --reserve-vram 3.0 --use-pytorch-cross-attention #--use-sage-attention --use-flash-attention
    
  3. Keep an eye on VRAM use. I use LACT which should be available in your default software repos. Use a smaller GGUF if your models are loading partially and offload more than 1-2GiB. It should still run faily well even with a little bit of offload but don't push it too hard. Either ComfyUI or Pytorch attempts to reserve VRAM to hold the data you are processing, so you might try adjusting workloads to require less VRAM space for data if you continue to crash or get OOMs.
  4. Keep an eye on system memory and swap use. Add --cache-none to your startup script if workloads are thrashing your swap. Use vmstat 1 to see your memory and swap read/write.

Again, a lot of this depends on your workload. If you're loading models completely and still crashing at ~70% of VRAM use, send me your workload and I'll see if I can reproduce it. Some things might just not play well on AMD and there's not much we can do about it.

dwightjl avatar May 16 '26 09:05 dwightjl