quiet flags now set at load time

This commit is contained in:
Concedo 2025-01-25 16:46:56 +08:00
parent bec231422a
commit 0e45d3bb7a
7 changed files with 100 additions and 94 deletions

View file

@ -54,7 +54,6 @@ struct load_model_inputs
const int cublas_info = 0;
const char * vulkan_info = nullptr;
const int blasbatchsize = 512;
const int debugmode = 0;
const int forceversion = 0;
const int gpulayers = 0;
const float rope_freq_scale = 1.0f;
@ -64,6 +63,8 @@ struct load_model_inputs
const float tensor_split[tensor_split_max] = {};
const int quant_k = 0;
const int quant_v = 0;
const bool quiet = false;
const int debugmode = 0;
};
struct generation_inputs
{
@ -97,7 +98,6 @@ struct generation_inputs
const bool stream_sse = false;
const char * grammar = nullptr;
const bool grammar_retain_state = false;
const bool quiet = false;
const float dynatemp_range = 0.0f;
const float dynatemp_exponent = 1.0f;
const float smoothing_factor = 0.0f;
@ -157,6 +157,7 @@ struct sd_load_model_inputs
const char * vae_filename = nullptr;
const char * lora_filename = nullptr;
const float lora_multiplier = 1.0f;
const bool quiet = false;
const int debugmode = 0;
};
struct sd_generation_inputs
@ -172,7 +173,6 @@ struct sd_generation_inputs
const int seed = 0;
const char * sample_method = nullptr;
const int clip_skip = -1;
const bool quiet = false;
};
struct sd_generation_outputs
{
@ -187,6 +187,7 @@ struct whisper_load_model_inputs
const int clblast_info = 0;
const int cublas_info = 0;
const char * vulkan_info = nullptr;
const bool quiet = false;
const int debugmode = 0;
};
struct whisper_generation_inputs
@ -195,7 +196,6 @@ struct whisper_generation_inputs
const char * audio_data = nullptr;
const bool suppress_non_speech = false;
const char * langcode = nullptr;
const bool quiet = false;
};
struct whisper_generation_outputs
{
@ -214,6 +214,7 @@ struct tts_load_model_inputs
const char * vulkan_info = nullptr;
const int gpulayers = 0;
const bool flash_attention = false;
const bool quiet = false;
const int debugmode = 0;
};
struct tts_generation_inputs
@ -221,7 +222,6 @@ struct tts_generation_inputs
const char * prompt = nullptr;
const int speaker_seed = 0;
const int audio_seed = 0;
const bool quiet = false;
const bool nocache = false;
};
struct tts_generation_outputs

View file

