Skip to content

Commit 521ad6b

Browse files
committed
lazy import_var error handling for saves
1 parent 9553e52 commit 521ad6b

File tree

1 file changed

+102
-67
lines changed

1 file changed

+102
-67
lines changed

koboldcpp.py

+102-67
Original file line numberDiff line numberDiff line change
@@ -1070,77 +1070,112 @@ def import_vars(dict):
10701070
smartcontext.set(1 if dict["smartcontext"] else 0)
10711071
unbantokens.set(1 if dict["unbantokens"] else 0)
10721072
runopts_var.set(runopts[0])
1073-
if dict["useclblast"]:
1074-
runopts_var.set(runopts[1])
1075-
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
1076-
elif dict["usecublas"]:
1077-
runopts_var.set(runopts[2])
1078-
if len(dict["usecublas"])==1:
1079-
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
1080-
else:
1081-
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
1082-
gpu_choice_var.set("1")
1083-
for g in range(3):
1084-
if str(g) in dict["usecublas"]:
1085-
gpu_choice_var.set(str(g+1))
1086-
break
1087-
if dict["gpulayers"]:
1088-
gpulayers_var.set(dict["gpulayers"])
1089-
1090-
if dict["noblas"] and dict["noavx2"]:
1091-
runopts_var.set(runopts[5])
1092-
elif dict["noavx2"]:
1093-
runopts_var.set(runopts[5])
1094-
elif dict["noblas"]:
1095-
runopts_var.set(runopts[3])
1096-
if dict["blasthreads"]:
1097-
blas_threads_var.set(str(dict["blasthreads"]))
1098-
else:
1099-
blas_threads_var.set("")
1100-
1101-
if dict["contextsize"]:
1102-
context_var.set(contextsize_text.index(str(dict["contextsize"])))
1073+
try:
1074+
if dict["useclblast"]:
1075+
runopts_var.set(runopts[1])
1076+
gpu_choice_var.set(str(["0 0", "1 0", "0 1"].index(str(dict["useclblast"][0]) + " " + str(dict["useclblast"][1])) + 1))
1077+
elif dict["usecublas"]:
1078+
runopts_var.set(runopts[2])
1079+
if len(dict["usecublas"])==1:
1080+
lowvram_var.set(1 if dict["usecublas"][0]=="lowvram" else 0)
1081+
else:
1082+
lowvram_var.set(1 if "lowvram" in dict["usecublas"] else 0)
1083+
gpu_choice_var.set("1")
1084+
for g in range(3):
1085+
if str(g) in dict["usecublas"]:
1086+
gpu_choice_var.set(str(g+1))
1087+
break
1088+
except (KeyError, IndexError):
1089+
pass
11031090

