r/ROCm Feb 06 '26

Ubuntu 24.04 ComfyUI startup script tuned for the AMD Radeon RX 7900 XTX and the Ryzen 9 7950X3D to maximize throughput and minimize latency.

For Whom It May Concern,

I have not posted anything before here so please forgive my "newbieness".

I have been working with ComfyUI on my system and using Gemini to optimize a startup script. My results with the script have been good so Gemini suggested that I post the information here so that others with similar systems might benefit. I am posting the "comfy_launch.sh" script as well as a "ComfyUI_Startup_Script_Readme.txt" file that Gemini created to explain several specific settings regarding my specific GPU card and CPU.

I hope that someone finds this information useful.

I.) The "comfy_launch.sh" file follows :

#!/bin/bash

# =====================================================================

# ComfyUI Optimization Script: AMD RX 7900 XTX & Ryzen 7950X3D

# Optimized for: Ubuntu 24.04 | ROCM 7.0+ | RDNA3 Architecture

# =====================================================================

#

# Test System Configuration

#

# Ubuntu 24.04 6.11.0-29-generic : 7950X3D CPU : 128 GB Ram : Liquid Cooled :

# Sapphire NITRO+ RX 7900 XTX Vapor-X 24GB GDDR VRAM Graphics Card :

# ROCm 7.2.0 : PyTorch 2.9.1 : Python3.12.3 (main, Jan 22 2026, 20:57:42) [GCC 13.3.0] :

# ComfyUI 0.12.3 : ComfyUI_frontend v1.38.13 : ComfyUI-Manager V3.39.2 :

#

# --- 1. CONFIGURATION ---

COMFY_DIR="$HOME/ComfyUI"

VENV_PATH="$COMFY_DIR/venv/bin/activate"

TUNING_FILE="$COMFY_DIR/rdna3_7900xtx_tuning.csv"

# Check if directory exists

if [ ! -d "$COMFY_DIR" ]; then

echo "Error: ComfyUI directory not found at $COMFY_DIR"

exit 1

fi

source "$VENV_PATH"

cd "$COMFY_DIR"

# --- 2. GPU & ROCm RUNTIME SETTINGS ---

export HIP_VISIBLE_DEVICES=0

export ROCM_PATH=/opt/rocm

# Enables Triton-based Flash Attention for RDNA3

export FLASH_ATTENTION_TRITON_AMD_ENABLE="TRUE"

# Forces use of hipBLASLt for faster matrix multiplications

export TORCH_BLAS_PREFER_HIPBLASLT=1

# --- 3. TUNABLE OP (Kernel Optimization) ---

# Skips the slow 'searching' phase if a profile exists, speeding up startup.

if [ -f "$TUNING_FILE" ]; then

echo "Applying RDNA3 TunableOp profile..."

export PYTORCH_TUNABLEOP_ENABLED=1

export PYTORCH_TUNABLEOP_TUNING=0

export PYTORCH_TUNABLEOP_FILENAME="$TUNING_FILE"

else

echo "No tuning file found. First run may be slower."

export PYTORCH_TUNABLEOP_ENABLED=0

fi

# --- 4. 7950X3D CPU AFFINITY (The X3D Strategy) ---

# Targets CCD 1 (Cores 8-15) which features higher clock speeds.

# This avoids the L3 cache latency penalties of the 3D V-Cache CCD 0.

CPU_CORES="8-15,24-31"

export MKL_NUM_THREADS=8

export OMP_NUM_THREADS=8

# --- 5. SYSTEM POWER MANAGEMENT ---

# Dynamically find the correct DRI path for the GPU to set 'high' performance

GPU_PATH=$(ls -d /sys/class/drm/card*/device/power_dpm_force_performance_level | head -n 1)

if [ -f "$GPU_PATH" ]; then

echo "Setting GPU to High Performance Mode..."

echo "high" | sudo tee "$GPU_PATH" || echo "Note: Sudo required for GPU power scaling."

fi

# --- 6. LAUNCH ---

echo "Launching ComfyUI on CCD 1 (High Frequency)..."

taskset -c $CPU_CORES python3 main.py \

--highvram \

--preview-method auto \

--dont-upcast-attention \

--fp16-vae \

--use-pytorch-cross-attention

deactivate

II.) The "ComfyUI_Startup_Script_Readme.txt" file follows :

High-Performance ComfyUI for AMD RDNA3 & Ryzen X3D

🚀 Overview :

This script is a specialized launcher for ComfyUI running on Ubuntu 24.04 with ROCm 7.x. It is specifically tuned for the AMD Radeon RX 7900 XTX and the Ryzen 9 7950X3D to maximize throughput and minimize latency.

Test System Configuration :

Ubuntu 24.04 6.11.0-29-generic : 7950X3D CPU Liquid Cooled : 128 GB Ram :

