Skip to content

Commit b246d83

Browse files
committed
fixed some global reference
1 parent ff9b404 commit b246d83

File tree

2 files changed

+59
-77
lines changed

2 files changed

+59
-77
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ if (LLAMA_HIPBLAS)
171171
message(STATUS "HIP and hipBLAS found")
172172
file(GLOB GGML_SOURCES_ROCM "ggml/src/ggml-cuda/*.cu")
173173
list(APPEND GGML_SOURCES_ROCM "ggml/src/ggml-cuda/ggml-cuda.cu")
174-
file(GLOB SRCS "ggml/src/ggml-cuda/template-instances/fattn-wmma*.cu")
174+
file(GLOB SRCS "ggml/src/ggml-cuda/template-instances/fattn-mma*.cu")
175175
list(APPEND GGML_SOURCES_ROCM ${SRCS})
176176
file(GLOB SRCS "ggml/src/ggml-cuda/template-instances/mmq*.cu")
177177
list(APPEND GGML_SOURCES_ROCM ${SRCS})

koboldcpp.py

Lines changed: 58 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
dry_seq_break_max = 128
4848

4949
# global vars
50+
KcppVersion = "1.83"
51+
showdebug = True
52+
guimode = False
53+
kcpp_instance = None #global running instance
54+
global_memory = None
55+
using_gui_launcher = False
56+
5057
handle = None
5158
friendlymodelname = "inactive"
5259
friendlysdmodelname = "inactive"
@@ -62,9 +69,6 @@
6269
modelbusy = threading.Lock()
6370
requestsinqueue = 0
6471
defaultport = 5001
65-
KcppVersion = "1.83"
66-
showdebug = True
67-
guimode = False
6872
showsamplerwarning = True
6973
showmaxctxwarning = True
7074
showusedmemwarning = True
@@ -100,10 +104,7 @@
100104
last_req_time = time.time()
101105
last_non_horde_req_time = time.time()
102106
currfinishreason = "null"
103-
using_gui_launcher = False
104-
using_outdated_flags = False
105-
kcpp_instance = None #global running instance
106-
global_memory = None
107+
107108

108109
saved_stdout = None
109110
saved_stderr = None
@@ -4624,11 +4625,7 @@ def convert_outdated_args(args):
46244625
dict = args
46254626
if isinstance(args, argparse.Namespace):
46264627
dict = vars(args)
4627-
4628-
global using_outdated_flags
4629-
using_outdated_flags = False
46304628
if "sdconfig" in dict and dict["sdconfig"] and len(dict["sdconfig"])>0:
4631-
using_outdated_flags = True
46324629
dict["sdmodel"] = dict["sdconfig"][0]
46334630
if dict["sdconfig"] and len(dict["sdconfig"]) > 1:
46344631
dict["sdclamped"] = 512
@@ -4637,7 +4634,6 @@ def convert_outdated_args(args):
46374634
if dict["sdconfig"] and len(dict["sdconfig"]) > 3:
46384635
dict["sdquant"] = (True if dict["sdconfig"][3]=="quant" else False)
46394636
if "hordeconfig" in dict and dict["hordeconfig"] and dict["hordeconfig"][0]!="":
4640-
using_outdated_flags = True
46414637
dict["hordemodelname"] = dict["hordeconfig"][0]
46424638
if len(dict["hordeconfig"]) > 1:
46434639
dict["hordegenlen"] = int(dict["hordeconfig"][1])
@@ -4648,33 +4644,12 @@ def convert_outdated_args(args):
46484644
dict["hordeworkername"] = dict["hordeconfig"][4]
46494645
if "noblas" in dict and dict["noblas"]:
46504646
dict["usecpu"] = True
4651-
46524647
if "failsafe" in dict and dict["failsafe"]: #failsafe implies noavx2
46534648
dict["noavx2"] = True
4654-
46554649
if ("model_param" not in dict or not dict["model_param"]) and ("model" in dict and dict["model"]):
46564650
dict["model_param"] = dict["model"]
4657-
4658-
check_deprecation_warning()
46594651
return args
46604652

