Skip to content

Commit

Permalink
Only Show Available Backends in GUI
Browse files Browse the repository at this point in the history
Hides unavailable backends from the user and if the program is launched without any backends made, it shows an error message to them stating no backends were found and to make them using the 'make' command
  • Loading branch information
YellowRoseCx committed Jul 27, 2023
1 parent 7863610 commit cee2e9d
Showing 1 changed file with 52 additions and 32 deletions.
84 changes: 52 additions & 32 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,12 +686,21 @@ def show_new_gui():

tabcontent = {}

lib_option_pairs = [
(lib_openblas, "Use OpenBLAS"),
(lib_clblast, "Use CLBlast"),
(lib_cublas, "Use CuBLAS/hipBLAS"),
(lib_default, "Use No BLAS"),
(lib_openblas_noavx2, "Use OpenBLAS (Old CPU, noavx2)"),
(lib_failsafe, "Failsafe Mode (Old CPU, noavx)")]
openblas_option, clblast_option, cublas_option, default_option, openblas_noavx2_option, failsafe_option = (opt if file_exists(lib) or (os.name == 'nt' and file_exists(opt + ".dll")) else None for lib, opt in lib_option_pairs)
# slider data
blasbatchsize_values = ["-1", "32", "64", "128", "256", "512", "1024"]
blasbatchsize_text = ["Don't Batch BLAS","32","64","128","256","512","1024"]
contextsize_text = ["512", "1024", "2048", "3072", "4096", "6144", "8192"]
runopts = ["Use OpenBLAS","Use CLBlast", "Use CuBLAS/hipBLAS", "Use No BLAS","Use OpenBLAS (Old CPU, noavx2)","Failsafe Mode (Old CPU, noavx)"]

runopts = [opt for lib, opt in lib_option_pairs if file_exists(lib) or os.name == 'nt' and file_exists(opt + ".dll")]
if not any(runopts):
show_gui_warning("No Backend Available")
def tabbuttonaction(name):
for t in tabcontent:
if name == t:
Expand Down Expand Up @@ -884,7 +893,7 @@ def changerunmode(a,b,c):

runoptbox = ctk.CTkComboBox(quick_tab, values=runopts, width=180,variable=runopts_var, state="readonly")
runoptbox.grid(row=1, column=1,padx=8, stick="nw")
runoptbox.set("Use OpenBLAS")
runoptbox.set(runopts[0])