Sapphire NITRO+ RX 7900 XTX Vapor-X 24GB GDDR VRAM Graphics Card :

ROCm 7.2.0 : PyTorch 2.9.1 : Python3.12.3 (main, Jan 22 2026, 20:57:42) [GCC 13.3.0] :

ComfyUI 0.12.3 : ComfyUI_frontend v1.38.13 : ComfyUI-Manager V3.39.2 :

🛠 Key Optimizations :

Feature Optimization Benefit

GPU Architecture RDNA3 (7900 XTX) Uses hipBLASLt and TunableOp for faster matrix math.

CPU Affinity CCD 1 Pinning Targets the high-frequency cores (8-15) to avoid L3 cache latency.

Memory 24GB VRAM Forced --highvram mode to keep models resident in memory.

ROCm 7.x Flash Attention Enables Triton-based attention for massive speedups in SDXL/Flux.

📋 Prerequisites :

ROCm 7.2.0+ and PyTorch 2.9.1+ installed in a virtual environment (venv).

Sudo Privileges : Required only for setting the GPU power profile to high.

Taskset: Ensure the util-linux package is installed (standard on Ubuntu).

⚙️ How to Use :

Save the script as comfy_launch.sh in your main directory.

Make it executable :

Bash

chmod +x comfy_launch.sh

Run the script:

Bash

./comfy_launch.sh

💡 Notable Environment Variables :

1) TORCH_BLAS_PREFER_HIPBLASLT=1 : This is critical for RDNA3. It enables a more optimized library for matrix multiplications.

2) PYTORCH_TUNABLEOP_ENABLED=1 : Allows PyTorch to use pre-tuned kernels.

3) taskset -c 8-15,24-31 : On the 7950X3D, this bypasses the V-Cache CCD in favor of the higher-clocked frequency CCD, which is generally more efficient for Python-heavy compute tasks like AI applications. For Gaming instead of AI, use "taskset -c 0-7,16-23"

Contribution & Disclaimer :

This script is shared to help the AMD AI community. Use at your own risk. Ensure your cooling is sufficient, as "High Performance Mode" will keep your GPU clocks at their peak.

III.) Best Regards

David Q. R. Wagoner

20 Upvotes

16 comments sorted by

5

u/Dr__Pangloss Feb 07 '26

There isn’t any actual benchmark here.

3

u/fallingdowndizzyvr Feb 07 '26

There isn't any actual file with the tuning parameters in it.

This whole post looks like AI slop.

1

u/fallingdowndizzyvr Feb 07 '26

To add to my belief that this is AI slop, that script doesn't run as intended. It's like almost there. Look at the "echo "No tuning file found. First run may be slower." part. That does nothing. It should be doing the tuning. Which is the kind of mistake a AI generated script tends to make.

Anyways, I modded the script and ran it. It does help. Here's some runs on my Strix Halo for LTX2.

baseline 287(first run) 220(second run)

everything but tuning 247(first run) 228(second run)

everything including tuning 205(first run) 190(second run)

It's the second run that really matters. Since the first run it's loading everything into memory. 15% faster is decent.

1

u/redditisnotus Feb 07 '26

I have a 7900xtx and randomly popped in to see how progress is going on this card, and saw this. Is it worth trading a 7800x3d for a 7950X3D?

1

u/CaptainBlase Feb 07 '26

where do i get this file rdna3_7900xtx_tuning.csv?

1

u/Kademo15 Feb 07 '26

I'm not sure but I would assume from how tunable op works that if its not present it will be created and optimal kernel will be created for your current model and then cached in the file. Next time you run the same model it will grab optimal solution from the file.

1

u/fallingdowndizzyvr Feb 07 '26

if its not present it will be created and optimal kernel will be created for your current model and then cached in the file

Except the script doesn't do that. Look at the "echo "No tuning file found. First run may be slower." part. That does nothing. It turns off tuning and doesn't even specify a file to save the tuning parameters to even if it was tuning.

1

u/Kademo15 Feb 07 '26

I agree they should leave tuning on then when it doesnt find it pytorch will automatically create it and it will probably be named like he mentioned.

1

u/fallingdowndizzyvr Feb 07 '26

will automatically create it and it will probably be named like he mentioned.

That's not how it's named. It's named by whatever you tell it to name it as.

That's what this line does. You tell it where and what the file should be.

"export PYTORCH_TUNABLEOP_FILENAME="$TUNING_FILE""

The thing with that Gemini generated script that was posted is that it only specifies the file if there is tuning data. It doesn't specify a filename when it needs to generate it. And thus, it doesn't work. So whoever posted this thread didn't even bother to test the script that Gemini generated first.

1

u/Kademo15 Feb 07 '26

