From 15513a0163fd675c3ba69ab06cf7b0b71589c014 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Sat, 18 Nov 2023 14:03:35 -0600 Subject: [PATCH] Bitsandbytes...PITA. --- postinstall.py | 83 +++++++++++++++++++++++++++++++++--------------- preload.py | 1 - requirements.txt | 1 - 3 files changed, 58 insertions(+), 27 deletions(-) diff --git a/postinstall.py b/postinstall.py index b9be982..1a4d494 100644 --- a/postinstall.py +++ b/postinstall.py @@ -42,7 +42,7 @@ def actual_install(): check_xformers() - #check_bitsandbytes() + check_bitsandbytes() install_requirements() @@ -209,29 +209,35 @@ def check_bitsandbytes(): bitsandbytes_version = None if os.name == "nt": print("Checking bitsandbytes (Windows)") - if bitsandbytes_version != "0.41.2": - venv_path = os.environ.get("VENV_DIR", None) - print(f"Virtual environment path: {venv_path}") - # Check for the dll in venv/lib/site-packages/bitsandbytes/libbitsandbytes_cuda118.dll - # If it doesn't exist, append the requirement - if not venv_path: - print("Could not find the virtual environment path. Skipping bitsandbytes installation.") - else: - win_dll = os.path.join(venv_path, "lib", "site-packages", "bitsandbytes", "libbitsandbytes_cuda118.dll") - print(f"Checking for {win_dll}") - if not os.path.exists(win_dll): - try: - pip_uninstall("bitsandbytes") - # Find any directories starting with ~ in the venv/lib/site-packages directory and delete them - for env_dir in os.listdir(os.path.join(venv_path, "lib", "site-packages")): - if env_dir.startswith("~"): - print(f"Deleting {env_dir}") - os.rmdir(os.path.join(venv_path, "lib", "site-packages", env_dir)) - except: - pass - print("Installing bitsandbytes") - pip_install("bitsandbytes==0.41.1", "--force-reinstall", - "--extra-index-url", "https://d8ahazard.github.io/sd_dreambooth_extension/bnb_index.html") + venv_path = os.environ.get("VENV_DIR", None) + print(f"Virtual environment path: {venv_path}") + # Check for the dll in venv/lib/site-packages/bitsandbytes/libbitsandbytes_cuda118.dll + # If it doesn't exist, append the requirement + if not venv_path: + print("Could not find the virtual environment path. Skipping bitsandbytes installation.") + else: + win_dll = os.path.join(venv_path, "lib", "site-packages", "bitsandbytes", "libbitsandbytes_cuda118.dll") + print(f"Checking for {win_dll}") + if not os.path.exists(win_dll): + print("Can't find bitsandbytes CUDA dll. Installing bitsandbytes") + try: + pip_uninstall("bitsandbytes") + # Find any directories starting with ~ in the venv/lib/site-packages directory and delete them + for env_dir in os.listdir(os.path.join(venv_path, "lib", "site-packages")): + if env_dir.startswith("~"): + print(f"Deleting {env_dir}") + os.rmdir(os.path.join(venv_path, "lib", "site-packages", env_dir)) + except: + pass + print("Installing bitsandbytes") + try: + pip_install( + "--prefer-binary", "https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl") + except Exception as e: + print("Bitsandbytes 0.41.1 installation failed") + print("Some features such as 8bit optimizers will be unavailable") + print_bitsandbytes_installation_error(str(e)) + pass else: print("Checking bitsandbytes (Linux)") if bitsandbytes_version != "0.41.1": @@ -318,6 +324,32 @@ def print_requirement_installation_error(err): print(line) +def print_bitsandbytes_installation_error(err): + print() + print("#######################################################################################################") + print("# BITSANDBYTES ISSUE DETECTED #") + print("#######################################################################################################") + print("#") + print("# Dreambooth could not find a compatible version of bitsandbytes.") + print("# bitsandbytes will not be available for Dreambooth.") + print("#") + print("# Bitsandbytes installation exception:") + for line in err.split('\n'): + line = line.strip() + if line: + print(line) + print("#") + print("# TO FIX THIS ISSUE, DO THE FOLLOWING:") + print("# 1. Fully restart your project (not just the webpage)") + print("# 2. Running the following commands from the A1111 project root:") + print("cd venv/Scripts") + print("activate") + print("cd ../..") + print("# WINDOWS ONLY: ") + print( + "pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl") + print("#######################################################################################################") + def print_xformers_installation_error(err): torch_ver = importlib_metadata.version("torch") print() @@ -351,11 +383,12 @@ def print_launch_errors(launch_errors): print("# 1. Fully restart your project (not just the webpage)") print("# 2. Update your A1111 project and extensions") print("# 3. Dreambooth requirements should have installed automatically, but you can manually install them") - print("# by running the following 4 commands from the A1111 project root:") + print("# by running the following commands from the A1111 project root:") print("cd venv/Scripts") print("activate") print("cd ../..") print("pip install -r ./extensions/sd_dreambooth_extension/requirements.txt") + print("pip install --prefer-binary --force-reinstall https://github.com/jllllll/bitsandbytes-windows-webui/releases/download/wheels/bitsandbytes-0.41.1-py3-none-win_amd64.whl") print("#######################################################################################################") diff --git a/preload.py b/preload.py index 238765d..294f0e7 100644 --- a/preload.py +++ b/preload.py @@ -16,7 +16,6 @@ def preload(parser: argparse.ArgumentParser): if os.name == "posix": # For now disable Torch2 Dynamo os.environ["TORCHDYNAMO_DISABLE"] = "1" - parser.add_argument("--dreambooth-models-path", type=str, help="Path to directory to store Dreambooth model file(" "s).", default=None) parser.add_argument("--lora-models-path", type=str, help="Path to directory to store Lora model file(s).", diff --git a/requirements.txt b/requirements.txt index 3d3dee5..6af5c3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ accelerate>=0.21.0 -bitsandbytes>=0.41.2 dadaptation>=3.1 diffusers>=0.23.1 discord-webhook==1.3.0