Skip to content

Commit cee2e9d

Browse files
committed
Only Show Available Backends in GUI
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
1 parent 7863610 commit cee2e9d

File tree

1 file changed

+52
-32
lines changed

1 file changed

+52
-32
lines changed

koboldcpp.py

+52-32
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,21 @@ def show_new_gui():
686686

687687
tabcontent = {}
688688

689+
lib_option_pairs = [
690+
(lib_openblas, "Use OpenBLAS"),
691+
(lib_clblast, "Use CLBlast"),
692+
(lib_cublas, "Use CuBLAS/hipBLAS"),
693+
(lib_default, "Use No BLAS"),
694+
(lib_openblas_noavx2, "Use OpenBLAS (Old CPU, noavx2)"),
695+
(lib_failsafe, "Failsafe Mode (Old CPU, noavx)")]
696+
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)
689697
# slider data
690698
blasbatchsize_values = ["-1", "32", "64", "128", "256", "512", "1024"]
691699
blasbatchsize_text = ["Don't Batch BLAS","32","64","128","256","512","1024"]
692700
contextsize_text = ["512", "1024", "2048", "3072", "4096", "6144", "8192"]
693-
runopts = ["Use OpenBLAS","Use CLBlast", "Use CuBLAS/hipBLAS", "Use No BLAS","Use OpenBLAS (Old CPU, noavx2)","Failsafe Mode (Old CPU, noavx)"]
694-
701+
runopts = [opt for lib, opt in lib_option_pairs if file_exists(lib) or os.name == 'nt' and file_exists(opt + ".dll")]
702+
if not any(runopts):
703+
show_gui_warning("No Backend Available")
695704
def tabbuttonaction(name):
696705
for t in tabcontent:
697706
if name == t:
@@ -884,7 +893,7 @@ def changerunmode(a,b,c):
884893

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

889898
# threads
890899
makelabelentry(quick_tab, "Threads:" , threads_var, 8, 50)
@@ -917,7 +926,7 @@ def changerunmode(a,b,c):
917926
makelabel(hardware_tab, "Presets:", 1)
918927
runoptbox = ctk.CTkComboBox(hardware_tab, values=runopts, width=180,variable=runopts_var, state="readonly")
919928
runoptbox.grid(row=1, column=1,padx=8, stick="nw")
920-
runoptbox.set("Use OpenBLAS")
929+
runoptbox.set(runopts[0])
921930
runopts_var.trace('w', changerunmode)
922931
changerunmode(1,1,1)
923932
# threads
@@ -1043,26 +1052,26 @@ def export_vars():
10431052
args.unbantokens = unbantokens.get()==1
10441053
gpuchoiceidx = 0
10451054
if gpu_choice_var.get()!="All":
1046-
if runopts_var.get() == runopts[1]: #if CLBlast selected
1055+
if runopts_var.get() == "Use CLBlast": #if CLBlast selected
10471056
if (gpu_choice_var.get()) in CLdevices:
10481057
gpuchoiceidx = CLdevices.index((gpu_choice_var.get()))
1049-
elif runopts_var.get() == runopts[2]:
1058+
elif runopts_var.get() == "Use CuBLAS/hipBLAS":
10501059
if (gpu_choice_var.get()) in CUdevices:
10511060
gpuchoiceidx = CUdevices.index((gpu_choice_var.get()))
1052-
if runopts_var.get() == runopts[1]:
1061+
if runopts_var.get() == "Use CLBlast":
10531062
args.useclblast = [[0,0], [1,0], [0,1]][gpuchoiceidx]
1054-
if runopts_var.get() == runopts[2]:
1063+
if runopts_var.get() == "Use CuBLAS/hipBLAS":
10551064
if gpu_choice_var.get()=="All":
10561065
args.usecublas = ["lowvram"] if lowvram_var.get() == 1 else ["normal"]
10571066
else:
10581067
args.usecublas = ["lowvram",str(gpuchoiceidx)] if lowvram_var.get() == 1 else ["normal",str(gpuchoiceidx)]
10591068
if gpulayers_var.get():
10601069
args.gpulayers = int(gpulayers_var.get())
1061-
if runopts_var.get()==runopts[3]:
1070+
if runopts_var.get()=="Use No BLAS":
10621071
args.noblas = True
1063-
if runopts_var.get()==runopts[4]:
1072+
if runopts_var.get()=="Use OpenBLAS (Old CPU, noavx2)":
10641073
args.noavx2 = True
1065-
if runopts_var.get()==runopts[5]:
1074+
if runopts_var.get()=="Failsafe Mode (Old CPU, noavx)":
10661075
args.noavx2 = True
10671076
args.noblas = True
10681077
args.nommap = True
@@ -1101,38 +1110,42 @@ def import_vars(dict):
11011110
stream.set(1 if "stream" in dict and dict["stream"] else 0)
11021111
smartcontext.set(1 if "smartcontext" in dict and dict["smartcontext"] else 0)
11031112
unbantokens.set(1 if "unbantokens" in dict and dict["unbantokens"] else 0)
1104-
runopts_var.set(runopts[0])
11051113
if "useclblast" in dict and dict["useclblast"]:
1106-
runopts_var.set(runopts[1])
1107-
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
1114+
if clblast_option is not None:
1115+
runopts_var.set(clblast_option)
1116+
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
11081117
elif "usecublas" in dict and dict["usecublas"]:
1109-
runopts_var.set(runopts[2])
1110-
if len(dict["usecublas"])==1:
1111-
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
1112-
else:
1113-
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
1114-
gpu_choice_var.set("1")
1115-
for g in range(3):
1116-
if str(g) in dict["usecublas"]:
1117-
gpu_choice_var.set(str(g+1))
1118-
break
1118+
if cublas_option is not None:
1119+
runopts_var.set(cublas_option)
1120+
if len(dict["usecublas"])==1:
1121+
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
1122+
else:
1123+
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
1124+
gpu_choice_var.set("1")
1125+
for g in range(3):
1126+
if str(g) in dict["usecublas"]:
1127+
gpu_choice_var.set(str(g+1))
1128+
break
11191129
if "gpulayers" in dict and dict["gpulayers"]:
11201130
gpulayers_var.set(dict["gpulayers"])
11211131