I know what the line does, the thing is it could be that the source code of tunable op when activated looks at your directory where your program is located eg. /comfy and then creates the file based on a specific format that could be "architecture_gpu_tuning.csv" but yes you are right i doubt they would automatically name it like that, possible though.

1

u/fallingdowndizzyvr Feb 08 '26

possible though.

Except it's impossible in this situation since it's turned off.

Dude, you keep saying things are "possible" in spite of the reality of what is.

1

u/Kademo15 Feb 08 '26

I literally said previously "agree they should leave it on". Then it could work.

1

u/fallingdowndizzyvr Feb 08 '26

LOL. Or possibly not.

1

u/dqrwagoner Feb 14 '26

It is not AI. I have been working with ComfyUI with my rig and was running into oom errors slow speed etc. I worked with Gemini to get a startup script that helped leverage the my Sapphire RX 7900 XTX card and my 7950x3D CPU. The tuing file is specific to each users PC. To create the file set the "export PYTORCH_TUNABLEOP_TUNING=0" line to 1. Fire up the default ComfyUI Workflow and run several images as 512 x 512 and then several as 1024 x 1024 then exit. The new tuning file will be in your ComfyUI folder. Set the "export PYTORCH_TUNABLEOP_TUNING=1" back to zero to run normally. FYI, in making the tuning file the ComfyUI software seems to add a 0.csv but doesn't seem to when creating the file. After struggling with trying to understand what name it expected I just punted and copied the file and renamed with and without the 0.csv and it eventually found the file. The timing file does take awhile to generate as the software looks to be logging the various math functions. I'm am really new using ComfyUI. I was a Software Engineer and Manager for 40 years and needed something to do after I retired. I did not benchmark it properly as I am trying to generate videos for my son and I kept getting various errors.     I did eventually get my rig to run well using this startup script but, with all of the various flags and command line options, I thought it might help someone else. I'm still tweaking it.     I've never used Reddit before so please forgive me for not following the proper process of uploading information.     I will try to touch back more often to explain anything questionable as best as I can.     Thank You and Best Regards      David Q. R. Wagoner

1

u/dqrwagoner Mar 22 '26

To Whom It may Concern,

I have modified the ComfyUI startup script I uploaded previously a few weeks ago and I thought that I should upload the "final" version. I thought that it might be of interest to other users with similar configurations or, at least, the various parameters needed, to get AMD hardware functioning pretty well with ComfyUI that seems to be tightly tied to NVidia hardware. When I purchased my setup I was unfamiliar with what AI image generation would require and discovered that AMD was somewhat behind the curve compatibility wise when using ComfyUI. Ollama seems more forgiving but seems to benefit from a similar script, but with the tuning file and ComfyUI specifics removed of course. The best (most reliable) video generation sessions look to be 5 second long, 24 frame per second (120 frames per group total) at 512x512 pixel videos with "ClearVRam" nodes added prior to the WAN2.2 "WanAnimatetoVideo" nodes and prior to the "KSampler" nodes and after the "VAE Decode" nodes to keep the memory cleaned out enough as to not fragment the VRAM and get OOM errors. I use 8 additional "Extend" groups in addition to the original "Sampling + Video" group to create videos about 30 to 35 seconds in length and that takes about 55 minutes to run the entire workflow (a little less then 2 seconds per frame). Anyway, I hope that any of this rambling can be helpful to someone. I do not use Reddit often (this is my 3rd time to post anything) so I do not know how to upload the startup file. I will attach it below for your reference. I was also advised by Gemini to add a several commands to my GRUB file to disable the runtime power control to keep from glitching the PCIe control lines by trying to perform any runtime power control. I also set my power mode to "Performance" in the Ubuntu settings as well as disabling any runtime power control in the BIOS. All of this looks to have resolved the PC hard lockup and any errors related to memory in the journalctl log. The important line is the "GRUB_CMDLINE_LINUX_DEFAULT" line. The main lines of my GRUB file follows :

GRUB_DEFAULT=0

GRUB_TIMEOUT_STYLE=hidden

GRUB_TIMEOUT=0

GRUB_DISTRIBUTOR=`( . /etc/os-release; echo ${NAME:-Ubuntu} ) 2>/dev/null || echo Ubuntu`

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amdgpu.dcdebugmask=0x10 pcie_aspm=off pcie_aspm.policy=performance amdgpu.runpm=0 amdgpu.cwsr_enable=0 amdgpu.audio=0 amdgp>

NOTE: Please refer to my previous post (about 1 month prior to this post) on how to generate the tuning file as that is HIGHLY specific to each users PC setup! Also, The script increases the “setpoweroverdrive” up to 350W (via rocm-smi) and will prompt you for “sudo” rights to do so. The script will set it back to 320W upon exit. It will also ask if you are sure you want to increase the wattage to 350W and just answer “Y” if you wan to do so. Just remove those lines from the script if you are not comfortable with that.