# threads
makelabelentry(quick_tab, "Threads:" , threads_var, 8, 50)
Expand Down Expand Up @@ -917,7 +926,7 @@ def changerunmode(a,b,c):
makelabel(hardware_tab, "Presets:", 1)
runoptbox = ctk.CTkComboBox(hardware_tab, values=runopts, width=180,variable=runopts_var, state="readonly")
runoptbox.grid(row=1, column=1,padx=8, stick="nw")
runoptbox.set("Use OpenBLAS")
runoptbox.set(runopts[0])
runopts_var.trace('w', changerunmode)
changerunmode(1,1,1)
# threads
Expand Down Expand Up @@ -1043,26 +1052,26 @@ def export_vars():
args.unbantokens = unbantokens.get()==1
gpuchoiceidx = 0
if gpu_choice_var.get()!="All":
if runopts_var.get() == runopts[1]: #if CLBlast selected
if runopts_var.get() == "Use CLBlast": #if CLBlast selected
if (gpu_choice_var.get()) in CLdevices:
gpuchoiceidx = CLdevices.index((gpu_choice_var.get()))
elif runopts_var.get() == runopts[2]:
elif runopts_var.get() == "Use CuBLAS/hipBLAS":
if (gpu_choice_var.get()) in CUdevices:
gpuchoiceidx = CUdevices.index((gpu_choice_var.get()))
if runopts_var.get() == runopts[1]:
if runopts_var.get() == "Use CLBlast":
args.useclblast = [[0,0], [1,0], [0,1]][gpuchoiceidx]
if runopts_var.get() == runopts[2]:
if runopts_var.get() == "Use CuBLAS/hipBLAS":
if gpu_choice_var.get()=="All":
args.usecublas = ["lowvram"] if lowvram_var.get() == 1 else ["normal"]
else:
args.usecublas = ["lowvram",str(gpuchoiceidx)] if lowvram_var.get() == 1 else ["normal",str(gpuchoiceidx)]
if gpulayers_var.get():
args.gpulayers = int(gpulayers_var.get())
if runopts_var.get()==runopts[3]:
if runopts_var.get()=="Use No BLAS":
args.noblas = True
if runopts_var.get()==runopts[4]:
if runopts_var.get()=="Use OpenBLAS (Old CPU, noavx2)":
args.noavx2 = True
if runopts_var.get()==runopts[5]:
if runopts_var.get()=="Failsafe Mode (Old CPU, noavx)":
args.noavx2 = True
args.noblas = True
args.nommap = True
Expand Down Expand Up @@ -1101,38 +1110,42 @@ def import_vars(dict):
stream.set(1 if "stream" in dict and dict["stream"] else 0)
smartcontext.set(1 if "smartcontext" in dict and dict["smartcontext"] else 0)
unbantokens.set(1 if "unbantokens" in dict and dict["unbantokens"] else 0)
runopts_var.set(runopts[0])
if "useclblast" in dict and dict["useclblast"]:
runopts_var.set(runopts[1])
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
if clblast_option is not None:
runopts_var.set(clblast_option)
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
elif "usecublas" in dict and dict["usecublas"]:
runopts_var.set(runopts[2])
if len(dict["usecublas"])==1:
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
else:
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
gpu_choice_var.set("1")
for g in range(3):
if str(g) in dict["usecublas"]:
gpu_choice_var.set(str(g+1))
break
if cublas_option is not None:
runopts_var.set(cublas_option)
if len(dict["usecublas"])==1:
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
else:
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
gpu_choice_var.set("1")
for g in range(3):
if str(g) in dict["usecublas"]:
gpu_choice_var.set(str(g+1))
break
if "gpulayers" in dict and dict["gpulayers"]:
gpulayers_var.set(dict["gpulayers"])

if "noavx2" in dict and "noblas" in dict and dict["noblas"] and dict["noavx2"]:
runopts_var.set(runopts[5])
if failsafe_option is not None:
runopts_var.set(failsafe_option)
elif "noavx2" in dict and dict["noavx2"]:
runopts_var.set(runopts[4])
if openblas_noavx2_option is not None:
runopts_var.set(openblas_noavx2_option)
elif "noblas" in dict and dict["noblas"]:
runopts_var.set(runopts[3])
if default_option is not None:
runopts_var.set(default_option)
elif openblas_option is not None:
runopts_var.set(openblas_option)
if "blasthreads" in dict and dict["blasthreads"]:
blas_threads_var.set(str(dict["blasthreads"]))
else:
blas_threads_var.set("")

if "contextsize" in dict and dict["contextsize"]:
context_var.set(contextsize_text.index(str(dict["contextsize"])))

if "ropeconfig" in dict and dict["ropeconfig"] and len(dict["ropeconfig"])>1:
if dict["ropeconfig"][0]>0:
customrope_var.set(1)
Expand Down Expand Up @@ -1223,13 +1236,20 @@ def load_config():
time.sleep(2)
sys.exit(2)

def show_gui_warning():
def show_gui_warning(issue=None):
from tkinter import messagebox
import tkinter as tk
root = tk.Tk()
root.attributes("-alpha", 0)
messagebox.showerror(title="New GUI failed, using Old GUI", message="The new GUI failed to load.\n\nTo use new GUI, please install the customtkinter python module.")
root.destroy()
if issue == "No Backend Available":
messagebox.showerror(title="No Backends Available!", message="KoboldCPP couldn't locate any backends to use.\n\nTo use the program, please run the 'make' command from the directory.")
root.destroy()
print("No Backend Available (i.e Default, OpenBLAS, CLBlast, CuBLAS). To use the program, please run the 'make' command from the directory.")
time.sleep(2)
sys.exit(2)
else:
messagebox.showerror(title="New GUI failed, using Old GUI", message="The new GUI failed to load.\n\nTo use new GUI, please install the customtkinter python module.")
root.destroy()

def show_old_gui():
import tkinter as tk
Expand Down

0 comments on commit cee2e9d

Please sign in to comment.