Skip to content

Commit 6bcd3b9

Browse files
committed
set number of experts only
1 parent 9da56f2 commit 6bcd3b9

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

expose.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct load_model_inputs
5050
const char * vulkan_info = nullptr;
5151
const int blasbatchsize = 128;
5252
const int blasubatchsize = 128;
53+
const int experts_used = 0;
5354
const int debugmode = 0;
5455
const int forceversion = 0;
5556
const int gpulayers = 0;

gpttype_adapter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std::string executable_path = "";
5252
std::string lora_filename = "";
5353
std::string lora_base = "";
5454
std::string mmproj_filename = "";
55+
5556
bool generation_finished;
5657
float last_process_time = 0;
5758
float last_eval_time = 0;
@@ -1689,6 +1690,7 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
16891690
kcpp_data->n_ubatch = GetUBatchSize(inputs.blasubatchsize, in_file_format);
16901691
kcpp_data->flash_attn = inputs.flash_attention;
16911692
kcpp_data->model_filename = inputs.model_filename;
1693+
kcpp_data->n_experts_used = inputs.experts_used;
16921694
kcpp_data->use_smartcontext = inputs.use_smartcontext;
16931695
kcpp_data->use_contextshift = inputs.use_contextshift;
16941696
debugmode = inputs.debugmode;
@@ -1898,6 +1900,7 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
18981900
llama_model_params model_params = llama_model_default_params();
18991901
llama_context_params llama_ctx_params = llama_context_default_params();
19001902
llama_ctx_params.n_ctx = clamped_max_context_length;
1903+
19011904
if(kcpp_data->use_contextshift)
19021905
{
19031906
llama_ctx_params.n_ctx += extra_context_handle_fragmentation;
@@ -1972,6 +1975,9 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
19721975
}
19731976

19741977
llama_model * llamamodel = llama_load_model_from_file(kcpp_data->model_filename.c_str(), model_params);
1978+
1979+
llamamodel->hparams.n_expert_used = kcpp_data->n_experts_used;
1980+
19751981
if(overwriteRope)
19761982
{
19771983
llama_ctx_params.rope_freq_base = rope_freq_base;

koboldcpp.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class load_model_inputs(ctypes.Structure):
130130
("mmproj_filename", ctypes.c_char_p),
131131
("use_mmap", ctypes.c_bool),
132132
("use_mlock", ctypes.c_bool),
133+
("experts_used", ctypes.c_int),
133134
("use_smartcontext", ctypes.c_bool),
134135
("use_contextshift", ctypes.c_bool),
135136
("clblast_info", ctypes.c_int),
@@ -1119,6 +1120,7 @@ def load_model(model_filename):
11191120
inputs.blasthreads = args.blasthreads
11201121
inputs.use_mmap = (not args.nommap)
11211122
inputs.use_mlock = args.usemlock
1123+
inputs.experts_used = args.experts_used
11221124
inputs.lora_filename = "".encode("UTF-8")
11231125
inputs.lora_base = "".encode("UTF-8")
11241126
if args.lora:
@@ -2689,7 +2691,7 @@ def hide_tooltip(event):
26892691

26902692
tabs = ctk.CTkFrame(root, corner_radius = 0, width=windowwidth, height=windowheight-50)
26912693
tabs.grid(row=0, stick="nsew")
2692-
tabnames= ["Quick Launch", "Hardware", "Tokens", "GPU AutoLayers", "Model Files", "Network", "Horde Worker","Image Gen","Audio","Extra"]
2694+
tabnames= ["Quick Launch", "Hardware", "Tokens", "GPU AutoLayers", "Model Files", "Network", "Horde Worker","Image Gen","Audio","Extra", "Croco"]
26932695
navbuttons = {}
26942696
navbuttonframe = ctk.CTkFrame(tabs, width=100, height=int(tabs.cget("height")))
26952697
navbuttonframe.grid(row=0, column=0, padx=2,pady=2)
@@ -2765,6 +2767,8 @@ def hide_tooltip(event):
27652767

27662768
blasubatchsize_var = ctk.IntVar()
27672769

2770+
experts_used_var = ctk.StringVar(value="0")
2771+
27682772
version_var = ctk.StringVar(value="0")
27692773
tensor_split_str_vars = ctk.StringVar(value="")
27702774
rowsplit_var = ctk.IntVar()
@@ -3238,6 +3242,8 @@ def changerunmode(a,b,c):
32383242

32393243
tensor_split_entry,tensor_split_label = makelabelentry(gpu_al_tab, "Tensor Split:", tensor_split_str_vars, 8, 160, tooltip='When using multiple GPUs this option controls how large tensors should be split across all GPUs.\nUses a comma-separated list of non-negative values that assigns the proportion of data that each GPU should get in order.\nFor example, "3,2" will assign 60% of the data to GPU 0 and 40% to GPU 1.')
32403244

3245+
makelabelentry(gpu_al_tab, "Opt. model metadata KV override:", experts_used_var, 26, 420, tooltip="Supersede metadata of a model, like Epislon _ e.g : llama.attention.layer_norm_rms_epsilon=float:1e5, 1.25e5, 3e6, etc.")
3246+
32413247
# load model
32423248
makefileentry(gpu_al_tab, "Model:", "Select GGML Model File", model_var, 40, 576, onchoosefile=on_picked_model_file, filetypes=[("GGML bin or GGUF", ("*.bin","*.gguf"))] ,tooltiptxt="Select a GGUF or GGML model file on disk to be loaded.")
32433249

@@ -3269,6 +3275,8 @@ def togglerope(a,b,c):
32693275
noqkvlabel.configure(text_color="#ff5555")
32703276
qkvslider,qkvlabel,qkvtitle = makeslider(tokens_tab, "Quantize KV Cache:", quantkv_text, quantkv_var, 0, 22, 30, set=0,tooltip="Enable quantization of KV cache (KVQ). Mode 0 (F16) is default. Modes 1-12 requires FlashAttention and disables ContextShift.\nModes 15-20 work without FA, for incompatible models. 0,13,14 can work with or without.")
32713277

3278+
3279+
32723280
# load model
32733281
makefileentry(tokens_tab, "Model:", "Select GGML or GGML Model File", model_var, 50, 576, onchoosefile=on_picked_model_file, filetypes=[("GGML bin or GGUF", ("*.bin","*.gguf"))] ,tooltiptxt="Select a GGUF or GGML model file on disk to be loaded.")
32743282

@@ -3424,6 +3432,40 @@ def kcpp_export_template():
34243432
makelabel(extra_tab, "Export as launcher .kcppt template (Expert Only)", 4, 0,tooltiptxt="Creates a KoboldCpp launch template for others to use.\nEmbeds JSON files directly into exported file when saving.\nWhen loaded, forces the backend to be automatically determined.\nWarning! Not recommended for beginners!")
34253433
ctk.CTkButton(extra_tab , text = "Generate LaunchTemplate", command = kcpp_export_template ).grid(row=5,column=0, stick="w", padx= 8, pady=2)
34263434

3435+
# croco tab
3436+
croco_tab = tabcontent["Croco"]
3437+
3438+
# makelabelentry(croco_tab, "Context Size:" , context_var, 2, 160,tooltip="How many threads to use during BLAS processing.\nIf left blank, uses same value as regular thread count.")
3439+
3440+
makelabelentry(croco_tab, "Threads:" , threads_var, 4, 80,tooltip="How many threads to use.\nRecommended value is your CPU core count, defaults are usually OK.")
3441+
3442+
makelabelentry(croco_tab, "BLAS threads:" , blas_threads_var, 6, 80,tooltip="How many threads to use during BLAS processing.\nIf left blank, uses same value as regular thread count.")
3443+
3444+
# makelabelentry(croco_tab, "Logical Blas Batch Size:" , blas_size_var, 8, 160,tooltip="How many tokens to process at once per batch.\nLarger values use more memory unless Physical Batch supersedes it.")
3445+
3446+
# makelabelentry(croco_tab, "Physical Blas Batch Size:" , blasubatchsize_var, 10, 160,tooltip="How many tokens to process at once per batch.\nLarger values use more memory.")
3447+
3448+
makelabelentry(croco_tab, "GPU Layers:", gpulayers_var, 12, 80,tooltip="How many layers to offload onto the GPU.\nVRAM intensive, usage increases with model and context size.\nRequires some trial and error to find the best fit value.\n\nCommon values for total layers, accuracy not guaranteed.\n\nLlama/Mistral 7b/8b: 33\nSolar 10.7b/11b: 49\nLlama 13b: 41\nLlama 20b(stack): 63\nLlama/Yi 34b: 61\nMixtral 8x7b: 33\nLlama 70b: 81")
3449+
3450+
makelabelentry(croco_tab, "Positive Layer offset:", poslayeroffset_var, 14, 80, tooltip="Adds layers to the GPU layers autoloader calculation in case of under-exploitation of your GPU(s)..")
3451+
3452+
makelabelentry(croco_tab, "Negative Layer Offset:", neglayeroffset_var, 16, 80, tooltip="Removes layers to the GPU layers autoloader calculation in case of Out of Memory (OOM) error..")
3453+
3454+
makelabelentry(croco_tab, "Tensor Split:", tensor_split_str_vars, 18, 280, tooltip='When using multiple GPUs this option controls how large tensors should be split across all GPUs.\nUses a comma-separated list of non-negative values that assigns the proportion of data that each GPU should get in order.\nFor example, "3,2" will assign 60% of the data to GPU 0 and 40% to GPU 1.')
3455+
3456+
makelabelentry(croco_tab, "RoPE Scale:", customrope_scale, 20, 80, tooltip="For Linear RoPE scaling. RoPE frequency scale.")
3457+
3458+
makelabelentry(croco_tab, "RoPE Base:", customrope_base, 22, 160, tooltip="For NTK Aware Scaling. RoPE frequency base.")
3459+
3460+
makelabelentry(croco_tab, "Quantize KV Cache:", quantkv_var, 24, 80, tooltip="Enable quantization of KV cache (KVQ). Mode 0 (F16) is default. Modes 1-12 requires FlashAttention and disables ContextShift.\nModes 15-20 work without FA, for incompatible models. 0,13,14 can work with or without.")
3461+
3462+
# makelabelentry(croco_tab, "Opt. model metadata KV override:", kv_override_var, 26, 420, tooltip="Supersede metadata of a model, like Epislon _ e.g : llama.attention.layer_norm_rms_epsilon=float:1e5, 1.25e5, 3e6, etc.")
3463+
3464+
makefileentry(croco_tab, "Model:", "Select GGML or GGML Model File", model_var, 28, 576, onchoosefile=on_picked_model_file, filetypes=[("GGML bin or GGUF", ("*.bin","*.gguf"))] ,tooltiptxt="Select a GGUF or GGML model file on disk to be loaded.")
3465+
model_var.trace("w", gui_changed_modelfile)
3466+
3467+
ctk.CTkButton(croco_tab, text = "Run Benchmark", command = guibench ).grid(row=32, stick="se", padx= 0, pady=0)
3468+
34273469
# launch
34283470
def guilaunch():
34293471
if model_var.get() == "" and sd_model_var.get() == "" and whisper_model_var.get() == "" and nomodel.get()!=1:
@@ -3521,6 +3563,8 @@ def export_vars():
35213563
args.blasbatchsize = int(blasbatchsize_values[int(blas_size_var.get())])
35223564

35233565
args.blasubatchsize = int(blasubatchsize_values[int(blasubatchsize_var.get())])
3566+
3567+
args.experts_used = None if experts_used_var.get() == "" else int(experts_used_var.get())
35243568

35253569
args.forceversion = 0 if version_var.get()=="" else int(version_var.get())
35263570

@@ -3675,6 +3719,10 @@ def import_vars(dict):
36753719
blas_threads_var.set(str(dict["blasthreads"]))
36763720
else:
36773721
blas_threads_var.set("")
3722+
if "experts_used" in dict and dict["experts_used"]:
3723+
experts_used_var.set(str(dict["experts_used"]))
3724+
else:
3725+
experts_used_var.set("0")
36783726
if "contextsize" in dict and dict["contextsize"]:
36793727
context_var.set(contextsize_text.index(str(dict["contextsize"])))
36803728
if "ropeconfig" in dict and dict["ropeconfig"] and len(dict["ropeconfig"])>1:
@@ -4632,6 +4680,9 @@ def main(launch_args,start_server=True):
46324680
if not args.blasthreads or args.blasthreads <= 0:
46334681
args.blasthreads = args.threads
46344682

4683+
if not args.experts_used or args.experts_used <= 0:
4684+
args.experts_used = 0
4685+
46354686
modelname = os.path.abspath(args.model_param)
46364687
print(args)
46374688
# Flush stdout for win32 issue with regards to piping in terminals,
@@ -4995,6 +5046,9 @@ def range_checker(arg: str):
49955046
advparser.add_argument("--blasubatchsize", help="Sets the Physical batch size used in BLAS processing (default 128 for VRAM savings, optimal speed is 512, 256 is a great compromise). Setting it to 0 alignes Physical BLAS batch on logical BLAS. Same steps as for logical BBS.", type=check_range(int,0,4096), default=0)
49965047

49975048
advparser.add_argument("--blasthreads", help="Use a different number of threads during BLAS if specified. Otherwise, has the same value as --threads",metavar=('[threads]'), type=int, default=0)
5049+
5050+
advparser.add_argument("--experts_used", help="Supersede metadata of a model, like Epislon (e.g : llama.attention.layer_norm_rms_epsilon=float:1e5, 1.25e5, 3e6, etc)", metavar=('[experts_used]'), type=int, default=0)
5051+
49985052
advparser.add_argument("--lora", help="LLAMA models only, applies a lora file on top of model. Experimental.", metavar=('[lora_filename]', '[lora_base]'), nargs='+')
49995053
advparser.add_argument("--contextshift", help="If set, do attempt to Trim and Shift the GGUF context without reprocessing everything once the max context is reached. If you disable it (or need to use Quantized KV cache (KVQ) with FlashAttention, aka. modes 1 to 14, which are incompatible with Context Shift), you can eventually use --smartcontext instead.", action='store_true')
50005054
advparser.add_argument("--nommap", help="If set, do not use mmap to load newer models", action='store_true')
@@ -5014,6 +5068,7 @@ def range_checker(arg: str):
50145068
advparser.add_argument("--ssl", help="Allows all content to be served over SSL instead. A valid UNENCRYPTED SSL cert and key .pem files must be provided", metavar=('[cert_pem]', '[key_pem]'), nargs='+')
50155069
advparser.add_argument("--nocertify", help="Allows insecure SSL connections. Use this if you have cert errors and need to bypass certificate restrictions.", action='store_true')
50165070
advparser.add_argument("--mmproj", help="Select a multimodal projector file for LLaVA.", default="")
5071+
50175072
advparser.add_argument("--password", help="Enter a password required to use this instance. This key will be required for all text endpoints. Image endpoints are not secured.", default=None)
50185073
advparser.add_argument("--ignoremissing", help="Ignores all missing non-essential files, just skipping them instead.", action='store_true')
50195074
advparser.add_argument("--chatcompletionsadapter", help="Select an optional ChatCompletions Adapter JSON file to force custom instruct tags.", default="")

otherarch/otherarch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct kcpp_params {
2323
int32_t n_ubatch = 512; // physical batch size for prompt processing (must be >=32 to use BLAS)
2424
int n_threads = -1;
2525
int n_blasthreads = -1;
26+
int n_experts_used = 0;
2627

2728
// sampling parameters
2829
int32_t top_k = 40; // <= 0 to use vocab size

0 commit comments

Comments
 (0)