mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-17 16:25:01 +02:00
added smartcaching implementation inspired from Pento95 (+2 squashed commit)
Squashed commit: [fcc498688] wip basic smart caching test [b6e8b2577] wip basic smart caching test
This commit is contained in:
+16
-5
@@ -53,7 +53,7 @@ default_draft_amount = 8
|
||||
default_ttsmaxlen = 4096
|
||||
default_visionmaxres = 1024
|
||||
net_save_slots = 12
|
||||
savestate_limit = 3 #3 savestate slots
|
||||
savestate_limit = 4 #savestate slots
|
||||
default_vae_tile_threshold = 768
|
||||
default_native_ctx = 16384
|
||||
overridekv_max = 4
|
||||
@@ -217,6 +217,7 @@ class load_model_inputs(ctypes.Structure):
|
||||
("check_slowness", ctypes.c_bool),
|
||||
("highpriority", ctypes.c_bool),
|
||||
("swa_support", ctypes.c_bool),
|
||||
("smartcache", ctypes.c_bool),
|
||||
("lora_multiplier", ctypes.c_float),
|
||||
("quiet", ctypes.c_bool),
|
||||
("debugmode", ctypes.c_int)]
|
||||
@@ -1519,6 +1520,7 @@ def load_model(model_filename):
|
||||
inputs.check_slowness = (not args.highpriority and os.name == 'nt' and 'Intel' in platform.processor())
|
||||
inputs.highpriority = args.highpriority
|
||||
inputs.swa_support = args.useswa
|
||||
inputs.smartcache = args.smartcache
|
||||
inputs = set_backend_props(inputs)
|
||||
ret = handle.load_model(inputs)
|
||||
return ret
|
||||
@@ -4344,7 +4346,7 @@ Change Mode<br>
|
||||
if self.path.endswith('/api/admin/check_state'):
|
||||
if global_memory and args.admin and args.admindir and os.path.exists(args.admindir) and self.check_header_password(args.adminpassword):
|
||||
cur_states = []
|
||||
for sl in range(savestate_limit): #0,1,2
|
||||
for sl in range(savestate_limit): #0,1,2,3
|
||||
oldstate = handle.calc_old_state_kv(sl)
|
||||
oldtokencnt = handle.calc_old_state_tokencount(sl)
|
||||
cur_states.append({"tokens":oldtokencnt,"size":oldstate})
|
||||
@@ -4997,8 +4999,8 @@ def show_gui():
|
||||
import customtkinter as ctk
|
||||
nextstate = 0 #0=exit, 1=launch
|
||||
corrupt_scaler = get_problematic_scaler()
|
||||
original_windowwidth = int(860 if corrupt_scaler else 580)
|
||||
original_windowheight = int(740 if corrupt_scaler else 580)
|
||||
original_windowwidth = int(860 if corrupt_scaler else 584)
|
||||
original_windowheight = int(740 if corrupt_scaler else 584)
|
||||
windowwidth = original_windowwidth
|
||||
windowheight = original_windowheight
|
||||
ctk.set_appearance_mode("dark")
|
||||
@@ -5160,6 +5162,7 @@ def show_gui():
|
||||
contextshift_var = ctk.IntVar(value=1)
|
||||
fastforward_var = ctk.IntVar(value=1)
|
||||
swa_var = ctk.IntVar(value=0)
|
||||
smartcache_var = ctk.IntVar(value=0)
|
||||
remotetunnel_var = ctk.IntVar(value=0)
|
||||
smartcontext_var = ctk.IntVar()
|
||||
flashattention_var = ctk.IntVar(value=0)
|
||||
@@ -5626,6 +5629,10 @@ def show_gui():
|
||||
if swa_var.get()==1:
|
||||
contextshift_var.set(0)
|
||||
|
||||
def togglesmartcache(a,b,c):
|
||||
if smartcache_var.get()==1:
|
||||
fastforward_var.set(1)
|
||||
|
||||
def togglefastforward(a,b,c):
|
||||
if fastforward_var.get()==0:
|
||||
contextshift_var.set(0)
|
||||
@@ -5845,6 +5852,7 @@ def show_gui():
|
||||
makecheckbox(tokens_tab, "Use ContextShift", contextshift_var, 2,tooltiptxt="Uses Context Shifting to reduce reprocessing.\nRecommended. Check the wiki for more info.", command=togglectxshift)
|
||||
makecheckbox(tokens_tab, "Use FastForwarding", fastforward_var, 3,tooltiptxt="Use fast forwarding to recycle previous context (always reprocess if disabled).\nRecommended.", command=togglefastforward)
|
||||
makecheckbox(tokens_tab, "Use Sliding Window Attention (SWA)", swa_var, 4,tooltiptxt="Allows Sliding Window Attention (SWA) KV Cache, which saves memory but cannot be used with context shifting.", command=toggleswa)
|
||||
makecheckbox(tokens_tab, "Use SmartCache", smartcache_var, 5,tooltiptxt="Enables intelligent context switching by saving KV cache snapshots to RAM. Requires fast forwarding.", command=togglesmartcache)
|
||||
|
||||
# context size
|
||||
makeslider(tokens_tab, "Context Size:",contextsize_text, context_var, 0, len(contextsize_text)-1, 18, width=280, set=7,tooltip="What is the maximum context size to support. Model specific. You cannot exceed it.\nLarger contexts require more memory, and not all models support it.")
|
||||
@@ -5854,7 +5862,7 @@ def show_gui():
|
||||
|
||||
nativectx_entry, nativectx_label = makelabelentry(tokens_tab, "Override Native Context:", customrope_nativectx, row=23, padx=(246 if corrupt_scaler else 146), singleline=True, tooltip="Overrides the native trained context of the loaded model with a custom value to be used for Rope scaling.")
|
||||
customrope_scale_entry, customrope_scale_label = makelabelentry(tokens_tab, "RoPE Scale:", customrope_scale, row=23, padx=(160 if corrupt_scaler else 100), singleline=True, tooltip="For Linear RoPE scaling. RoPE frequency scale.")
|
||||
customrope_base_entry, customrope_base_label = makelabelentry(tokens_tab, "RoPE Base:", customrope_base, row=24, padx=(160 if corrupt_scaler else 100), singleline=True, tooltip="For NTK Aware Scaling. RoPE frequency base.")
|
||||
customrope_base_entry, customrope_base_label = makelabelentry(tokens_tab, "Base:", customrope_base, row=23, padx=(420 if corrupt_scaler else 220), singleline=True, tooltip="For NTK Aware Scaling. RoPE frequency base.",labelpadx=(280 if corrupt_scaler else 180))
|
||||
def togglerope(a,b,c):
|
||||
if customrope_var.get() == 1:
|
||||
manualropebox.grid()
|
||||
@@ -6143,6 +6151,7 @@ def show_gui():
|
||||
args.noshift = contextshift_var.get()==0
|
||||
args.nofastforward = fastforward_var.get()==0
|
||||
args.useswa = swa_var.get()==1
|
||||
args.smartcache = smartcache_var.get()==1
|
||||
args.remotetunnel = remotetunnel_var.get()==1
|
||||
args.foreground = keepforeground.get()==1
|
||||
args.cli = terminalonly.get()==1
|
||||
@@ -6364,6 +6373,7 @@ def show_gui():
|
||||
contextshift_var.set(0 if "noshift" in dict and dict["noshift"] else 1)
|
||||
fastforward_var.set(0 if "nofastforward" in dict and dict["nofastforward"] else 1)
|
||||
swa_var.set(1 if "useswa" in dict and dict["useswa"] else 0)
|
||||
smartcache_var.set(1 if "smartcache" in dict and dict["smartcache"] else 0)
|
||||
remotetunnel_var.set(1 if "remotetunnel" in dict and dict["remotetunnel"] else 0)
|
||||
keepforeground.set(1 if "foreground" in dict and dict["foreground"] else 0)
|
||||
terminalonly.set(1 if "cli" in dict and dict["cli"] else 0)
|
||||
@@ -8335,6 +8345,7 @@ if __name__ == '__main__':
|
||||
advparser.add_argument("--noshift","--no-context-shift", help="If set, do not attempt to Trim and Shift the GGUF context.", action='store_true')
|
||||
advparser.add_argument("--nofastforward", help="If set, do not attempt to fast forward GGUF context (always reprocess). Will also enable noshift", action='store_true')
|
||||
advparser.add_argument("--useswa", help="If set, allows Sliding Window Attention (SWA) KV Cache, which saves memory but cannot be used with context shifting.", action='store_true')
|
||||
advparser.add_argument("--smartcache", help="Enables intelligent context switching by saving KV cache snapshots to RAM. Requires fast forwarding.", action='store_true')
|
||||
advparser.add_argument("--ropeconfig", help="If set, uses customized RoPE scaling from configured frequency scale and frequency base (e.g. --ropeconfig 0.25 10000). Otherwise, uses NTK-Aware scaling set automatically based on context size. For linear rope, simply set the freq-scale and ignore the freq-base",metavar=('[rope-freq-scale]', '[rope-freq-base]'), default=[0.0, 10000.0], type=float, nargs='+')
|
||||
advparser.add_argument("--overridenativecontext", help="Overrides the native trained context of the loaded model with a custom value to be used for Rope scaling.",metavar=('[trained context]'), type=int, default=0)
|
||||
compatgroup3 = advparser.add_mutually_exclusive_group()
|
||||
|
||||
Reference in New Issue
Block a user