1104-
if dict["ropeconfig"] and len(dict["ropeconfig"])>1:
1105-
if dict["ropeconfig"][0]>0:
1106-
customrope_var.set(1)
1107-
customrope_scale.set(str(dict["ropeconfig"][0]))
1108-
customrope_base.set(str(dict["ropeconfig"][1]))
1109-
else:
1110-
customrope_var.set(0)
1111-
1112-
if dict["blasbatchsize"]:
1113-
blas_size_var.set(blasbatchsize_values.index(str(dict["blasbatchsize"])))
1114-
if dict["forceversion"]:
1115-
version_var.set(str(dict["forceversion"]))
1116-
1117-
if dict["mirostat"] and len(dict["mirostat"])>1:
1118-
usemirostat.set(0 if str(dict["mirostat"][0])=="0" else 1)
1119-
mirostat_var.set(str(dict["mirostat"][0]))
1120-
mirostat_tau.set(str(dict["mirostat"][1]))
1121-
mirostat_eta.set(str(dict["mirostat"][2]))
1122-
1123-
if dict["model_param"]:
1124-
model_var.set(dict["model_param"])
1125-
1126-
if dict["lora"]:
1127-
if len(dict["lora"]) > 1:
1128-
lora_var.set(dict["lora"][0])
1129-
lora_base_var.set(dict["lora"][1])
1091+
try:
1092+
if dict["gpulayers"]:
1093+
gpulayers_var.set(dict["gpulayers"])
1094+
except (KeyError, IndexError):
1095+
pass
1096+
try:
1097+
if dict["noblas"] and dict["noavx2"]:
1098+
runopts_var.set(runopts[5])
1099+
elif dict["noavx2"]:
1100+
runopts_var.set(runopts[5])
1101+
elif dict["noblas"]:
1102+
runopts_var.set(runopts[3])
1103+
except (KeyError, IndexError):
1104+
pass
1105+
try:
1106+
if dict["blasthreads"]:
1107+
blas_threads_var.set(str(dict["blasthreads"]))
11301108
else:
1131-
lora_var.set(dict["lora"][0])
1132-
1133-
if dict["port_param"]:
1134-
port_var.set(dict["port_param"])
1135-
1136-
if dict["host"]:
1137-
host_var.set(dict["host"])
1109+
blas_threads_var.set("")
1110+
except (KeyError, IndexError):
1111+
pass
1112+
try:
1113+
if dict["contextsize"]:
1114+
context_var.set(contextsize_text.index(str(dict["contextsize"])))
1115+
except (KeyError, IndexError):
1116+
pass
1117+
try:
1118+
if dict["ropeconfig"] and len(dict["ropeconfig"])>1:
1119+
if dict["ropeconfig"][0]>0:
1120+
customrope_var.set(1)
1121+
customrope_scale.set(str(dict["ropeconfig"][0]))
1122+
customrope_base.set(str(dict["ropeconfig"][1]))
1123+
else:
1124+
customrope_var.set(0)
1125+
except (KeyError, IndexError):
1126+
pass
1127+
try:
1128+
if dict["blasbatchsize"]:
1129+
blas_size_var.set(blasbatchsize_values.index(str(dict["blasbatchsize"])))
1130+
except (KeyError, IndexError):
1131+
pass
1132+
try:
1133+
if dict["forceversion"]:
1134+
version_var.set(str(dict["forceversion"]))
1135+
except (KeyError, IndexError):
1136+
pass
1137+
try:
1138+
if dict["mirostat"] and len(dict["mirostat"])>1:
1139+
usemirostat.set(0 if str(dict["mirostat"][0])=="0" else 1)
1140+
mirostat_var.set(str(dict["mirostat"][0]))
1141+
mirostat_tau.set(str(dict["mirostat"][1]))
1142+
mirostat_eta.set(str(dict["mirostat"][2]))
1143+
except (KeyError, IndexError):
1144+
pass
1145+
try:
1146+
if dict["model_param"]:
1147+
model_var.set(dict["model_param"])
1148+
except (KeyError, IndexError):
1149+
pass
1150+
try:
1151+
if dict["lora"]:
1152+
if len(dict["lora"]) > 1:
1153+
lora_var.set(dict["lora"][0])
1154+
lora_base_var.set(dict["lora"][1])
1155+
else:
1156+
lora_var.set(dict["lora"][0])
1157+
except (KeyError, IndexError):
1158+
pass
1159+
try:
1160+
if dict["port_param"]:
1161+
port_var.set(dict["port_param"])
1162+
except (KeyError, IndexError):
1163+
pass
1164+
try:
1165+
if dict["host"]:
1166+
host_var.set(dict["host"])
1167+
except (KeyError, IndexError):
1168+
pass
1169+
try:
1170+
if dict["hordeconfig"] and len(dict["hordeconfig"]) > 1:
1171+
horde_name_var.set(dict["hordeconfig"][0])
1172+
horde_gen_var.set(dict["hordeconfig"][1])
1173+
horde_context_var.set(dict["hordeconfig"][2])
1174+
except (KeyError, IndexError):
1175+
pass
11381176

1139-
if dict["hordeconfig"] and len(dict["hordeconfig"]) > 1:
1140-
horde_name_var.set(dict["hordeconfig"][0])
1141-
horde_gen_var.set(dict["hordeconfig"][1])
1142-
horde_context_var.set(dict["hordeconfig"][2])
11431177

1178+
11441179
def save_config():
11451180
file_type = [("KoboldCpp Settings", "*.kcpps")]
11461181
filename = asksaveasfile(filetypes=file_type, defaultextension=file_type)

0 commit comments

Comments
 (0)