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 <pema@syr.edu>
This commit is contained in:
ttio2tech 2023-09-16 17:09:04 -04:00 committed by GitHub
parent ceee6dfd73
commit 71e99185cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -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):

View File

@ -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
<a name="tech_list"></a>