@ -106,7 +106,7 @@ static kcpp_params * kcpp_data = nullptr;
static int max_context_limit_at_load = 0;
static int n_past = 0;
static int debugmode = 0; //-1 = hide all, 0 = normal, 1 = showall
static bool quiet = false;
static bool is_quiet = false;
static std::vector<gpt_vocab::id> last_n_tokens;
static std::vector<gpt_vocab::id> current_context_tokens;
static size_t mem_per_token = 0;
@ -939,12 +939,12 @@ void sample_xtc(llama_token_data_array * candidates, float xtc_threshold, float
if(last_idx>1) //if there are 2 or more viable candidates
{
if (debugmode==1 && !quiet) {
if (debugmode==1 && !is_quiet) {
printf("XTC penalties [");
}
// then remove all other tokens above threshold EXCEPT the least likely one
for (size_t i = 0; i < last_idx - 1; ++i) {
if (debugmode==1 && !quiet)
if (debugmode==1 && !is_quiet)
{
gpt_vocab::id token = candidates->data[i].id;
std::string tokenizedstr = FileFormatTokenizeID(token, file_format);
@ -953,7 +953,7 @@ void sample_xtc(llama_token_data_array * candidates, float xtc_threshold, float
}
candidates->data[i].logit -= 999.0f; //infinity gets wonky results downstream, this hack works well enough
}
if (debugmode==1 && !quiet) {
if (debugmode==1 && !is_quiet) {
printf("]\n");
}
candidates->sorted = false;
@ -1142,7 +1142,7 @@ void sample_dry(int n_ctx, int penalty_range, float penalty_multiplier, float pe
max_exponent = FLOAT_MAX_LOG / std::log(penalty_base);
}
if (debugmode==1 && !quiet && !dry_max_token_repeat.empty()) {
if (debugmode==1 && !is_quiet && !dry_max_token_repeat.empty()) {
printf("DRY penalties [");
}
size_t count = 0;
@ -1153,7 +1153,7 @@ void sample_dry(int n_ctx, int penalty_range, float penalty_multiplier, float pe
repeat_exp = max_exponent;
}
float penalty = penalty_multiplier * pow(penalty_base, repeat_exp);
if (debugmode==1 && !quiet)
if (debugmode==1 && !is_quiet)
{
std::string tokenizedstr = FileFormatTokenizeID(token, file_format);
::utreplace(tokenizedstr, "\n", "\\n");
@ -1166,7 +1166,7 @@ void sample_dry(int n_ctx, int penalty_range, float penalty_multiplier, float pe
{
candidates->sorted = false;
}
if (debugmode==1 && !quiet && !dry_max_token_repeat.empty()) {
if (debugmode==1 && !is_quiet && !dry_max_token_repeat.empty()) {
printf("]\n");
}
}
@ -1697,7 +1697,7 @@ static void load_grammar(const std::string & gammarstr)
printf("\nIgnored invalid grammar sampler.");
return;
}
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
parsed_grammar.print(stderr);
}
@ -1840,7 +1840,7 @@ 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 && !quiet)
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);
@ -1857,7 +1857,7 @@ static float CalcGradientAIRopeFreqBase(float original_rope_base, int n_ctx_trai
{
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 && !quiet)
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);
@ -1873,6 +1873,7 @@ static float CalcGradientAIRopeFreqBase(float original_rope_base, int n_ctx_trai
ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in_file_format, FileFormatExtraMeta in_file_format_meta)
{
is_quiet = inputs.quiet;
ggml_time_init();
kcpp_data = new kcpp_params(); //allocate on heap to avoid linux segfault. yes this leaks memory.
@ -2688,13 +2689,13 @@ std::vector<int> gpttype_get_token_arr(const std::string & input, bool addbos)
printf("\nWarning: KCPP text generation not initialized!\n");
return toks;
}
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nFileFormat: %d, Tokenizing: %s",file_format ,input.c_str());
}
TokenizeString(input, toks, file_format,addbos);
int tokcount = toks.size();
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nTokens Counted: %d\n",tokcount);
}
@ -2779,7 +2780,6 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
llama_perf_context_reset(llama_ctx_v4);
}
quiet = inputs.quiet;
generation_finished = false; // Set current generation status
generated_tokens.clear(); // New Generation, new tokens
delayed_generated_tokens.clear();
@ -2858,7 +2858,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
banned_token_ids.clear();
if(banned_tokens.size()>0)
{
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nBanning %zu single character sequences...",banned_tokens.size());
}
@ -2875,13 +2875,13 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
}
}
}
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nBanned a total of %zu individual tokens.\n",banned_token_ids.size());
}
}
if(debugmode==1 && !quiet && banned_phrases.size()>0)
if(debugmode==1 && !is_quiet && banned_phrases.size()>0)
{
printf("\nBanned a total of %zu phrases, with max token count of %d.\n",banned_phrases.size(),delayed_generated_tokens_limit);
}
@ -2926,7 +2926,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
//images have changed. swap identifiers to force reprocessing
current_llava_identifier = (current_llava_identifier==LLAVA_TOKEN_IDENTIFIER_A?LLAVA_TOKEN_IDENTIFIER_B:LLAVA_TOKEN_IDENTIFIER_A);
llava_composite_image_signature = new_llava_composite;
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nLLAVA images changed, existing cache invalidated");
}
@ -2982,7 +2982,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
const int MAX_CHAR_LEN = 40;
const int MAX_SEQ_LEN = 20;
if (debugmode == 1 && !quiet)
if (debugmode == 1 && !is_quiet)
{
printf("\nProcessing %zu dry break strings...", kcpp_data->dry_sequence_breakers.size());
}
@ -2994,7 +2994,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
}
GetOverlappingTokenSequences(sequence_break, dry_sequence_breakers, MAX_SEQ_LEN);
}
if (debugmode == 1 && !quiet)
if (debugmode == 1 && !is_quiet)
{
int trivial = 0, non_trivial = 0;
for (const auto &seq : dry_sequence_breakers)
@ -3014,7 +3014,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
}
bool stream_sse = inputs.stream_sse;
bool allow_regular_prints = (!quiet && debugmode!=-1);
bool allow_regular_prints = (!is_quiet && debugmode!=-1);
std::string grammarstr = inputs.grammar;
bool grammar_retain_state = inputs.grammar_retain_state;
@ -3047,7 +3047,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
if (kcpp_data->seed <= 0 || kcpp_data->seed==0xFFFFFFFF)
{
kcpp_data->seed = (((uint32_t)time(NULL)) % 1000000u);
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nUsing Seed: %d",kcpp_data->seed);
}
@ -3079,7 +3079,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
}
else
{
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nCreating clip image embed...");
}
@ -3087,7 +3087,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
if (!llava_image_embed_make_with_clip_img(clp_ctx, kcpp_data->n_threads, clp_img_data, &llava_images[i].clp_img_embd, &llava_images[i].clp_image_tokens)) {
printf("\nError: Clip image %d failed to create embd!",i);
}
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
printf("\nLLAVA Clip Embed %i used Tokens: %d",i,llava_images[i].clp_image_tokens);
}
@ -3210,7 +3210,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
std::fill(last_n_tokens.begin(), last_n_tokens.end(), 0);
n_past = 0;
if (debugmode==1 && !quiet)
if (debugmode==1 && !is_quiet)
{
std::string outstr = "";
printf("\n\n[Debug: Dump Raw Input Tokens, format: %d]\n", file_format);
@ -3355,7 +3355,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
printf("\n");
}
if (debugmode==1 && !quiet)
if (debugmode==1 && !is_quiet)
{
std::string outstr = "";
printf("\n[Debug: Dump Forwarded Input Tokens, format: %d]\n", file_format);
@ -3404,7 +3404,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
draft_used = true;
draft_results = speculative_decoding_eval_chunk(draft_ctx, llama_ctx_v4, embd, n_vocab, n_past);
evalres = draft_results.draft_success;
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
std::string draftedtoks = get_tok_vec_str(draft_results.draftids);
printf("\nDrafted %d Tokens: [%s]\n",speculative_chunk_amt,draftedtoks.c_str());
@ -3607,7 +3607,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
if(draft_used)
{
int32_t draftedid = draft_results.draftids[logits_sampled];
if(debugmode==1 && !quiet)
if(debugmode==1 && !is_quiet)
{
std::string drafttok = FileFormatTokenizeID(draftedid, file_format, true);
std::string realtok = FileFormatTokenizeID(id, file_format, true);
@ -3660,7 +3660,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
{
printf("\rGenerating (%d / %d tokens)", (kcpp_data->n_predict - remaining_tokens), kcpp_data->n_predict);
}
if(debugmode==1 && !quiet && top_picks_history.size()>0)
if(debugmode==1 && !is_quiet && top_picks_history.size()>0)
{
printf(" [");
bool firstloop = true;
@ -3912,7 +3912,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs)
delayed_generated_tokens.pop_front();
}
if(debugmode==1 && !quiet && file_format == FileFormat::GGUF_GENERIC)
if(debugmode==1 && !is_quiet && file_format == FileFormat::GGUF_GENERIC)
{
printf("\n");
llama_perf_context_print(llama_ctx_v4);

View file

@ -12,7 +12,7 @@ Current version indicated by LITEVER below.
-->
<script>
const LITEVER = 205;
const LITEVER = 206;
const urlParams = new URLSearchParams(window.location.search);
var localflag = true;
const STORAGE_PREFIX = (localflag?"e_":"")+"kaihordewebui_";
@ -5009,8 +5009,17 @@ initializeInstructUIFunctionality();
function copyMarkdownCode(btn)
{
const codeContainer = btn.parentElement.querySelector('pre code');
//selectElementContents(codeContainer);
navigator.clipboard.writeText(codeContainer.innerText);
let innercode = codeContainer.innerText;
//remove common language descriptiors from the start
let langsmatched = ["matlab","jsonc","powershell","ps1","haskell","hs","vbnet","vb","apache","apacheconf","makefile","mk","ini","protobuf","proto","typescript","tsx","markdown","md","mkdown","mkd","python","py","javascript","js","jsx","html","xhtml","xml","css","json","typescript","ts","tsx","bash","sh","zsh","java","csharp","cs","c","h","cpp","hpp","php","sql","ruby","rb","go","golang","kotlin","kt","swift","rust","rs","r","dart","scala","dockerfile","docker","yaml","yml","ini","toml","perl","pl","shell","console","powershell","ps1","lua","typescript","ts"];
for(let i = 0; i < langsmatched.length; ++i) {
let matcher = langsmatched[i]+"\n";
if (innercode.startsWith(matcher)) {
innercode = innercode.substring(matcher.length);
break;
}
}
navigator.clipboard.writeText(innercode);
}
function simpleMarkdown(text) {
@ -13469,7 +13478,12 @@ initializeInstructUIFunctionality();
if (document.getElementById("jailbreakprompt2") && document.getElementById("jailbreakprompt2").checked && document.getElementById("jailbreakprompttext2").value!="") {
let addrole = document.getElementById("jailbreakprompttext2role").value;
addrole = ((addrole==2)?"system":(addrole==1?"assistant":"user"));
oai_payload.messages.push({ "role": addrole, "content": document.getElementById("jailbreakprompttext2").value });
let postmsg = { "role": addrole, "content": document.getElementById("jailbreakprompttext2").value };
if(addrole=="assistant" && targetep.toLowerCase().includes("api.deepseek.com"))
{
postmsg["prefix"] = true;
}
oai_payload.messages.push(postmsg);
}
oaiemulatecompletionscontent = "";

View file

@ -160,7 +160,6 @@ class load_model_inputs(ctypes.Structure):
("cublas_info", ctypes.c_int),
("vulkan_info", ctypes.c_char_p),
("blasbatchsize", ctypes.c_int),
("debugmode", ctypes.c_int),
("forceversion", ctypes.c_int),
("gpulayers", ctypes.c_int),
("rope_freq_scale", ctypes.c_float),
@ -169,7 +168,9 @@ class load_model_inputs(ctypes.Structure):
("flash_attention", ctypes.c_bool),
("tensor_split", ctypes.c_float * tensor_split_max),
("quant_k", ctypes.c_int),
("quant_v", ctypes.c_int)]
("quant_v", ctypes.c_int),
("quiet", ctypes.c_bool),
("debugmode", ctypes.c_int)]
class generation_inputs(ctypes.Structure):
_fields_ = [("seed", ctypes.c_int),
@ -202,7 +203,6 @@ class generation_inputs(ctypes.Structure):
("stream_sse", ctypes.c_bool),
("grammar", ctypes.c_char_p),
("grammar_retain_state", ctypes.c_bool),
("quiet", ctypes.c_bool),
("dynatemp_range", ctypes.c_float),
("dynatemp_exponent", ctypes.c_float),
("smoothing_factor", ctypes.c_float),
@ -242,6 +242,7 @@ class sd_load_model_inputs(ctypes.Structure):
("vae_filename", ctypes.c_char_p),
("lora_filename", ctypes.c_char_p),
("lora_multiplier", ctypes.c_float),
("quiet", ctypes.c_bool),
("debugmode", ctypes.c_int)]
class sd_generation_inputs(ctypes.Structure):
@ -255,8 +256,7 @@ class sd_generation_inputs(ctypes.Structure):
("height", ctypes.c_int),
("seed", ctypes.c_int),
("sample_method", ctypes.c_char_p),
("clip_skip", ctypes.c_int),
("quiet", ctypes.c_bool)]
("clip_skip", ctypes.c_int)]
class sd_generation_outputs(ctypes.Structure):
_fields_ = [("status", ctypes.c_int),
@ -268,14 +268,14 @@ class whisper_load_model_inputs(ctypes.Structure):
("clblast_info", ctypes.c_int),
("cublas_info", ctypes.c_int),
("vulkan_info", ctypes.c_char_p),
("quiet", ctypes.c_bool),
("debugmode", ctypes.c_int)]
class whisper_generation_inputs(ctypes.Structure):
_fields_ = [("prompt", ctypes.c_char_p),
("audio_data", ctypes.c_char_p),
("suppress_non_speech", ctypes.c_bool),
("langcode", ctypes.c_char_p),
("quiet", ctypes.c_bool)]
("langcode", ctypes.c_char_p)]
class whisper_generation_outputs(ctypes.Structure):
_fields_ = [("status", ctypes.c_int),
@ -291,13 +291,13 @@ class tts_load_model_inputs(ctypes.Structure):
("vulkan_info", ctypes.c_char_p),
("gpulayers", ctypes.c_int),
("flash_attention", ctypes.c_bool),
("quiet", ctypes.c_bool),
("debugmode", ctypes.c_int)]
class tts_generation_inputs(ctypes.Structure):
_fields_ = [("prompt", ctypes.c_char_p),
("speaker_seed", ctypes.c_int),
("audio_seed", ctypes.c_int),
("quiet", ctypes.c_bool),
("nocache", ctypes.c_bool)]
class tts_generation_outputs(ctypes.Structure):
@ -513,6 +513,12 @@ def set_backend_props(inputs):
inputs.vulkan_info = s.encode("UTF-8")
else:
inputs.vulkan_info = "".encode("UTF-8")
# set universal flags
inputs.quiet = args.quiet
inputs.debugmode = args.debugmode
inputs.executable_path = (getdirpath()+"/").encode("UTF-8")
return inputs
def end_trim_to_sentence(input_text):
@ -1077,13 +1083,10 @@ def load_model(model_filename):
inputs.moe_experts = args.moeexperts
inputs = set_backend_props(inputs)
inputs.executable_path = (getdirpath()+"/").encode("UTF-8")
inputs.debugmode = args.debugmode
ret = handle.load_model(inputs)
return ret
def generate(genparams, is_quiet=False, stream_flag=False):
def generate(genparams, stream_flag=False):
global maxctx, args, currentusergenkey, totalgens, pendingabortkey
prompt = genparams.get('prompt', "")
@ -1121,7 +1124,6 @@ def generate(genparams, is_quiet=False, stream_flag=False):
grammar_retain_state = genparams.get('grammar_retain_state', False)
genkey = genparams.get('genkey', '')
trimstop = genparams.get('trim_stop', True)
quiet = is_quiet
dynatemp_range = genparams.get('dynatemp_range', 0.0)
dynatemp_exponent = genparams.get('dynatemp_exponent', 1.0)
smoothing_factor = genparams.get('smoothing_factor', 0.0)
@ -1170,7 +1172,6 @@ def generate(genparams, is_quiet=False, stream_flag=False):
inputs.rep_pen_slope = rep_pen_slope
inputs.presence_penalty = presence_penalty
inputs.stream_sse = stream_sse
inputs.quiet = quiet
inputs.dynatemp_range = dynatemp_range
inputs.dynatemp_exponent = dynatemp_exponent
inputs.smoothing_factor = smoothing_factor
@ -1289,8 +1290,6 @@ def generate(genparams, is_quiet=False, stream_flag=False):
def sd_load_model(model_filename,vae_filename,lora_filename,t5xxl_filename,clipl_filename,clipg_filename):
global args
inputs = sd_load_model_inputs()
inputs.debugmode = args.debugmode
inputs.executable_path = (getdirpath()+"/").encode("UTF-8")
inputs.model_filename = model_filename.encode("UTF-8")
thds = args.threads
quant = 0
@ -1368,7 +1367,6 @@ def sd_generate(genparams):
height = tryparseint(genparams.get("height", 512))
seed = tryparseint(genparams.get("seed", -1))
sample_method = genparams.get("sampler_name", "k_euler_a")
is_quiet = True if (args.quiet or args.debugmode == -1) else False
clip_skip = tryparseint(genparams.get("clip_skip", -1))
#clean vars
@ -1405,7 +1403,6 @@ def sd_generate(genparams):
inputs.height = height
inputs.seed = seed
inputs.sample_method = sample_method.lower().encode("UTF-8")
inputs.quiet = is_quiet
inputs.clip_skip = clip_skip
ret = handle.sd_generate(inputs)
outstr = ""
@ -1417,8 +1414,6 @@ def sd_generate(genparams):
def whisper_load_model(model_filename):
global args
inputs = whisper_load_model_inputs()
inputs.debugmode = args.debugmode
inputs.executable_path = (getdirpath()+"/").encode("UTF-8")
inputs.model_filename = model_filename.encode("UTF-8")
inputs = set_backend_props(inputs)
ret = handle.whisper_load_model(inputs)
@ -1426,7 +1421,6 @@ def whisper_load_model(model_filename):
def whisper_generate(genparams):
global args
is_quiet = True if (args.quiet or args.debugmode == -1) else False
prompt = genparams.get("prompt", "")
audio_data = genparams.get("audio_data", "")
if audio_data.startswith("data:audio"):
@ -1434,7 +1428,6 @@ def whisper_generate(genparams):
inputs = whisper_generation_inputs()
inputs.prompt = prompt.encode("UTF-8")
inputs.audio_data = audio_data.encode("UTF-8")
inputs.quiet = is_quiet
lc = genparams.get("langcode", genparams.get("language", "auto"))
lc = lc.strip().lower() if (lc and lc.strip().lower()!="") else "auto"
inputs.langcode = lc.encode("UTF-8")
@ -1448,8 +1441,6 @@ def whisper_generate(genparams):
def tts_load_model(ttc_model_filename,cts_model_filename):
global args
inputs = tts_load_model_inputs()
inputs.debugmode = args.debugmode
inputs.executable_path = (getdirpath()+"/").encode("UTF-8")
inputs.ttc_model_filename = ttc_model_filename.encode("UTF-8")
inputs.cts_model_filename = cts_model_filename.encode("UTF-8")
inputs.gpulayers = (999 if args.ttsgpu else 0)
@ -1466,7 +1457,6 @@ def tts_load_model(ttc_model_filename,cts_model_filename):
def tts_generate(genparams):
global args
is_quiet = True if (args.quiet or args.debugmode == -1) else False
prompt = genparams.get("input", genparams.get("text", ""))
prompt = prompt.strip()
voice = 1
@ -1486,7 +1476,6 @@ def tts_generate(genparams):
except Exception:
aseed = -1
inputs.audio_seed = aseed
inputs.quiet = is_quiet
inputs.nocache = genparams.get("nocache", False)
ret = handle.tts_generate(inputs)
outstr = ""
@ -2044,7 +2033,6 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
async def generate_text(self, genparams, api_format, stream_flag):
global friendlymodelname, chatcompl_adapter, currfinishreason
is_quiet = args.quiet
currfinishreason = "null"
def run_blocking(): # api format 1=basic,2=kai,3=oai,4=oai-chat
@ -2054,7 +2042,7 @@ class ServerRequestHandler(http.server.SimpleHTTPRequestHandler):
global last_non_horde_req_time
last_non_horde_req_time = time.time()
return generate(genparams=genparams,is_quiet=is_quiet,stream_flag=stream_flag)
return generate(genparams=genparams,stream_flag=stream_flag)
genout = {"text": "", "status": -1, "stopreason": -1, "prompt_tokens":0, "completion_tokens": 0, "total_tokens": 0}
if stream_flag:

