From cbf4b3472b1da35937ff12c06072214a2e5cbad7 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:18:56 +0100 Subject: [PATCH 01/10] Automatic launch argument for AMD GPUs This commit adds a few lines to detect if the system has an AMD gpu and adds an environment variable needed for torch to recognize the gpu. --- webui.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/webui.sh b/webui.sh index c4d6521d..23629ef9 100755 --- a/webui.sh +++ b/webui.sh @@ -165,5 +165,11 @@ else printf "\n%s\n" "${delimiter}" printf "Launching launch.py..." printf "\n%s\n" "${delimiter}" - exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" + gpu_info=$(lspci | grep VGA) + if echo "$gpu_info" | grep -q "AMD" + then + HSA_OVERRIDE_GFX_VERSION=10.3.0 exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" + else + exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" + fi fi From eaebcf638391071172d504568d661931f7e3c740 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:20:18 +0100 Subject: [PATCH 02/10] GPU detection script This commit adds a script that detects which GPU is currently used in Windows and Linux --- detection.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 detection.py diff --git a/detection.py b/detection.py new file mode 100644 index 00000000..eb4db0df --- /dev/null +++ b/detection.py @@ -0,0 +1,45 @@ +# This script detects which GPU is currently used in Windows and Linux +import os +import sys + +def check_gpu(): + # First, check if the `lspci` command is available + if not os.system("which lspci > /dev/null") == 0: + # If the `lspci` command is not available, try the `dxdiag` command on Windows + if os.name == "nt": + # On Windows, run the `dxdiag` command and check the output for the "Card name" field + # Create the dxdiag.txt file + os.system("dxdiag /t dxdiag.txt") + + # Read the dxdiag.txt file + with open("dxdiag.txt", "r") as f: + output = f.read() + + if "Card name" in output: + card_name_start = output.index("Card name: ") + len("Card name: ") + card_name_end = output.index("\n", card_name_start) + card_name = output[card_name_start:card_name_end] + else: + card_name = "Unknown" + print(f"Card name: {card_name}") + os.remove("dxdiag.txt") + if "AMD" in card_name: + return "AMD" + elif "Intel" in card_name: + return "Intel" + elif "NVIDIA" in card_name: + return "NVIDIA" + else: + return "Unknown" + else: + # If the `lspci` command is available, use it to get the GPU vendor and model information + output = os.popen("lspci | grep -i vga").read() + if "AMD" in output: + return "AMD" + elif "Intel" in output: + return "Intel" + elif "NVIDIA" in output: + return "NVIDIA" + else: + return "Unknown" + From a407c9f0147c779865c940cbf62c7019dbc1f7b4 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Fri, 13 Jan 2023 19:22:23 +0100 Subject: [PATCH 03/10] Automatic torch install for amd on linux This commit allows the launch script to automatically download rocm's torch version for AMD GPUs using an external GPU detection script. It also prints the operative system and GPU in use. --- launch.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/launch.py b/launch.py index bcbb792c..668548f1 100644 --- a/launch.py +++ b/launch.py @@ -7,6 +7,7 @@ import shlex import platform import argparse import json +import detection dir_repos = "repositories" dir_extensions = "extensions" @@ -15,6 +16,12 @@ git = os.environ.get('GIT', "git") index_url = os.environ.get('INDEX_URL', "") stored_commit_hash = None +# Get the GPU vendor and the operating system +gpu = detection.check_gpu() +if os.name == "posix": + os_name = platform.uname().system +else: + os_name = os.name def commit_hash(): global stored_commit_hash @@ -173,7 +180,11 @@ def run_extensions_installers(settings_file): def prepare_environment(): - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") + if gpu == "AMD" and os_name !="nt": + torch_command = os.environ.get('TORCH_COMMAND', "pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2") + else: + torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") + requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") commandline_args = os.environ.get('COMMANDLINE_ARGS', "") @@ -295,6 +306,8 @@ def tests(test_dir): def start(): + print(f"Operating System: {os_name}") + print(f"GPU: {gpu}") print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}") import webui if '--nowebui' in sys.argv: From 54fa77facc1849fbbfe61c1ca6d99b117d609d67 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 12:10:45 +0100 Subject: [PATCH 04/10] Fix detection script on macos This fixes the script on macos --- detection.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/detection.py b/detection.py index eb4db0df..442c4be5 100644 --- a/detection.py +++ b/detection.py @@ -31,6 +31,8 @@ def check_gpu(): return "NVIDIA" else: return "Unknown" + else: + return "Unknown" else: # If the `lspci` command is available, use it to get the GPU vendor and model information output = os.popen("lspci | grep -i vga").read() From 934cba0f4ca3e80a2079a657ebb6ca8c1ee2d10b Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:43:29 +0100 Subject: [PATCH 05/10] Delete detection.py --- detection.py | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 detection.py diff --git a/detection.py b/detection.py deleted file mode 100644 index 442c4be5..00000000 --- a/detection.py +++ /dev/null @@ -1,47 +0,0 @@ -# This script detects which GPU is currently used in Windows and Linux -import os -import sys - -def check_gpu(): - # First, check if the `lspci` command is available - if not os.system("which lspci > /dev/null") == 0: - # If the `lspci` command is not available, try the `dxdiag` command on Windows - if os.name == "nt": - # On Windows, run the `dxdiag` command and check the output for the "Card name" field - # Create the dxdiag.txt file - os.system("dxdiag /t dxdiag.txt") - - # Read the dxdiag.txt file - with open("dxdiag.txt", "r") as f: - output = f.read() - - if "Card name" in output: - card_name_start = output.index("Card name: ") + len("Card name: ") - card_name_end = output.index("\n", card_name_start) - card_name = output[card_name_start:card_name_end] - else: - card_name = "Unknown" - print(f"Card name: {card_name}") - os.remove("dxdiag.txt") - if "AMD" in card_name: - return "AMD" - elif "Intel" in card_name: - return "Intel" - elif "NVIDIA" in card_name: - return "NVIDIA" - else: - return "Unknown" - else: - return "Unknown" - else: - # If the `lspci` command is available, use it to get the GPU vendor and model information - output = os.popen("lspci | grep -i vga").read() - if "AMD" in output: - return "AMD" - elif "Intel" in output: - return "Intel" - elif "NVIDIA" in output: - return "NVIDIA" - else: - return "Unknown" - From 629612935372aa7faeb764b5660431e49b93de24 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:45:07 +0100 Subject: [PATCH 06/10] Revert detection code --- launch.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/launch.py b/launch.py index 668548f1..bcbb792c 100644 --- a/launch.py +++ b/launch.py @@ -7,7 +7,6 @@ import shlex import platform import argparse import json -import detection dir_repos = "repositories" dir_extensions = "extensions" @@ -16,12 +15,6 @@ git = os.environ.get('GIT', "git") index_url = os.environ.get('INDEX_URL', "") stored_commit_hash = None -# Get the GPU vendor and the operating system -gpu = detection.check_gpu() -if os.name == "posix": - os_name = platform.uname().system -else: - os_name = os.name def commit_hash(): global stored_commit_hash @@ -180,11 +173,7 @@ def run_extensions_installers(settings_file): def prepare_environment(): - if gpu == "AMD" and os_name !="nt": - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2") - else: - torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") - + torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 --extra-index-url https://download.pytorch.org/whl/cu113") requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt") commandline_args = os.environ.get('COMMANDLINE_ARGS', "") @@ -306,8 +295,6 @@ def tests(test_dir): def start(): - print(f"Operating System: {os_name}") - print(f"GPU: {gpu}") print(f"Launching {'API server' if '--nowebui' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}") import webui if '--nowebui' in sys.argv: From 6192a222bf7131771a2cd7655a64a5b24a1e6e2e Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:46:23 +0100 Subject: [PATCH 07/10] Export TORCH_COMMAND for AMD from the webui --- webui.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/webui.sh b/webui.sh index 23629ef9..35f52f2a 100755 --- a/webui.sh +++ b/webui.sh @@ -168,6 +168,7 @@ else gpu_info=$(lspci | grep VGA) if echo "$gpu_info" | grep -q "AMD" then + export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" HSA_OVERRIDE_GFX_VERSION=10.3.0 exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" else exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" From c4ba34928ec7f977585494f0fa5925496c887698 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 15:58:50 +0100 Subject: [PATCH 08/10] Quick format fix --- webui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.sh b/webui.sh index 35f52f2a..fcba6b7d 100755 --- a/webui.sh +++ b/webui.sh @@ -168,7 +168,7 @@ else gpu_info=$(lspci | grep VGA) if echo "$gpu_info" | grep -q "AMD" then - export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" + export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" HSA_OVERRIDE_GFX_VERSION=10.3.0 exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" else exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" From 2e172cf831a928223e93803b94896325bd4c22a7 Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:25:32 +0100 Subject: [PATCH 09/10] Only set TORCH_COMMAND if wasn't set webui-user --- webui.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/webui.sh b/webui.sh index fcba6b7d..35542ed6 100755 --- a/webui.sh +++ b/webui.sh @@ -168,7 +168,10 @@ else gpu_info=$(lspci | grep VGA) if echo "$gpu_info" | grep -q "AMD" then - export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" + if [ -z ${TORCH_COMMAND+x} ] + then + export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" + fi HSA_OVERRIDE_GFX_VERSION=10.3.0 exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" else exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" From ba077e2110cab891a46d14665fb161ce0669f31e Mon Sep 17 00:00:00 2001 From: DaniAndTheWeb <57776841+DaniAndTheWeb@users.noreply.github.com> Date: Sat, 14 Jan 2023 23:19:52 +0100 Subject: [PATCH 10/10] Fix TORCH_COMMAND check --- webui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.sh b/webui.sh index 35542ed6..6e07778f 100755 --- a/webui.sh +++ b/webui.sh @@ -168,7 +168,7 @@ else gpu_info=$(lspci | grep VGA) if echo "$gpu_info" | grep -q "AMD" then - if [ -z ${TORCH_COMMAND+x} ] + if [[ -z "${TORCH_COMMAND}" ]] then export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2" fi