From 71e99185cb50497d7273505986d5c8aa16b96267 Mon Sep 17 00:00:00 2001 From: ttio2tech <125389792+ttio2tech@users.noreply.github.com> Date: Sat, 16 Sep 2023 17:09:04 -0400 Subject: [PATCH] add support for AMD GPU on Linux. Skip the xformers installation if detecting AMD GPU. also add a section in readme. (#397) Co-authored-by: tio2 --- launch.py | 21 ++++++++++++++++++--- readme.md | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/launch.py b/launch.py index 4ce6a163..ef13bee5 100644 --- a/launch.py +++ b/launch.py @@ -1,7 +1,6 @@ import os os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" - import sys import platform import fooocus_version @@ -13,7 +12,6 @@ from modules.path import modelfile_path, lorafile_path, vae_approx_path, fooocus REINSTALL_ALL = False - def prepare_environment(): torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118") torch_command = os.environ.get('TORCH_COMMAND', @@ -35,6 +33,23 @@ def prepare_environment(): if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"): run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True) + import torch + + def detect_gpu_type(): + if torch.cuda.is_available(): + gpu_name = torch.cuda.get_device_name(0) + if "NVIDIA" in gpu_name: + return "NVIDIA GPU" + elif "Radeon" in gpu_name: + return "AMD GPU" + else: + return "Unknown GPU Type" + else: + return "No GPU Available" + + gpu_type = detect_gpu_type() + print("Detected GPU Type:", gpu_type) + if REINSTALL_ALL or not is_installed("xformers"): if platform.system() == "Windows": if platform.python_version().startswith("3.10"): @@ -45,7 +60,7 @@ def prepare_environment(): "You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness") if not is_installed("xformers"): exit(0) - elif platform.system() == "Linux": + elif platform.system() == "Linux" and gpu_type == 'NVIDIA GPU': run_pip(f"install -U -I --no-deps {xformers_package}", "xformers") if REINSTALL_ALL or not requirements_met(requirements_file): diff --git a/readme.md b/readme.md index 5f4ed9b9..7ad4b08f 100644 --- a/readme.md +++ b/readme.md @@ -130,6 +130,10 @@ Or if you want to open a remote port, use Coming soon ... +### Linux (AMD GPUs) + +Installation is the same as Linux part. It has been tested for 6700XT. Works for both Pytorch 1.13 and Pytorch 2. + ## List of "Hidden" Tricks