View file

@ -114,8 +114,11 @@ static std::string recent_data = "";
static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv;
static bool notiling = false;
bool sdtype_load_model(const sd_load_model_inputs inputs) {
static bool sd_is_quiet = false;
bool sdtype_load_model(const sd_load_model_inputs inputs) {
sd_is_quiet = inputs.quiet;
set_sd_quiet(sd_is_quiet);
executable_path = inputs.executable_path;
std::string taesdpath = "";
std::string lorafilename = inputs.lora_filename;
@ -290,9 +293,6 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
sd_image_t * results;
sd_image_t* control_image = NULL;
bool is_quiet = inputs.quiet;
set_sd_quiet(is_quiet);
//sanitize prompts, remove quotes and limit lengths
std::string cleanprompt = clean_input_prompt(inputs.prompt);
std::string cleannegprompt = clean_input_prompt(inputs.negative_prompt);
@ -345,7 +345,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
std::vector<uint8_t> resized_image_buf(img2imgW * img2imgH * img2imgC);
std::string ts = get_timestamp_str();
if(!is_quiet)
if(!sd_is_quiet)
{
printf("\n[%s] Generating Image (%d steps)\n",ts.c_str(),inputs.sample_steps);
}else{
@ -385,7 +385,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
if (sd_params->mode == TXT2IMG) {
if(!is_quiet && sddebugmode==1)
if(!sd_is_quiet && sddebugmode==1)
{
printf("\nTXT2IMG PROMPT:%s\nNPROMPT:%s\nCLPSKP:%d\nCFGSCLE:%f\nW:%d\nH:%d\nSM:%d\nSTEP:%d\nSEED:%d\nBATCH:%d\nCIMG:%p\nCSTR:%f\n\n",
sd_params->prompt.c_str(),
@ -471,7 +471,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
input_image.channel = img2imgC;
input_image.data = resized_image_buf.data();
if(!is_quiet && sddebugmode==1)
if(!sd_is_quiet && sddebugmode==1)
{
printf("\nIMG2IMG PROMPT:%s\nNPROMPT:%s\nCLPSKP:%d\nCFGSCLE:%f\nW:%d\nH:%d\nSM:%d\nSTEP:%d\nSEED:%d\nBATCH:%d\nCIMG:%p\nSTR:%f\n\n",
sd_params->prompt.c_str(),

View file

@ -466,6 +466,7 @@ static llama_context * cts_ctx = nullptr; //codes to speech
static TTS_VER ttsver = TTS_VER_2;
static int ttsdebugmode = 0;
static bool tts_is_quiet = false;
static std::string ttsplatformenv, ttsdeviceenv, ttsvulkandeviceenv;
static std::string last_generated_audio = "";
static std::string last_generation_settings_prompt = ""; //for caching purposes to fix ST bug
@ -480,6 +481,8 @@ static int nthreads = 4;
bool ttstype_load_model(const tts_load_model_inputs inputs)
{
tts_is_quiet = inputs.quiet;
//duplicated from expose.cpp
int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices
std::string usingclblast = "GGML_OPENCL_CONFIGURED="+std::to_string(cl_parseinfo>0?1:0);
@ -623,7 +626,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
{
audio_seed = (((uint32_t)time(NULL)) % 1000000u);
}
if(ttsdebugmode==1 && !inputs.quiet)
if(ttsdebugmode==1 && !tts_is_quiet)
{
printf("\nUsing Speaker Seed: %d", speaker_seed);
printf("\nUsing Audio Seed: %d", audio_seed);
@ -639,7 +642,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
&& last_generated_audio!=""
&& last_generation_settings_prompt == std::string(inputs.prompt))
{
if (ttsdebugmode == 1 && !inputs.quiet) {
if (ttsdebugmode == 1 && !tts_is_quiet) {
printf("\nReusing Cached Audio.\n");
}
output.data = last_generated_audio.c_str();
@ -662,7 +665,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
if(empty_check)
{
//no input
if(!inputs.quiet)
if(!tts_is_quiet)
{
printf("\nTTS sent empty input.\n");
last_generated_audio = "";
@ -676,7 +679,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
timer_start();
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nInput: %s\n", prompt_clean.c_str());
}
@ -691,7 +694,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
if(last_speaker_seed==speaker_seed && !last_speaker_codes.empty())
{
//able to proceed, do nothing
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nReuse speaker ID=%d (%d tokens)...", last_speaker_seed, last_speaker_codes.size());
}
@ -717,7 +720,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
}
last_speaker_codes = common_tokenize(ttcvocab, speaker, false, true);
last_speaker_seed = speaker_seed;
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nSpecial ID=%d (%d tokens)...", last_speaker_seed, last_speaker_codes.size());
}
@ -725,7 +728,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
//generate the voice texture of our new speaker
last_speaker_codes.clear();
guide_tokens = prepare_guide_tokens(ttcvocab,sampletext,ttsver);
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nGuide Tokens (%d tokens):\n", guide_tokens.size());
const std::string inp_txt = common_detokenize(ttc_ctx, guide_tokens, true);
@ -734,7 +737,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
}
prompt_add(prompt_inp, ttcvocab, sampletext, false, true);
prompt_add(prompt_inp, ttcvocab, "<|text_end|>\n<|audio_start|>\n", false, true);
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nPrepare new speaker (%d input tokens)...\n", prompt_inp.size());
print_tok_vec(prompt_inp);
@ -806,7 +809,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
}
}
last_speaker_seed = speaker_seed;
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nNew speaker ID=%d created (%d tokens)...", last_speaker_seed, last_speaker_codes.size());
const std::string inp_txt = common_detokenize(ttc_ctx, last_speaker_codes, true);
@ -821,7 +824,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
//second pass: add the speaker before the actual prompt
guide_tokens = prepare_guide_tokens(ttcvocab,prompt_clean,ttsver);
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nGuide Tokens (%d tokens):\n", guide_tokens.size());
const std::string inp_txt = common_detokenize(ttc_ctx, guide_tokens, true);
@ -834,7 +837,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
}
prompt_add(prompt_inp, ttcvocab, prompt_clean, false, true);
if(!inputs.quiet)
if(!tts_is_quiet)
{
printf("\nTTS Processing (%d input tokens)...\n", prompt_inp.size());
}
@ -847,7 +850,7 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
prompt_add(prompt_inp, ttcvocab, "\n", false, true);
}
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
printf("\nDUMP TTS PROMPT (%d tokens):\n", prompt_inp.size());
print_tok_vec(prompt_inp);
@ -913,13 +916,13 @@ tts_generation_outputs ttstype_generate(const tts_generation_inputs inputs)
output.status = 0;
return output;
}
if(!inputs.quiet)
if(!tts_is_quiet)
{
printf("\rTTS Generating (%d outputs)", n_decode);
}
}
if(!inputs.quiet && ttsdebugmode==1)
if(!tts_is_quiet && ttsdebugmode==1)
{
const std::string inp_txt = common_detokenize(ttc_ctx, codes, true);
printf("\nGenerated %d Codes: '%s'\n",codes.size(), inp_txt.c_str());

View file

@ -24,7 +24,7 @@
#endif
static int whisperdebugmode = 0;
static bool whisperquiet = false;
static bool whisper_is_quiet = false;
static whisper_context * whisper_ctx = nullptr;
static std::string whisper_output_text = "";
@ -90,7 +90,7 @@ static bool read_wav(const std::string & b64data, std::vector<float>& pcmf32, st
std::vector<float> raw_pcm;
raw_pcm.resize(n);
if(whisperdebugmode==1 && !whisperquiet)
if(whisperdebugmode==1 && !whisper_is_quiet)
{
printf("\nwav_data_size: %d, n:%d",wav_data.size(),n);
}
@ -107,7 +107,7 @@ static bool read_wav(const std::string & b64data, std::vector<float>& pcmf32, st
}
if (wav.sampleRate != COMMON_SAMPLE_RATE) {
if(whisperdebugmode==1 && !whisperquiet)
if(whisperdebugmode==1 && !whisper_is_quiet)
{
printf("\nResample wav from %" PRIu32 " to %" PRIu32 " (in size: %zu)",
wav.sampleRate, COMMON_SAMPLE_RATE, raw_pcm.size());
@ -140,6 +140,8 @@ void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
static std::string whisperplatformenv, whisperdeviceenv, whispervulkandeviceenv;
bool whispertype_load_model(const whisper_load_model_inputs inputs)
{
whisper_is_quiet = inputs.quiet;
//duplicated from expose.cpp
int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices
std::string usingclblast = "GGML_OPENCL_CONFIGURED="+std::to_string(cl_parseinfo>0?1:0);
@ -203,8 +205,7 @@ whisper_generation_outputs whispertype_generate(const whisper_generation_inputs
return output;
}
whisperquiet = inputs.quiet;
if(!whisperquiet)
if(!whisper_is_quiet)
{
printf("\nWhisper Transcribe Generating...");
}
@ -263,14 +264,14 @@ whisper_generation_outputs whispertype_generate(const whisper_generation_inputs
return output;
}
if (!whisperquiet && whisperdebugmode==1) {
if (!whisper_is_quiet && whisperdebugmode==1) {
whisper_print_timings(whisper_ctx);
}
// output text transcription
whisper_output_text = output_txt(whisper_ctx, pcmf32s);
std::string ts = get_timestamp_str();
if(!whisperquiet)
if(!whisper_is_quiet)
{
printf("\n[%s] Whisper Transcribe Output: %s",ts.c_str(),whisper_output_text.c_str());
} else {