From be98e7433743e6f42a8212a6a34f2830618c98aa Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Wed, 31 May 2023 12:41:03 -0500 Subject: [PATCH] Install older bitsandbytes on older gpus + fix llama-cpp-python issue (#75) --- webui.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 70d473ac..6f8610d6 100644 --- a/webui.py +++ b/webui.py @@ -7,6 +7,7 @@ import subprocess import sys script_dir = os.getcwd() +conda_env_path = os.path.join(script_dir, "installer_files", "env") # Use this to set your command-line flags. For the full list, see: # https://github.com/oobabooga/text-generation-webui/#starting-the-web-ui @@ -16,7 +17,6 @@ CMD_FLAGS = '--chat --model-menu' def run_cmd(cmd, assert_success=False, environment=False, capture_output=False, env=None): # Use the conda environment if environment: - conda_env_path = os.path.join(script_dir, "installer_files", "env") if sys.platform.startswith("win"): conda_bat_path = os.path.join(script_dir, "installer_files", "conda", "condabin", "conda.bat") cmd = "\"" + conda_bat_path + "\" activate \"" + conda_env_path + "\" >nul && " + cmd @@ -98,6 +98,20 @@ def update_dependencies(): if os.path.exists(extension_req_path): run_cmd("python -m pip install -r " + extension_req_path + " --upgrade", assert_success=True, environment=True) + # Latest bitsandbytes requires minimum compute 7.0 + nvcc_device_query = "__nvcc_device_query" if not sys.platform.startswith("win") else "__nvcc_device_query.exe" + min_compute = 70 + compute_array = run_cmd(os.path.join(conda_env_path, "bin", nvcc_device_query), environment=True, capture_output=True) + old_bnb = "bitsandbytes==0.38.1" if not sys.platform.startswith("win") else "https://github.com/jllllll/bitsandbytes-windows-webui/raw/main/bitsandbytes-0.38.1-py3-none-any.whl" + if compute_array.returncode == 0 and not any(int(compute) >= min_compute for compute in compute_array.stdout.decode('utf-8').split(',')): + old_bnb_install = run_cmd(f"python -m pip install {old_bnb} --force-reinstall --no-deps", environment=True).returncode == 0 + print("\n\nWARNING: GPU with compute < 7.0 detected!") + if old_bnb_install: + print("Older version of bitsandbytes has been installed to maintain compatibility.") + print("You will be unable to use --load-in-4bit!\n\n") + else: + print("You will be unable to use --load-in-8bit until you install bitsandbytes 0.38.1!\n\n") + # The following dependencies are for CUDA, not CPU # Check if the package cpuonly exists to determine if torch uses CUDA or not cpuonly_exist = run_cmd("conda list cpuonly | grep cpuonly", environment=True, capture_output=True).returncode == 0 @@ -200,5 +214,10 @@ if __name__ == "__main__": download_model() os.chdir(script_dir) + # Workaround for llama-cpp-python loading paths in CUDA env vars even if they do not exist + conda_path_bin = os.path.join(conda_env_path, "bin") + if not os.path.exists(conda_path_bin): + os.mkdir(conda_path_bin) + # Run the model with webui run_model()