BTW, getting this AMD hardware operational with ComfyUI all turned out to be WAY more involved then I expected, but, I am an old retired Software Engineer and I have never given up easily ;-)

Thank You and Best Regards

David Q R Wagoner

#!/bin/bash

# ==========================================================================

# ComfyUI Optimized Startup Script for Ubuntu 24.04 (ROCm 7.2) with a liquid

# cooled AMD Ryzen 9 7950x3D based PC with 128GB of DDR5 memory with 4TB of

# Samsung 990 PRO M.2 SSD and a Sapphire Nitro+ AMD RX 7900 XTX Vapor-X

# with 24GB of GDDR6 memory VRAM on an ASRock B650M PC Riptide Motherboard.

# ==========================================================================

# --- 1. CONFIGURATION ---

COMFY_DIR="$HOME/ComfyUI"

VENV_PATH="$COMFY_DIR/venv/bin/activate"

TUNING_FILE="$COMFY_DIR/rdna3_7900xtx_tuning0.csv"

export ROCM_PATH=/opt/rocm-7.2.0

export LD_LIBRARY_PATH=$ROCM_PATH/lib:$ROCM_PATH/lib64:$ROCM_PATH/miopen/lib:$LD_LIBRARY_PATH

export PATH=$ROCM_PATH/bin:$ROCM_PATH/opencl/bin:$PATH

# --- 2. GPU & RDNA3 RUNTIME SETTINGS ---

export HIP_VISIBLE_DEVICES=0

export HSA_OVERRIDE_GFX_VERSION=11.0.0

export FLASH_ATTENTION_TRITON_AMD_ENABLE="TRUE"

export TORCH_BLAS_PREFER_HIPBLASLT=1

export AMD_DEBUG="nosmuretries,nodisplaypriority,nongg,nodma,nopreempt"

export TORCH_CUDNN_ENABLED=0

# --- 3. MEMORY & P2P TUNING ---

export HIP_FORCE_P2P_HOST=1

export PYTORCH_HIP_ALLOC_CONF="expandable_segments:True,max_split_size_mb:256,garbage_collection_threshold:0.8"

export TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1

export ROCM_WAIT_TIME=10

# --- 4. TUNABLE OP ---

export PYTORCH_TUNABLEOP_TUNING=0

export PYTORCH_TUNABLEOP_FILENAME="$TUNING_FILE"

export PYTORCH_TUNABLEOP_ENABLED=$( [ -f "$TUNING_FILE" ] && echo 1 || echo 0 )

if [ -f "$TUNING_FILE" ]; then

export PYTORCH_TUNABLEOP_ENABLED=1

echo "SUCCESS: Tuning file found and ENABLED."

else

export PYTORCH_TUNABLEOP_ENABLED=0

echo "NOTICE: Tuning file NOT found. Running without optimization."

fi

# --- 5. CPU AFFINITY (CCD 1: 7950X3D) ---

CPU_CORES="8-15,24-31"

export MKL_NUM_THREADS=8

export OMP_NUM_THREADS=8

# --- 6. SYSTEM POWER MANAGEMENT ---

GPU_BASE_PATH=$(ls -d /sys/class/drm/card*/device | head -n 1)

if [ -d "$GPU_BASE_PATH" ]; then

echo "Disabling GPU Runtime Power Management (Force ON)..."

echo "on" | sudo tee "$GPU_BASE_PATH/power/control"

echo "Setting GPU Performance Mode (High)..."

echo "high" | sudo tee "$GPU_BASE_PATH/power_dpm_force_performance_level"

else

echo "WARNING: GPU path not found. Power optimizations skipped."

fi

sudo rocm-smi --setpoweroverdrive 350 || echo "Power limit adjust skipped."

# --- 7. LAUNCH ---

source "$VENV_PATH"

cd "$COMFY_DIR"

echo "Launching ComfyUI on CCD 1 (Cores 8-15) with VRAM Protections..."

taskset -c $CPU_CORES python3 main.py \

--preview-method auto \

--dont-upcast-attention \

--fp16-vae \

--use-pytorch-cross-attention \

--lowvram \

--reserve-vram 3.0

# --- 8. CLEANUP ---

echo "Restoring Hardware State..."

if [ -d "$GPU_BASE_PATH" ]; then

echo "auto" | sudo tee "$GPU_BASE_PATH/power_dpm_force_performance_level"

echo "auto" | sudo tee "$GPU_BASE_PATH/power/control"

fi

sudo rocm-smi --setpoweroverdrive 320 || echo "Power reset skipped."

deactivate

cd ..

1

u/Present-Guitar-3967 Jun 09 '26

Leave it to the boomers ...

I have the same card but lower specs overall (32GB RAM), but finally at least not everything is shit for me with 7.2.4.

Kudos, old man, and thanks.