11221132
if "noavx2" in dict and "noblas" in dict and dict["noblas"] and dict["noavx2"]:
1123-
runopts_var.set(runopts[5])
1133+
if failsafe_option is not None:
1134+
runopts_var.set(failsafe_option)
11241135
elif "noavx2" in dict and dict["noavx2"]:
1125-
runopts_var.set(runopts[4])
1136+
if openblas_noavx2_option is not None:
1137+
runopts_var.set(openblas_noavx2_option)
11261138
elif "noblas" in dict and dict["noblas"]:
1127-
runopts_var.set(runopts[3])
1139+
if default_option is not None:
1140+
runopts_var.set(default_option)
1141+
elif openblas_option is not None:
1142+
runopts_var.set(openblas_option)
11281143
if "blasthreads" in dict and dict["blasthreads"]:
11291144
blas_threads_var.set(str(dict["blasthreads"]))
11301145
else:
11311146
blas_threads_var.set("")
1132-
11331147
if "contextsize" in dict and dict["contextsize"]:
11341148
context_var.set(contextsize_text.index(str(dict["contextsize"])))
1135-
11361149
if "ropeconfig" in dict and dict["ropeconfig"] and len(dict["ropeconfig"])>1:
11371150
if dict["ropeconfig"][0]>0:
11381151
customrope_var.set(1)
@@ -1223,13 +1236,20 @@ def load_config():
12231236
time.sleep(2)
12241237
sys.exit(2)
12251238

1226-
def show_gui_warning():
1239+
def show_gui_warning(issue=None):
12271240
from tkinter import messagebox
12281241
import tkinter as tk
12291242
root = tk.Tk()
12301243
root.attributes("-alpha", 0)
1231-
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.")
1232-
root.destroy()
1244+
if issue == "No Backend Available":
1245+
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.")
1246+
root.destroy()
1247+
print("No Backend Available (i.e Default, OpenBLAS, CLBlast, CuBLAS). To use the program, please run the 'make' command from the directory.")
1248+
time.sleep(2)
1249+
sys.exit(2)
1250+
else:
1251+
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.")
1252+
root.destroy()
12331253

12341254
def show_old_gui():
12351255
import tkinter as tk

0 commit comments

Comments
 (0)