4661-
def check_deprecation_warning():
4662-
# slightly naggy warning to encourage people to switch to new flags
4663-
# if you want you can remove this at your own risk,
4664-
# but i am not going to troubleshoot or provide support for deprecated flags.
4665-
global using_outdated_flags
4666-
if using_outdated_flags:
4667-
print("\n=== !!! IMPORTANT WARNING !!! ===")
4668-
print("You are using one or more OUTDATED config files or launch flags!")
4669-
print("The flags --hordeconfig and --sdconfig have been DEPRECATED, and MAY be REMOVED in future!")
4670-
print("They will still work for now, but you SHOULD switch to the updated flags instead, to avoid future issues!")
4671-
print("New flags are: --hordemodelname --hordeworkername --hordekey --hordemaxctx --hordegenlen --sdmodel --sdthreads --sdquant --sdclamped")
4672-
print("For more information on these flags, please check --help")
4673-
print(">>> If you are using the GUI launcher, simply re-saving your config again will get rid of this warning.")
4674-
print("=== !!! IMPORTANT WARNING !!! ===\n")
4675-
4676-
4677-
46784653
def setuptunnel(global_memory, has_sd):
46794654
# This script will help setup a cloudflared tunnel for accessing KoboldCpp over the internet
46804655
# It should work out of the box on both linux and windows
@@ -4829,8 +4804,12 @@ def reload_new_config(filename): #for changing config after launch
48294804
config = json.load(f)
48304805
args.istemplate = False
48314806
for key, value in config.items(): #do not overwrite certain values
4832-
if key not in ["remotetunnel","port","host","port_param","admin","adminpassword","admindir","ssl","nocertify","benchmark","prompt"]:
4807+
if key not in ["remotetunnel","showgui","port","host","port_param","admin","adminpassword","admindir","ssl","nocertify","benchmark","prompt","config"]:
48334808
setattr(args, key, value)
4809+
setattr(args,"showgui",False)
4810+
setattr(args,"benchmark",False)
4811+
setattr(args,"prompt","")
4812+
setattr(args,"config",None)
48344813

48354814
def load_config_cli(filename):
48364815
print("Loading .kcpps configuration file...")
@@ -4941,7 +4920,7 @@ def analyze_gguf_model_wrapper(filename=""):
49414920
dumpthread = threading.Thread(target=analyze_gguf_model, args=(args,filename))
49424921
dumpthread.start()
49434922

4944-
def main(launch_args,start_server=True):
4923+
def main(launch_args):
49454924
global args, showdebug, kcpp_instance, exitcounter
49464925
args = launch_args #note: these are NOT shared with the child processes!
49474926

@@ -4954,15 +4933,13 @@ def main(launch_args,start_server=True):
49544933
exit_with_error(1, "Error: Using --quantkv requires --flashattention")
49554934

49564935
args = convert_outdated_args(args)
4936+
if not ((args.model_param or args.model) and args.prompt and not args.benchmark and not (args.debugmode >= 1)):
4937+
print(f"***\nWelcome to KoboldCpp - Version {KcppVersion}")
4938+
if args.debugmode != 1:
4939+
showdebug = False #not shared with child process!
49574940

4958-
if (args.model_param or args.model) and args.prompt and not args.benchmark and not (args.debugmode >= 1):
4959-
suppress_stdout()
4960-
4961-
print(f"***\nWelcome to KoboldCpp - Version {KcppVersion}") # just update version manually
4962-
4963-
#perform some basic cleanup of old temporary directories
49644941
try:
4965-
delete_old_pyinstaller()
4942+
delete_old_pyinstaller() #perform some basic cleanup of old temporary directories
49664943
except Exception as e:
49674944
print(f"Error cleaning up orphaned pyinstaller dirs: {e}")
49684945

@@ -4974,10 +4951,7 @@ def main(launch_args,start_server=True):
49744951
analyze_gguf_model_wrapper(args.analyze)
49754952
return
49764953

4977-
if args.debugmode != 1:
4978-
showdebug = False #not shared with child process!
4979-
4980-
if args.config and len(args.config)==1: #handle config loading for launch
4954+
if args.config and len(args.config)==1: #handle initial config loading for launch
49814955
cfgname = args.config[0]
49824956
if isinstance(cfgname, str):
49834957
dlfile = download_model_from_url(cfgname,[".kcpps",".kcppt"])
@@ -4999,35 +4973,15 @@ def main(launch_args,start_server=True):
49994973
args.model_param = dlfile
50004974
load_config_cli(args.model_param)
50014975

5002-
# lastly, show the GUI launcher if a model was not provided
5003-
if args.showgui or (not args.model_param and not args.sdmodel and not args.whispermodel and not args.ttsmodel and not args.nomodel):
5004-
#give them a chance to pick a file
5005-
print("For command line arguments, please refer to --help")
5006-
print("***")
5007-
try:
5008-
show_gui()
5009-
except Exception as ex:
5010-
exitcounter = 999
5011-
ermsg = "Reason: " + str(ex) + "\nFile selection GUI unsupported.\ncustomtkinter python module required!\n\nYou must use the command line instead, e.g. python ./koboldcpp.py --help"
5012-
show_gui_msgbox("Warning, GUI failed to start",ermsg)
5013-
if args.skiplauncher:
5014-
print("Note: In order to use --skiplauncher, you need to specify a model with --model")
5015-
time.sleep(3)
5016-
sys.exit(2)
5017-
5018-
if args.model_param and (args.benchmark or args.prompt):
5019-
start_server = False
5020-
50214976
# manager command queue
5022-
multiprocessing.freeze_support()
50234977
with multiprocessing.Manager() as mp_manager:
5024-
global_memory = mp_manager.dict({"tunnel_url": "", "restart_target":""})
4978+
global_memory = mp_manager.dict({"tunnel_url": "", "restart_target":"", "input_to_exit":False})
50254979

