Skip to content

Instantly share code, notes, and snippets.

@NoXPhasma
Last active June 21, 2024 16:51
Show Gist options
  • Save NoXPhasma/ba42b615c0ed1cb0c2b3a4a1b359ccf7 to your computer and use it in GitHub Desktop.
Save NoXPhasma/ba42b615c0ed1cb0c2b3a4a1b359ccf7 to your computer and use it in GitHub Desktop.
Install stable-diffusion-webui with ROCm support on Linux

Install stable-diffusion-webui with ROCm support on Arch Linux

First time installation:

  1. Clone and switch to the stable-diffusion-webui folder
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui
cd stable-diffusion-webui
  1. Create a new python environment and switch to it
python -m venv venv
source venv/bin/activate
  1. Update pip and wheel
python -m pip install --upgrade pip wheel
  1. To prevent a memory leak in the application, we need to preload /usr/lib/libtcmalloc.so, this is part of the gperftools package. So let's install that:
sudo pacman -S gperftools
  1. Create and edit a new shell file which we will use to start stable-diffusion-webui
touch start.sh
nano start.sh
  1. Add this content to the file and save it with CTRL+O and exit with CTRL+X
#!/usr/bin/env bash
source venv/bin/activate
export HSA_OVERRIDE_GFX_VERSION=10.3.0
export MIOPEN_DEBUG_COMGR_HIP_PCH_ENFORCE=0
export PYTORCH_HIP_ALLOC_CONF=garbage_collection_threshold:0.9,max_split_size_mb:512
export PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.9,max_split_size_mb:512
export TORCH_COMMAND='pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm5.7'
export REQS_FILE='requirements.txt'
export LD_PRELOAD=/usr/lib/libtcmalloc.so
python launch.py --precision full --no-half --enable-insecure-extension-access --listen --opt-sub-quad-attention --no-half-vae --disable-nan-check --medvram
  1. Make the file executable
chmod +x start.sh
  1. Deactivate the python environment
deactivate

Running stable-diffusion-webui

Switch to the stable-diffusion-webui folder and run:

./start.sh
@EtereosDawn
Copy link

Hello, any idea ?
image

@NoXPhasma
Copy link
Author

This seems to be an issue with stable-diffusion-web itself. It also happens with their own runner. For some reason, after trying several times, it eventually worked. No idea what exactly is causing it.

@kallestrop
Copy link

How can i force the start script to use Python 3.10 in the environment? I've Python 3.12.4 default install and additionally a Python 3.10 install from AUR.

But after executing start.sh it always uses the default 3.12 version of Python:

user@endeavour:~/stable-diffusion-webui$ ./start.sh 
=============================================================================================
INCOMPATIBLE PYTHON VERSION

This program is tested with 3.10.6 Python, but you have 3.12.4.
If you encounter an error with "RuntimeError: Couldn't install torch." message,
or any other error regarding unsuccessful package (library) installation,
please downgrade (or upgrade) to the latest version of 3.10 Python
and delete current Python and "venv" folder in WebUI's directory.

@NoXPhasma
Copy link
Author

@kallestrop You'll need to use python3.10 to create the python environment in step 2:

/path/to/python3.10 -m venv venv

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