2023-04-14 14:02:27 +02:00
|
|
|
"""
|
2023-04-18 12:12:33 +02:00
|
|
|
This script checks and installs the required modules.
|
2023-04-18 12:40:46 +02:00
|
|
|
|
2023-04-19 12:41:16 +02:00
|
|
|
This script runs inside the legacy "stable-diffusion" folder
|
|
|
|
|
2023-04-18 12:40:46 +02:00
|
|
|
TODO - Maybe replace the bulk of this script with a call to `pip install -f requirements.txt`, with
|
|
|
|
a custom index URL depending on the platform.
|
|
|
|
|
2023-04-14 14:02:27 +02:00
|
|
|
"""
|
2022-12-24 09:07:50 +01:00
|
|
|
|
2023-04-18 12:12:33 +02:00
|
|
|
import os
|
|
|
|
from importlib.metadata import version as pkg_version
|
|
|
|
import platform
|
2023-04-19 12:50:08 +02:00
|
|
|
import traceback
|
2023-04-18 12:12:33 +02:00
|
|
|
|
|
|
|
os_name = platform.system()
|
|
|
|
|
|
|
|
modules_to_check = {
|
2023-04-18 12:40:46 +02:00
|
|
|
"torch": ("1.11.0", "1.13.1", "2.0.0"),
|
|
|
|
"torchvision": ("0.12.0", "0.14.1", "0.15.1"),
|
2023-04-21 11:56:14 +02:00
|
|
|
"sdkit": "1.0.80",
|
2023-04-18 12:12:33 +02:00
|
|
|
"stable-diffusion-sdkit": "2.1.4",
|
|
|
|
"rich": "12.6.0",
|
|
|
|
"uvicorn": "0.19.0",
|
|
|
|
"fastapi": "0.85.1",
|
2023-04-20 13:37:10 +02:00
|
|
|
# "xformers": "0.0.16",
|
2023-04-18 12:12:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def version(module_name: str) -> str:
|
|
|
|
try:
|
|
|
|
return pkg_version(module_name)
|
|
|
|
except:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def install(module_name: str, module_version: str):
|
2023-04-20 13:18:38 +02:00
|
|
|
if module_name == "xformers" and (os_name == "Darwin" or is_amd_on_linux()):
|
2023-04-20 12:47:27 +02:00
|
|
|
return
|
|
|
|
|
2023-04-18 12:12:33 +02:00
|
|
|
index_url = None
|
|
|
|
if module_name in ("torch", "torchvision"):
|
|
|
|
module_version, index_url = apply_torch_install_overrides(module_version)
|
|
|
|
|
|
|
|
install_cmd = f"python -m pip install --upgrade {module_name}=={module_version}"
|
|
|
|
if index_url:
|
|
|
|
install_cmd += f" --index-url {index_url}"
|
2023-04-21 12:19:38 +02:00
|
|
|
if module_name == "sdkit" and version("sdkit") is not None:
|
2023-04-18 12:12:33 +02:00
|
|
|
install_cmd += " -q"
|
|
|
|
|
|
|
|
print(">", install_cmd)
|
|
|
|
os.system(install_cmd)
|
|
|
|
|
|
|
|
|
|
|
|
def init():
|
|
|
|
for module_name, allowed_versions in modules_to_check.items():
|
|
|
|
if os.path.exists(f"../src/{module_name}"):
|
|
|
|
print(f"Skipping {module_name} update, since it's in developer/editable mode")
|
|
|
|
continue
|
|
|
|
|
|
|
|
allowed_versions, latest_version = get_allowed_versions(module_name, allowed_versions)
|
2023-04-20 15:10:45 +02:00
|
|
|
|
|
|
|
requires_install = False
|
|
|
|
if module_name in ("torch", "torchvision"):
|
|
|
|
if version(module_name) is None: # allow any torch version
|
|
|
|
requires_install = True
|
|
|
|
elif version(module_name) not in allowed_versions:
|
|
|
|
requires_install = True
|
|
|
|
|
|
|
|
if requires_install:
|
2023-04-18 12:12:33 +02:00
|
|
|
try:
|
|
|
|
install(module_name, latest_version)
|
|
|
|
except:
|
2023-04-19 12:50:08 +02:00
|
|
|
traceback.print_exc()
|
2023-04-18 12:12:33 +02:00
|
|
|
fail(module_name)
|
|
|
|
|
|
|
|
print(f"{module_name}: {version(module_name)}")
|
|
|
|
|
|
|
|
|
|
|
|
### utilities
|
|
|
|
|
|
|
|
|
2023-04-18 12:13:56 +02:00
|
|
|
def get_allowed_versions(module_name: str, allowed_versions: tuple):
|
2023-04-18 12:12:33 +02:00
|
|
|
allowed_versions = (allowed_versions,) if isinstance(allowed_versions, str) else allowed_versions
|
|
|
|
latest_version = allowed_versions[-1]
|
|
|
|
|
|
|
|
if module_name in ("torch", "torchvision"):
|
|
|
|
allowed_versions = include_cuda_versions(allowed_versions)
|
|
|
|
|
|
|
|
return allowed_versions, latest_version
|
|
|
|
|
|
|
|
|
|
|
|
def apply_torch_install_overrides(module_version: str):
|
|
|
|
index_url = None
|
|
|
|
if os_name == "Windows":
|
|
|
|
module_version += "+cu117"
|
|
|
|
index_url = "https://download.pytorch.org/whl/cu117"
|
2023-04-20 13:18:38 +02:00
|
|
|
elif is_amd_on_linux():
|
|
|
|
index_url = "https://download.pytorch.org/whl/rocm5.4.2"
|
2023-04-18 12:12:33 +02:00
|
|
|
|
|
|
|
return module_version, index_url
|
|
|
|
|
|
|
|
|
|
|
|
def include_cuda_versions(module_versions: tuple) -> tuple:
|
|
|
|
"Adds CUDA-specific versions to the list of allowed version numbers"
|
|
|
|
|
|
|
|
allowed_versions = tuple(module_versions)
|
|
|
|
allowed_versions += tuple(f"{v}+cu116" for v in module_versions)
|
|
|
|
allowed_versions += tuple(f"{v}+cu117" for v in module_versions)
|
2023-04-20 14:16:34 +02:00
|
|
|
allowed_versions += tuple(f"{v}+rocm5.2" for v in module_versions)
|
2023-04-18 14:06:52 +02:00
|
|
|
allowed_versions += tuple(f"{v}+rocm5.4.2" for v in module_versions)
|
2023-04-18 12:12:33 +02:00
|
|
|
|
|
|
|
return allowed_versions
|
|
|
|
|
|
|
|
|
2023-04-20 13:18:38 +02:00
|
|
|
def is_amd_on_linux():
|
|
|
|
if os_name == "Linux":
|
|
|
|
with open("/proc/bus/pci/devices", "r") as f:
|
|
|
|
device_info = f.read()
|
|
|
|
if "amdgpu" in device_info and "nvidia" not in device_info:
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-04-18 12:12:33 +02:00
|
|
|
def fail(module_name):
|
|
|
|
print(
|
|
|
|
f"""Error installing {module_name}. Sorry about that, please try to:
|
|
|
|
1. Run this installer again.
|
|
|
|
2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting
|
|
|
|
3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB
|
|
|
|
4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues
|
|
|
|
Thanks!"""
|
|
|
|
)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
### start
|
|
|
|
|
|
|
|
init()
|