5026-
if start_server and args.remotetunnel:
4980+
if args.remotetunnel and not args.prompt and not args.benchmark:
50274981
setuptunnel(global_memory, True if args.sdmodel else False)
50284982

50294983
# invoke the main koboldcpp process
5030-
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "start_server": start_server, "g_memory": global_memory})
4984+
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory})
50314985
kcpp_instance.daemon = True
50324986
kcpp_instance.start()
50334987

@@ -5051,7 +5005,7 @@ def main(launch_args,start_server=True):
50515005
kcpp_instance = None
50525006
print("Restarting KoboldCpp...")
50535007
reload_new_config(targetfilepath)
5054-
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "start_server": start_server, "g_memory": global_memory})
5008+
kcpp_instance = multiprocessing.Process(target=kcpp_main_process,kwargs={"launch_args": args, "g_memory": global_memory})
50555009
kcpp_instance.daemon = True
50565010
kcpp_instance.start()
50575011
global_memory["restart_target"] = ""
@@ -5060,15 +5014,43 @@ def main(launch_args,start_server=True):
50605014
time.sleep(0.2)
50615015
except (KeyboardInterrupt,SystemExit):
50625016
break
5017+
if global_memory["input_to_exit"]:
5018+
print("===")
5019+
print("Press ENTER key to exit.", flush=True)
5020+
input()
50635021

5064-
def kcpp_main_process(launch_args, start_server=True, g_memory=None):
5022+
def kcpp_main_process(launch_args, g_memory=None):
50655023
global embedded_kailite, embedded_kcpp_docs, embedded_kcpp_sdui, start_time, exitcounter, global_memory
50665024
global libname, args, friendlymodelname, friendlysdmodelname, fullsdmodelpath, mmprojpath, password, fullwhispermodelpath, ttsmodelpath
50675025

5026+
start_server = True
5027+
50685028
args = launch_args
50695029
global_memory = g_memory
50705030
start_time = time.time()
50715031

5032+
if (args.model_param or args.model) and args.prompt and not args.benchmark and not (args.debugmode >= 1):
5033+
suppress_stdout()
5034+
5035+
# show the GUI launcher if a model was not provided
5036+
if args.showgui or (not args.model_param and not args.sdmodel and not args.whispermodel and not args.ttsmodel and not args.nomodel):
5037+
#give them a chance to pick a file
5038+
print("For command line arguments, please refer to --help")
5039+
print("***")
5040+
try:
5041+
show_gui()
5042+
except Exception as ex:
5043+
exitcounter = 999
5044+
ermsg = "Reason: " + str(ex) + "\nFile selection GUI unsupported.\ncustomtkinter python module required!\n\nYou must use the command line instead, e.g. python ./koboldcpp.py --help"
5045+
show_gui_msgbox("Warning, GUI failed to start",ermsg)
5046+
if args.skiplauncher:
5047+
print("Note: In order to use --skiplauncher, you need to specify a model with --model")
5048+
time.sleep(3)
5049+
sys.exit(2)
5050+
5051+
if args.model_param and (args.benchmark or args.prompt):
5052+
start_server = False
5053+
50725054
#try to read story if provided
50735055
if args.preloadstory:
50745056
global preloaded_story
@@ -5644,11 +5626,9 @@ def onready_subprocess():
56445626
print(f"Error writing benchmark to file: {e}")
56455627
global using_gui_launcher
56465628
if using_gui_launcher and not save_to_file:
5647-
print("===")
5648-
print("Press ENTER key to exit.", flush=True)
5649-
input()
5629+
global_memory["input_to_exit"] = True
5630+
time.sleep(1)
56505631

5651-
check_deprecation_warning()
56525632
if start_server:
56535633
if args.remotetunnel:
56545634
if remote_url:
@@ -5663,6 +5643,8 @@ def onready_subprocess():
56635643
print("Server was not started, main function complete. Idling.", flush=True)
56645644

56655645
if __name__ == '__main__':
5646+
import multiprocessing
5647+
multiprocessing.freeze_support()
56665648

56675649
def check_range(value_type, min_value, max_value):
56685650
def range_checker(arg: str):
@@ -5790,4 +5772,4 @@ def range_checker(arg: str):
57905772
compatgroup.add_argument("--noblas", help=argparse.SUPPRESS, action='store_true')
57915773
compatgroup3.add_argument("--nommap", help=argparse.SUPPRESS, action='store_true')
57925774

5793-
main(parser.parse_args(),start_server=True)
5775+
main(parser.parse_args())

0 commit comments

Comments
 (0)