FIX_1: MPS and DML device errors on install

+VersionUP (0.5.0 alpha4)
This commit is contained in:
Gourieff 2023-11-05 13:41:50 +07:00
parent 524c4b78b3
commit d57dc191d6
4 changed files with 19 additions and 8 deletions

View File

@ -2,7 +2,7 @@
<img src="https://github.com/Gourieff/Assets/raw/main/sd-webui-reactor/ReActor_logo_red.png?raw=true" alt="logo" width="180px"/>
![Version](https://img.shields.io/badge/version-0.5.0_alpha3-lightgreen?style=for-the-badge&labelColor=darkgreen)
![Version](https://img.shields.io/badge/version-0.5.0_alpha4-lightgreen?style=for-the-badge&labelColor=darkgreen)
<a href='https://ko-fi.com/gourieff' target='_blank'><img height='33' src='https://storage.ko-fi.com/cdn/kofi3.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

View File

@ -2,7 +2,7 @@
<img src="https://github.com/Gourieff/Assets/raw/main/sd-webui-reactor/ReActor_logo_red.png?raw=true" alt="logo" width="180px"/>
![Version](https://img.shields.io/badge/версия-0.5.0_alpha3-lightgreen?style=for-the-badge&labelColor=darkgreen)
![Version](https://img.shields.io/badge/версия-0.5.0_alpha4-lightgreen?style=for-the-badge&labelColor=darkgreen)
<a href='https://ko-fi.com/gourieff' target='_blank'><img height='33' src='https://storage.ko-fi.com/cdn/kofi3.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>

View File

@ -43,9 +43,12 @@ def get_sd_option(name: str, default: Any) -> Any:
assert shared.opts.data is not None
return shared.opts.data.get(name, default)
def run_pip(*args):
def pip_install(*args):
subprocess.run([sys.executable, "-m", "pip", "install", *args])
def pip_uninstall(*args):
subprocess.run([sys.executable, "-m", "pip", "uninstall", "-y", *args])
def is_installed (
package: str, version: str | None = None, strict: bool = True
):
@ -96,10 +99,18 @@ with open(req_file) as file:
install_count = 0
try:
ort = "onnxruntime-gpu"
import torch.cuda as cuda
if cuda.is_available():
import torch
if torch.cuda.is_available():
if first_run:
last_device = "CUDA"
elif torch.backends.mps.is_available() or hasattr(torch,'dml'):
ort = "onnxruntime"
# to prevent errors when ORT-GPU is installed but we want ORT instead:
if first_run:
pip_uninstall("onnxruntime", "onnxruntime-gpu")
# just in case:
if last_device == "CUDA":
last_device = "CPU"
else:
if last_device == "CUDA":
last_device = "CPU"
@ -107,7 +118,7 @@ with open(req_file) as file:
txt.write(last_device)
if not is_installed(ort,"1.16.1",False):
install_count += 1
run_pip(ort)
pip_install(ort)
except Exception as e:
print(e)
print(f"\nERROR: Failed to install {ort} - ReActor won't start")
@ -125,7 +136,7 @@ with open(req_file) as file:
strict = False
if not is_installed(package,package_version,strict):
install_count += 1
run_pip(package)
pip_install(package)
except Exception as e:
print(e)
print(f"\nERROR: Failed to install {package} - ReActor won't start")

View File

@ -1,5 +1,5 @@
app_title = "ReActor"
version_flag = "v0.5.0-a3"
version_flag = "v0.5.0-a4"
from scripts.reactor_logger import logger, get_Run, set_Run