mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-10 17:14:36 +00:00
added option to unload model from admin control
This commit is contained in:
parent
08e0745e7e
commit
c923e9fe46
1 changed files with 19 additions and 8 deletions
27
koboldcpp.py
27
koboldcpp.py
|
@ -2946,6 +2946,7 @@ Change Mode<br>
|
||||||
if args.admin and args.admindir and os.path.exists(args.admindir) and self.check_header_password(args.adminpassword):
|
if args.admin and args.admindir and os.path.exists(args.admindir) and self.check_header_password(args.adminpassword):
|
||||||
dirpath = os.path.abspath(args.admindir)
|
dirpath = os.path.abspath(args.admindir)
|
||||||
opts = [f for f in sorted(os.listdir(dirpath)) if (f.endswith(".kcpps") or f.endswith(".kcppt") or f.endswith(".gguf")) and os.path.isfile(os.path.join(dirpath, f))]
|
opts = [f for f in sorted(os.listdir(dirpath)) if (f.endswith(".kcpps") or f.endswith(".kcppt") or f.endswith(".gguf")) and os.path.isfile(os.path.join(dirpath, f))]
|
||||||
|
opts.append("unload_model")
|
||||||
response_body = (json.dumps(opts).encode())
|
response_body = (json.dumps(opts).encode())
|
||||||
|
|
||||||
elif self.path.endswith(('/api/extra/perf')):
|
elif self.path.endswith(('/api/extra/perf')):
|
||||||
|
@ -3437,13 +3438,18 @@ Change Mode<br>
|
||||||
except Exception:
|
except Exception:
|
||||||
targetfile = ""
|
targetfile = ""
|
||||||
if targetfile and targetfile!="":
|
if targetfile and targetfile!="":
|
||||||
dirpath = os.path.abspath(args.admindir)
|
if targetfile=="unload_model": #special request to simply unload model
|
||||||
targetfilepath = os.path.join(dirpath, targetfile)
|
print("Admin: Received request to unload model")
|
||||||
opts = [f for f in os.listdir(dirpath) if (f.lower().endswith(".kcpps") or f.lower().endswith(".kcppt") or f.lower().endswith(".gguf")) and os.path.isfile(os.path.join(dirpath, f))]
|
global_memory["restart_target"] = "unload_model"
|
||||||
if targetfile in opts and os.path.exists(targetfilepath):
|
|
||||||
print(f"Admin: Received request to reload config to {targetfile}")
|
|
||||||
global_memory["restart_target"] = targetfile
|
|
||||||
resp = {"success": True}
|
resp = {"success": True}
|
||||||
|
else:
|
||||||
|
dirpath = os.path.abspath(args.admindir)
|
||||||
|
targetfilepath = os.path.join(dirpath, targetfile)
|
||||||
|
opts = [f for f in os.listdir(dirpath) if (f.lower().endswith(".kcpps") or f.lower().endswith(".kcppt") or f.lower().endswith(".gguf")) and os.path.isfile(os.path.join(dirpath, f))]
|
||||||
|
if targetfile in opts and os.path.exists(targetfilepath):
|
||||||
|
print(f"Admin: Received request to reload config to {targetfile}")
|
||||||
|
global_memory["restart_target"] = targetfile
|
||||||
|
resp = {"success": True}
|
||||||
response_body = (json.dumps(resp).encode())
|
response_body = (json.dumps(resp).encode())
|
||||||
|
|
||||||
elif self.path.endswith('/set_tts_settings'): #return dummy response
|
elif self.path.endswith('/set_tts_settings'): #return dummy response
|
||||||
|
@ -6139,7 +6145,7 @@ def main(launch_args, default_args):
|
||||||
if args.admin and args.admindir:
|
if args.admin and args.admindir:
|
||||||
dirpath = os.path.abspath(args.admindir)
|
dirpath = os.path.abspath(args.admindir)
|
||||||
targetfilepath = os.path.join(dirpath, restart_target)
|
targetfilepath = os.path.join(dirpath, restart_target)
|
||||||
if os.path.exists(targetfilepath):
|
if os.path.exists(targetfilepath) or restart_target=="unload_model":
|
||||||
print("Terminating old process...")
|
print("Terminating old process...")
|
||||||
global_memory["load_complete"] = False
|
global_memory["load_complete"] = False
|
||||||
kcpp_instance.terminate()
|
kcpp_instance.terminate()
|
||||||
|
@ -6147,7 +6153,12 @@ def main(launch_args, default_args):
|
||||||
kcpp_instance = None
|
kcpp_instance = None
|
||||||
print("Restarting KoboldCpp...")
|
print("Restarting KoboldCpp...")
|
||||||
fault_recovery_mode = True
|
fault_recovery_mode = True
|
||||||
if targetfilepath.endswith(".gguf"):
|
if restart_target=="unload_model":
|
||||||
|
reload_from_new_args(vars(default_args))
|
||||||
|
args.model_param = None
|
||||||
|
args.model = None
|
||||||
|
args.nomodel = True
|
||||||
|
elif targetfilepath.endswith(".gguf"):
|
||||||
reload_from_new_args(vars(default_args))
|
reload_from_new_args(vars(default_args))
|
||||||
args.model_param = targetfilepath
|
args.model_param = targetfilepath
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue