reloading is working correctly.

This commit is contained in:
Concedo 2025-02-06 22:24:18 +08:00
parent 080d5e6495
commit 8fef9f3fb5
3 changed files with 149 additions and 28 deletions

View file

@ -1842,28 +1842,10 @@ static float CalcGradientAIRopeFreqBase(float original_rope_base, int n_ctx_trai
float chi_ctx_value = (n_ctx_desired * ctx_multiplier) / 6.28318;
float gradient_ai_rope_freq_base_value = powf(original_rope_base, log10f(chi_ctx_value) / log10f(chi_ctx_train_value));
if(debugmode==1 && !is_quiet)
{
printf("Trained max context length (value:%.d).\n", n_ctx_train);
printf("Desired context length (value:%.d).\n", n_ctx_desired);
// printf("Solar context multiplier (value:%.3f).\n", ctx_multiplier);
// printf("Chi context train (value:%.3f).\n", chi_ctx_train_value);
// printf("Chi chosen context (value:%.3f).\n", chi_ctx_value);
// printf("Log Chi context train (value:%.3f).\n", log10f(chi_ctx_train_value));
// printf("Log Chi chosen context (value:%.3f).\n", log10f(chi_ctx_value));
printf("RoPE Frequency Base value (value:%.3f).\n", original_rope_base);
printf("RoPE base calculated via Gradient AI formula. (value:%.1f).\n", gradient_ai_rope_freq_base_value);
}
if(model_arch==GGUFArch::ARCH_SOLAR)
{
float extended_rope_positive_offset_value = 1 + ((log10f(chi_ctx_value) - log10f(chi_ctx_train_value)) / ((log10f(chi_ctx_value) * log10f(chi_ctx_train_value)) - (log10f(chi_ctx_value) + log10f(chi_ctx_train_value))));
float rope_freq_base_with_positive_offset = gradient_ai_rope_freq_base_value * extended_rope_positive_offset_value;
if(debugmode==1 && !is_quiet)
{
printf("Extended RoPE Positive Offset (multiplicator) for Solar based models. (value:%.3f).\n", extended_rope_positive_offset_value);
printf("RoPE base calculated via Gradient AI formula for Solar based models. (value:%.1f).\n", rope_freq_base_with_positive_offset);
}
return rope_freq_base_with_positive_offset;
}
else
@ -1931,7 +1913,6 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
if(file_format==FileFormat::GGUF_GENERIC)
{
printf("Using automatic RoPE scaling for GGUF. If the model has custom RoPE settings, they'll be used directly instead!\n");
printf("It means that the RoPE values written above will be replaced by the RoPE values indicated after loading.\n");
}
else
{

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
-->
<script>
const LITEVER = 210;
const LITEVER = 211;
const urlParams = new URLSearchParams(window.location.search);
var localflag = true;
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -2830,6 +2830,8 @@ Current version indicated by LITEVER below.
const koboldcpp_perf_endpoint = "/api/extra/perf";
const koboldcpp_websearch_endpoint = "/api/extra/websearch";
const koboldcpp_tts_endpoint = "/api/extra/tts";
const koboldcpp_admin_list_endpoint = "/api/admin/list_options";
const koboldcpp_admin_reload_endpoint = "/api/admin/reload_config";
const oai_models_endpoint = "/models";
const oai_submit_endpoint = "/completions";
@ -2979,6 +2981,7 @@ Current version indicated by LITEVER below.
var koboldcpp_has_vision = false;
var koboldcpp_has_multiplayer = false;
var koboldcpp_has_websearch = false;
var koboldcpp_admin_type = 0; //0 = no admin, 1=has admin, 2=protected admin
var lastSearchQuery = "";
var lastSearchResults = [];
var multiplayer_active = false;
@ -6063,6 +6066,10 @@ Current version indicated by LITEVER below.
{
return (custom_kobold_endpoint!="" && koboldcpp_version && koboldcpp_version!="" && compare_version_str(koboldcpp_version, "1.81") >= 0 && koboldcpp_has_tts);
}
function is_using_kcpp_with_admin()
{
return (custom_kobold_endpoint!="" && koboldcpp_version && koboldcpp_version!="" && compare_version_str(koboldcpp_version, "1.83") >= 0 && koboldcpp_admin_type>0);
}
function is_using_web_lite()
{
return (window.location.hostname.includes("koboldai.net") || window.location.hostname.includes("lostruins.github.io"));
@ -8411,7 +8418,8 @@ Current version indicated by LITEVER below.
document.getElementById("pasteimgcontainer").classList.contains("hidden") &&
document.getElementById("choosesharecontainer").classList.contains("hidden") &&
document.getElementById("advancedloadfile").classList.contains("hidden") &&
document.getElementById("welcomecontainer").classList.contains("hidden")
document.getElementById("welcomecontainer").classList.contains("hidden") &&
document.getElementById("admincontainer").classList.contains("hidden")
);
}
@ -8446,6 +8454,7 @@ Current version indicated by LITEVER below.
document.getElementById("choosesharecontainer").classList.add("hidden");
document.getElementById("advancedloadfile").classList.add("hidden");
document.getElementById("welcomecontainer").classList.add("hidden");
document.getElementById("admincontainer").classList.add("hidden");
mainmenu_untab(false);
}
@ -9459,6 +9468,7 @@ Current version indicated by LITEVER below.
koboldcpp_has_multiplayer = (data.multiplayer?true:false);
koboldcpp_has_websearch = (data.websearch?true:false);
koboldcpp_has_tts = (data.tts?true:false);
koboldcpp_admin_type = (data.admin?data.admin:0);
let has_password = (data.protected?true:false);
let has_txt2img = (data.txt2img?true:false);
let no_txt_model = (mdlname=="inactive");
@ -9504,7 +9514,7 @@ Current version indicated by LITEVER below.
kai_json_load(tmpstory, false);
}
}else{
if(koboldcpp_has_multiplayer)
if(koboldcpp_has_multiplayer || koboldcpp_admin_type>0)
{
//force refresh
render_gametext(false);
@ -9837,6 +9847,99 @@ Current version indicated by LITEVER below.
document.getElementById("customendpointcontainer").classList.add("hidden");
}
var last_admin_key = "";
function display_admin_container()
{
mainmenu_untab(false);
let fetch_kcpps_configs = function(adminkey)
{
let header = {'Content-Type': 'application/json'};
last_admin_key = adminkey;
if(adminkey!="")
{
header['Authorization'] = 'Bearer ' + adminkey;
}
fetch(custom_kobold_endpoint + koboldcpp_admin_list_endpoint, {
method: 'GET',
headers: header,
})
.then(x => x.json())
.then(values => {
if(values && values.length>0)
{
//on values received
var dropdown = document.getElementById("adminconfigdropdown");
for (var i = dropdown.options.length; i >= 0; i--) {
var option = dropdown.options[i];
dropdown.remove(option);
}
for(var i=0;i<values.length;++i)
{
var el = document.createElement("option");
el.textContent = values[i];
el.value = values[i];
dropdown.appendChild(el);
}
document.getElementById("admincontainer").classList.remove("hidden");
}
else
{
msgbox("Error: No configurations were returned by the server.\n\nCheck that the .kcpps directory has been set with --admindir, and ensure that your password is correct, if used.","Error");
}
}).catch((error) => {
console.log("Error: " + error);
msgbox(error,"Error");
});
};
if (koboldcpp_admin_type == 2) {
inputBox("Please input admin password:", "Admin Password Required", "", "(Input Admin Password)", () => {
let userinput = getInputBoxValue();
userinput = userinput.trim();
if (userinput != null && userinput != "") {
fetch_kcpps_configs(userinput);
}
}, false, false, true);
} else {
fetch_kcpps_configs("");
}
}
function trigger_admin_reload()
{
document.getElementById("admincontainer").classList.add("hidden");
let targetfile = document.getElementById("adminconfigdropdown").value;
if(!targetfile)
{
msgbox("No config file was selected.");
return;
}
let header = {'Content-Type': 'application/json'};
if(last_admin_key!="")
{
header['Authorization'] = 'Bearer ' + last_admin_key;
}
fetch(custom_kobold_endpoint + koboldcpp_admin_reload_endpoint, {
method: 'POST',
headers: header,
body: JSON.stringify({
"filename": targetfile
})
})
.then(x => x.json())
.then(values => {
let success = (values && values.success);
if (success) {
msgbox("KoboldCpp is now restarting!\n\nIt may take some time before the new instance is ready to use.", "KoboldCpp Reload Started");
} else {
msgbox("The request to reload KoboldCpp with a new configuration failed!\n\nPlease check if the feature is enabled, the admin directory is set, and selected config and password are correct.", "KoboldCpp Reload Failed");
}
}).catch((error) => {
console.log("Error: " + error);
msgbox(error,"Error");
});
}
function display_saveloadcontainer()
{
mainmenu_untab(true);
@ -17078,6 +17181,15 @@ Current version indicated by LITEVER below.
document.getElementById("gametext").innerHTML = fulltxt;
}
if(localflag && is_using_kcpp_with_admin())
{
document.getElementById("topbtn_admin").classList.remove("hidden");
}
else
{
document.getElementById("topbtn_admin").classList.add("hidden");
}
if (perfdata == null) {
document.getElementById("topbtn_reconnect").classList.remove("hidden");
if(localflag)
@ -19722,6 +19834,10 @@ Current version indicated by LITEVER below.
</button>
<div class="navbar-collapse collapse" id="navbarNavDropdown">
<ul class="nav navbar-nav">
<li class="nav-item hidden" id="topbtn_admin">
<a class="nav-link mainnav" href="#" onclick="closeTopNav();display_admin_container()">Admin</a>
</li>
<li class="nav-item hidden" id="topbtn_reconnect">
<a class="nav-link mainnav" href="#" onclick="closeTopNav();attempt_connect()">Reconnect</a>
</li>
@ -20306,6 +20422,28 @@ Current version indicated by LITEVER below.
</div>
</div>
<div class="popupcontainer flex hidden" id="admincontainer">
<div class="popupbg flex"></div>
<div class="nspopup flexsizevsmall">
<div class="popuptitlebar">
<div class="popuptitletext">Change Loaded KoboldCpp Config</div>
</div>
<div class="menutext">
<b></b>Warning: This will terminate the current KoboldCpp instance and relaunch it with a new config.</b><br><br>
If an invalid configuration is selected, the new server may fail to relaunch!<br><br>
<div>
<select title="Select New Config" style="padding:4px;" class="form-control" id="adminconfigdropdown">
</select>
</div>
<br>
</div>
<div class="popupfooter">
<button type="button" style="width:200px" class="btn btn-primary" onclick="trigger_admin_reload()">Reload KoboldCpp</button>
<button type="button" class="btn btn-primary" onclick="hide_popups()">Cancel</button>
</div>
</div>
</div>
<div class="popupcontainer flex hidden" id="newgamecontainer">
<div class="popupbg flex"></div>
<div class="nspopup flexsizevsmall">

View file

@ -682,7 +682,8 @@ def get_capabilities():
has_whisper = (fullwhispermodelpath!="")
has_search = True if args.websearch else False
has_tts = (ttsmodelpath!="")
return {"result":"KoboldCpp", "version":KcppVersion, "protected":has_password, "llm":has_llm, "txt2img":has_txt2img,"vision":has_vision,"transcribe":has_whisper,"multiplayer":has_multiplayer,"websearch":has_search,"tts":has_tts}
admin_type = (2 if args.admin and args.admindir and args.adminpassword else (1 if args.admin and args.admindir else 0))
return {"result":"KoboldCpp", "version":KcppVersion, "protected":has_password, "llm":has_llm, "txt2img":has_txt2img,"vision":has_vision,"transcribe":has_whisper,"multiplayer":has_multiplayer,"websearch":has_search,"tts":has_tts, "admin": admin_type}
def dump_gguf_metadata(file_path): #if you're gonna copy this into your own project at least credit concedo
chunk_size = 1024*1024*12 # read first 12mb of file
@ -5038,8 +5039,6 @@ def main(launch_args,start_server=True):
restart_target = global_memory["restart_target"]
if restart_target!="":
print(f"Reloading new config: {restart_target}")
break
if restart_target!="":
global_memory["restart_target"] = ""
time.sleep(0.5) #sleep for 0.5s then restart
if args.admin and args.admindir:
@ -5056,6 +5055,7 @@ def main(launch_args,start_server=True):
kcpp_instance.daemon = True
kcpp_instance.start()
global_memory["restart_target"] = ""
time.sleep(1)
else:
time.sleep(0.2)
except (KeyboardInterrupt,SystemExit):
@ -5510,6 +5510,7 @@ def kcpp_main_process(launch_args, start_server=True, g_memory=None):
enabledmlist.append("ApiKeyPassword") if "protected" in caps and caps["protected"] else disabledmlist.append("ApiKeyPassword")
enabledmlist.append("WebSearchProxy") if "websearch" in caps and caps["websearch"] else disabledmlist.append("WebSearchProxy")
enabledmlist.append("TextToSpeech") if "tts" in caps and caps["tts"] else disabledmlist.append("TextToSpeech")
enabledmlist.append("AdminControl") if "admin" in caps and caps["admin"]!=0 else disabledmlist.append("AdminControl")
print(f"======\nActive Modules: {' '.join(enabledmlist)}")
print(f"Inactive Modules: {' '.join(disabledmlist)}")
@ -5526,6 +5527,7 @@ def kcpp_main_process(launch_args, start_server=True, g_memory=None):
else:
print("Your SSL configuration is INVALID. SSL will not be used.")
endpoint_url = ""
remote_url = ""
httpsaffix = ("https" if sslvalid else "http")
if args.host=="":
endpoint_url = f"{httpsaffix}://localhost:{args.port}"
@ -5540,6 +5542,7 @@ def kcpp_main_process(launch_args, start_server=True, g_memory=None):
val = global_memory["tunnel_url"]
if val:
endpoint_url = val
remote_url = val
print(f"Your remote Kobold API can be found at {endpoint_url}/api")
print(f"Your remote OpenAI Compatible API can be found at {endpoint_url}/v1")
if args.sdmodel:
@ -5648,9 +5651,8 @@ def kcpp_main_process(launch_args, start_server=True, g_memory=None):
check_deprecation_warning()
if start_server:
if args.remotetunnel:
if endpoint_url:
print("======\n")
print(f"Your remote tunnel is ready, please connect to {endpoint_url}", flush=True)
if remote_url:
print(f"======\nYour remote tunnel is ready, please connect to {remote_url}", flush=True)
else:
# Flush stdout for previous win32 issue so the client can see output.
print(f"======\nPlease connect to custom endpoint at {endpoint_url}", flush=True)