mirror of
https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
synced 2024-06-07 21:20:49 +00:00
Prepare further startup check & move away from nvidia-smi
This commit is contained in:
parent
36669b811c
commit
cb87b2d483
@ -1,9 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
|
||||||
|
|
||||||
## Functions for checking if user wants to skip startup
|
import torch
|
||||||
|
|
||||||
|
## Functions for checking if user wants to skip startup checks
|
||||||
SKIP_STARTUP_CHECKS = "./skip_startup_checks.txt"
|
SKIP_STARTUP_CHECKS = "./skip_startup_checks.txt"
|
||||||
|
|
||||||
def startup_skip_check():
|
def startup_skip_check():
|
||||||
@ -14,15 +15,29 @@ def startup_skip_check():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
## Functions for checks
|
## Functions for checks
|
||||||
|
# Performs gpu brand check
|
||||||
|
def get_gpu_brand():
|
||||||
|
try:
|
||||||
|
cuda_is_available = torch.cuda.is_available()
|
||||||
|
if cuda_is_available == True:
|
||||||
|
gpu_brand = torch.cuda.get_device_name()
|
||||||
|
gpu_brand = gpu_brand.split()[0]
|
||||||
|
print("\nGPU brand:", gpu_brand)
|
||||||
|
return gpu_brand
|
||||||
|
else:
|
||||||
|
print("Cuda is not currently available")
|
||||||
|
except:
|
||||||
|
print("Torch or Cuda is not currently available")
|
||||||
|
|
||||||
|
# Performs vram check
|
||||||
def vram_check():
|
def vram_check():
|
||||||
try:
|
try:
|
||||||
output = subprocess.check_output(['nvidia-smi', '--query-gpu=memory.total', '--format=csv,noheader,nounits'])
|
total_vram = torch.cuda.get_device_properties(0).total_memory // 1024 ** 2
|
||||||
total_vram = sum(map(int, output.decode('utf-8').strip().split('\n')))
|
|
||||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||||
print("\nUnable to get VRAM amount")
|
print("\nUnable to get VRAM amount")
|
||||||
|
|
||||||
if total_vram is not None:
|
if total_vram is not None:
|
||||||
print(f"\nTotal VRAM available: {total_vram} bytes")
|
print(f"Total VRAM: {total_vram} MegaBytes")
|
||||||
if total_vram > 8192:
|
if total_vram > 8192:
|
||||||
return 0
|
return 0
|
||||||
elif total_vram <= 8192 and total_vram > 4096:
|
elif total_vram <= 8192 and total_vram > 4096:
|
||||||
@ -33,10 +48,8 @@ def vram_check():
|
|||||||
return 3
|
return 3
|
||||||
|
|
||||||
# Function to write new args to webui-user.bat file
|
# Function to write new args to webui-user.bat file
|
||||||
def write_commandline_args():
|
def write_commandline_args(new_commandline_args):
|
||||||
bat_file = "./webui-user.bat"
|
bat_file = "./webui-user.bat"
|
||||||
## TODO: Switch this to use actual dynamic commandline args from user options and system info
|
|
||||||
new_commandline_args = ""
|
|
||||||
|
|
||||||
# Read webui-user.bat file and save lines
|
# Read webui-user.bat file and save lines
|
||||||
with open(bat_file, 'r') as file:
|
with open(bat_file, 'r') as file:
|
||||||
@ -54,6 +67,8 @@ def write_commandline_args():
|
|||||||
|
|
||||||
## Main starting check sequence
|
## Main starting check sequence
|
||||||
def start_check_sequence():
|
def start_check_sequence():
|
||||||
|
new_commandline_args = ""
|
||||||
|
|
||||||
print("Running system checks")
|
print("Running system checks")
|
||||||
|
|
||||||
# Initial check to see if they wish to perform startup checks at each launch or not - It's really not necessary to
|
# Initial check to see if they wish to perform startup checks at each launch or not - It's really not necessary to
|
||||||
@ -65,29 +80,42 @@ def start_check_sequence():
|
|||||||
with open(SKIP_STARTUP_CHECKS, "w") as file:
|
with open(SKIP_STARTUP_CHECKS, "w") as file:
|
||||||
file.write("1")
|
file.write("1")
|
||||||
|
|
||||||
# Skip webui install at each start?
|
## Skip webui install at each start?
|
||||||
## TODO: Implement check if already answered
|
|
||||||
skip_webui_install = str(input("\nWould you like to skip stable-diffusion webui installation at each startup? (y)es or (n)o: ")).lower()
|
skip_webui_install = str(input("\nWould you like to skip stable-diffusion webui installation at each startup? (y)es or (n)o: ")).lower()
|
||||||
while (skip_webui_install != "yes") and (skip_webui_install != "y") and (skip_webui_install != "no") and (skip_webui_install != "n"):
|
while (skip_webui_install != "yes") and (skip_webui_install != "y") and (skip_webui_install != "no") and (skip_webui_install != "n"):
|
||||||
print("\nPlease choose a valid response (y)es or (n)o")
|
print("\nPlease choose a valid response (y)es or (n)o")
|
||||||
skip_webui_install = str(input("Would you like to skip stable-diffusion webui installation at each startup? (y)es or (n)o: ")).lower()
|
skip_webui_install = str(input("Would you like to skip stable-diffusion webui installation at each startup? (y)es or (n)o: ")).lower()
|
||||||
if (skip_webui_install == "yes") or (skip_webui_install == "y"):
|
if (skip_webui_install == "yes") or (skip_webui_install == "y"):
|
||||||
## TODO
|
new_commandline_args += "--skip-install "
|
||||||
pass
|
|
||||||
|
|
||||||
# Perform checks and set variables
|
## Perform checks and set variables
|
||||||
|
# GPU brand
|
||||||
|
gpu_brand = get_gpu_brand()
|
||||||
|
if (gpu_brand == "NVIDIA"):
|
||||||
|
new_commandline_args += "--xformers "
|
||||||
|
|
||||||
|
# VRAM check
|
||||||
vram_low_med = vram_check()
|
vram_low_med = vram_check()
|
||||||
|
|
||||||
if vram_low_med == 0:
|
if (vram_low_med == 0):
|
||||||
pass
|
pass
|
||||||
elif vram_low_med == 1:
|
elif (vram_low_med == 1):
|
||||||
# TODO
|
|
||||||
print("Medium vram")
|
print("Medium vram")
|
||||||
elif vram_low_med == 2:
|
new_commandline_args += "--medvram "
|
||||||
# TODO
|
elif (vram_low_med == 2):
|
||||||
print("Low vram")
|
print("Low vram")
|
||||||
|
new_commandline_args += "--lowvram "
|
||||||
else:
|
else:
|
||||||
print("NVIDIA GPU or driver not found.")
|
pass
|
||||||
|
|
||||||
|
# Ask user to confirm command line arguments, perform command line argument write
|
||||||
|
print("\"", new_commandline_args, "\"")
|
||||||
|
confirm_write = str(input("\nWould you like to set these arguments?\nPlease note that this will get rid of any existing arguments\n(y)es or (n)o: ")).lower()
|
||||||
|
while (confirm_write != "yes") and (confirm_write != "y") and (confirm_write != "no") and (confirm_write != "n"):
|
||||||
|
print("\nPlease choose a valid response (y)es or (n)o")
|
||||||
|
confirm_write = str(input("Would you like to skip stable-diffusion webui installation at each startup? (y)es or (n)o: ")).lower()
|
||||||
|
if (confirm_write == "yes") or (confirm_write == "y"):
|
||||||
|
write_commandline_args(new_commandline_args)
|
||||||
|
|
||||||
# Checks if we should skip loading the startup checks
|
# Checks if we should skip loading the startup checks
|
||||||
skip_startup_checks = startup_skip_check()
|
skip_startup_checks = startup_skip_check()
|
||||||
|
Loading…
Reference in New Issue
Block a user