From 4548d893ee835a8df2dc538c401d17e488097d1d Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Tue, 10 Dec 2024 23:01:28 +0800 Subject: [PATCH] better way to handle termux compatibility (+2 squashed commit) Squashed commit: [301986f11] better way to handle termux compatibility [16b03b225] updated lite --- Makefile | 28 +++++++++++++++---- ggml/src/ggml-cpu/ggml-cpu-aarch64.c | 4 +-- ggml/src/ggml-cpu/ggml-cpu-impl.h | 2 +- ggml/src/ggml-cpu/ggml-cpu-quants.c | 4 +-- ggml/src/ggml-cpu/ggml-cpu.c | 10 +++---- ggml/src/ggml-impl.h | 2 +- klite.embd | 42 +++++++++++++++++----------- 7 files changed, 58 insertions(+), 34 deletions(-) diff --git a/Makefile b/Makefile index 810ab777a..3b29929c9 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,10 @@ ifndef UNAME_M UNAME_M := $(shell uname -m) endif +ifndef UNAME_O +UNAME_O := $(shell uname -o) +endif + ifneq ($(shell grep -e "Arch Linux" -e "ID_LIKE=arch" /etc/os-release 2>/dev/null),) ARCH_ADD = -lcblas endif @@ -133,6 +137,9 @@ ifdef LLAMA_PERF CXXFLAGS += -DGGML_PERF endif +CCV := $(shell $(CC) --version | head -n 1) +CXXV := $(shell $(CXX) --version | head -n 1) + # Architecture specific # TODO: probably these flags need to be tweaked on some architectures # feel free to update the Makefile for your architecture and send a pull request or issue @@ -315,9 +322,19 @@ ifneq ($(filter aarch64%,$(UNAME_M)),) CFLAGS += CXXFLAGS += else - # sve is cooked so we are disabling it - CFLAGS += -mcpu=native -DLLAMA_NOSVE - CXXFLAGS += -mcpu=native -DLLAMA_NOSVE + # sve is cooked on termux so we are disabling it + ifeq ($(UNAME_O), Android) + ifneq ($(findstring clang, $(CCV)), ) + CFLAGS += -mcpu=native+nosve + CXXFLAGS += -mcpu=native+nosve + else + CFLAGS += -mcpu=native + CXXFLAGS += -mcpu=native + endif + else + CFLAGS += -mcpu=native + CXXFLAGS += -mcpu=native + endif endif endif @@ -406,17 +423,16 @@ else endif endif -CCV := $(shell $(CC) --version | head -n 1) -CXXV := $(shell $(CXX) --version | head -n 1) # # Print build information # -$(info I llama.cpp build info: ) +$(info I koboldcpp build info: ) $(info I UNAME_S: $(UNAME_S)) $(info I UNAME_P: $(UNAME_P)) $(info I UNAME_M: $(UNAME_M)) +$(info I UNAME_O: $(UNAME_O)) $(info I CFLAGS: $(CFLAGS)) $(info I CXXFLAGS: $(CXXFLAGS)) $(info I LDFLAGS: $(LDFLAGS)) diff --git a/ggml/src/ggml-cpu/ggml-cpu-aarch64.c b/ggml/src/ggml-cpu/ggml-cpu-aarch64.c index 76fe25d22..14a1f00eb 100644 --- a/ggml/src/ggml-cpu/ggml-cpu-aarch64.c +++ b/ggml/src/ggml-cpu/ggml-cpu-aarch64.c @@ -741,7 +741,7 @@ void ggml_gemv_q4_0_8x8_q8_0(int n, float * restrict s, size_t bs, const void * UNUSED(blocklen); #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) if (ggml_cpu_has_sve() && ggml_cpu_get_sve_cnt() == QK8_0) { const void * b_ptr = vx; const void * a_ptr = vy; @@ -2081,7 +2081,7 @@ void ggml_gemm_q4_0_8x8_q8_0(int n, float * restrict s, size_t bs, const void * UNUSED(blocklen); #if ! ((defined(_MSC_VER)) && ! defined(__clang__)) && defined(__aarch64__) -#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) && defined(__ARM_FEATURE_MATMUL_INT8) if (ggml_cpu_has_sve() && ggml_cpu_has_matmul_int8() && ggml_cpu_get_sve_cnt() == QK8_0) { const void * b_ptr = vx; const void * a_ptr = vy; diff --git a/ggml/src/ggml-cpu/ggml-cpu-impl.h b/ggml/src/ggml-cpu/ggml-cpu-impl.h index 6c8134397..d71076ad1 100644 --- a/ggml/src/ggml-cpu/ggml-cpu-impl.h +++ b/ggml/src/ggml-cpu/ggml-cpu-impl.h @@ -59,7 +59,7 @@ struct ggml_compute_params { #endif #endif -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) #include #include #endif diff --git a/ggml/src/ggml-cpu/ggml-cpu-quants.c b/ggml/src/ggml-cpu/ggml-cpu-quants.c index b0d36bc4e..33c455c73 100644 --- a/ggml/src/ggml-cpu/ggml-cpu-quants.c +++ b/ggml/src/ggml-cpu/ggml-cpu-quants.c @@ -1829,7 +1829,7 @@ void ggml_vec_dot_q4_0_q8_0(int n, float * restrict s, size_t bs, const void * r int ib = 0; float sumf = 0; -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) svfloat32_t sumv0 = svdup_n_f32(0.0f); svfloat32_t sumv1 = svdup_n_f32(0.0f); @@ -3419,7 +3419,7 @@ void ggml_vec_dot_q8_0_q8_0(int n, float * restrict s, size_t bs, const void * r int ib = 0; float sumf = 0; -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) svfloat32_t sumv0 = svdup_n_f32(0.0f); svfloat32_t sumv1 = svdup_n_f32(0.0f); diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c index a6d9b8a20..010ef2f0b 100644 --- a/ggml/src/ggml-cpu/ggml-cpu.c +++ b/ggml/src/ggml-cpu/ggml-cpu.c @@ -40,7 +40,7 @@ #include #endif -#if (defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE)) || defined(__ARM_FEATURE_MATMUL_INT8) +#if defined(__ARM_FEATURE_SVE) || defined(__ARM_FEATURE_MATMUL_INT8) #undef GGML_USE_LLAMAFILE #endif @@ -2442,7 +2442,7 @@ static void ggml_init_arm_arch_features(void) { ggml_arm_arch_features.has_i8mm = !!(hwcap2 & HWCAP2_I8MM); ggml_arm_arch_features.has_sve = !!(hwcap & HWCAP_SVE); -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) ggml_arm_arch_features.sve_cnt = PR_SVE_VL_LEN_MASK & prctl(PR_SVE_GET_VL); #endif #elif defined(__APPLE__) @@ -2479,7 +2479,7 @@ static void ggml_init_arm_arch_features(void) { ggml_arm_arch_features.has_i8mm = 0; #endif -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_FEATURE_SVE) ggml_arm_arch_features.has_sve = 1; ggml_arm_arch_features.sve_cnt = 16; #else @@ -13946,7 +13946,7 @@ int ggml_cpu_has_dotprod(void) { } int ggml_cpu_has_sve(void) { -#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) return ggml_arm_arch_features.has_sve; #else return 0; @@ -13962,7 +13962,7 @@ int ggml_cpu_has_matmul_int8(void) { } int ggml_cpu_get_sve_cnt(void) { -#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#if defined(__ARM_ARCH) && defined(__ARM_FEATURE_SVE) return ggml_arm_arch_features.sve_cnt; #else return 0; diff --git a/ggml/src/ggml-impl.h b/ggml/src/ggml-impl.h index 3e19c2cea..78e3af8f2 100644 --- a/ggml/src/ggml-impl.h +++ b/ggml/src/ggml-impl.h @@ -10,7 +10,7 @@ #include #include -#if defined(__ARM_FEATURE_SVE) && ! defined(LLAMA_NOSVE) +#ifdef __ARM_FEATURE_SVE #include #endif // __ARM_FEATURE_SVE diff --git a/klite.embd b/klite.embd index ab2cd14c4..819328b67 100644 --- a/klite.embd +++ b/klite.embd @@ -263,7 +263,7 @@ Current version indicated by LITEVER below. max-width: 100%; height: auto; } - .txtchunk, ai_context_koboldlite_internal, #gametext, .chat_received_withd_msg p,.chat_sent_msg p { + .txtchunk, #gametext, .chat_received_withd_msg p,.chat_sent_msg p { white-space: pre-wrap; } @@ -12169,7 +12169,7 @@ Current version indicated by LITEVER below. { let newgenlc = newgen.toLowerCase().trim(); if (newgenlc.startsWith("draw ") || - newgenlc.match(/\b(?:draw (?:a|an)\b)|(?:draw me (?:a|an)\b)|(?:(?:draw|show me|generate|create|make|illustrate|visualize|produce|give me)(?:\s\w+){0,3}\s(?:image|picture|drawing|photo))/)) + newgenlc.match(/\b(?:draw (?:a|an)\b)|(?:draw me (?:a|an)\b)|(?:(?:draw|show me|generate|create|make|illustrate|visualize|produce|give me)(?:\s\w+){0,4}\s(?:image|picture|drawing|photo))/)) { img_gen_trigger_prompt = newgen; doNotGenerate = true; @@ -16186,11 +16186,11 @@ Current version indicated by LITEVER below. if(localsettings.opmode==3 && localsettings.gui_type_chat==1) { - render_enhanced_chat(textToRender); + render_messenger_ui(textToRender); } else { - document.getElementById("chat_msg_body").innerHTML = render_enhanced_chat_instruct(textToRender,false); + document.getElementById("chat_msg_body").innerHTML = render_aesthetic_ui(textToRender,false); } if ((localsettings.opmode == 3 && localsettings.chatopponent != "")||localsettings.opmode == 4||localsettings.opmode==2) { document.getElementById("cht_inp_bg").classList.add("shorter"); @@ -16879,7 +16879,7 @@ Current version indicated by LITEVER below. return chatunits; } - function render_enhanced_chat(input) + function render_messenger_ui(input) { var chatbody = document.getElementById("chat_msg_body"); if(!chatbody) @@ -18066,7 +18066,7 @@ Current version indicated by LITEVER below. } } - function render_enhanced_chat_instruct(input, isPreview) //class suffix string used to prevent defined styles from leaking into global scope + function render_aesthetic_ui(input, isPreview) //class suffix string used to prevent defined styles from leaking into global scope { if(!isPreview) { @@ -18078,7 +18078,15 @@ Current version indicated by LITEVER below. document.getElementById('enhancedchatinterface_inner').style.backgroundColor = null; } } + let as = aestheticInstructUISettings; let classSuffixStr = isPreview ? "prv" : ""; + let portraitsStyling = // Also, implement portraits as css classes. Now chat entries can reuse them instead of recreating them. + ` + `; + const contextDict = { sysOpen: '', youOpen: '', AIOpen: '', closeTag: '' } let you = "$UnusedTagMatch$"; let bot = "$UnusedTagMatch$"; // Instruct tags will be used to wrap text in styled bubbles. if(localsettings.opmode==3||localsettings.opmode==4) @@ -18087,7 +18095,6 @@ Current version indicated by LITEVER below. bot = get_instruct_endtag(); } - let as = aestheticInstructUISettings; // ..and use this as shortcut to avoid typing it each time. if(localsettings.opmode==3) { if(!input.startsWith("\n")) @@ -18152,12 +18159,6 @@ Current version indicated by LITEVER below. } } - let portraitsStyling = // Also, implement portraits as css classes. Now chat entries can reuse them instead of recreating them. - ` - `; // We'll transform the input to a well-formatted HTML string that'll contain the whole visuals for the Aesthetic Instruct Mode. Effectively we're styling the input. let noSystemPrompt = input.trim().startsWith(you.trim()) || input.trim().startsWith(bot.trim()); @@ -18167,6 +18168,13 @@ Current version indicated by LITEVER below. if (synchro_pending_stream != "" && !isPreview) { newbodystr += getStreamingText(); } // Add the pending stream if it's needed. This will add any streamed text to a new bubble for the AI. + else{ + let codeblockcount = (newbodystr.match(/```/g) || []).length; + if(codeblockcount>0 && codeblockcount%2!=0 ) + { + newbodystr += "```"; //force end code block + } + } newbodystr += contextDict.closeTag + '

'; // Lastly, append the closing div so our body's raw form is completed. if (aestheticInstructUISettings.use_markdown) { @@ -18177,8 +18185,8 @@ Current version indicated by LITEVER below. let internalHTMLparts = []; // We'll cache the embedded HTML parts here to keep them intact. for (let role of aestheticTextStyleRoles) { // ..starting by the "speech" and *actions* for each role. let styleRole = aestheticInstructUISettings.use_uniform_colors ? 'uniform' : role; // Uniform role is preferred if it's active on the settings. - newbodystr = newbodystr.replace(new RegExp(`${contextDict[`${role}Open`]}([^]*?)${contextDict.closeTag}`, 'g'), (match, p) => { - let replacedText = match.replace(/<[^>]*>/g, (htmlPart) => { internalHTMLparts.push(htmlPart); return ``; }); + newbodystr = newbodystr.replace(new RegExp(`${contextDict[`${role}Open`]}([^]*?)${contextDict.closeTag}`, 'g'), (match, captured) => { + let replacedText = captured.replace(/<[^>]*>/g, (htmlPart) => { internalHTMLparts.push(htmlPart); return ``; }); replacedText = replacedText.replace(bold_regex, wrapperSpan(styleRole, 'action')); // Apply the actions style to *actions*. replacedText = replacedText.replace(italics_regex, wrapperSpan(styleRole, 'action')); // Apply the actions style to *actions*. replacedText = replacedText.replace(/“(.*?)”/g, wrapperSpan(styleRole, 'speech')); // Apply the speech style to "speech". @@ -18187,7 +18195,7 @@ Current version indicated by LITEVER below. { replacedText = simpleMarkdown(replacedText); } - return replacedText; + return `${replacedText}`; }); } newbodystr = newbodystr.replace(//gm, (match, p) => { @@ -18304,7 +18312,7 @@ Current version indicated by LITEVER below. preview = replaceAll(preview,'\n[USER_REPLY]\n', ""); preview = replaceAll(preview,'\n[AI_REPLY]\n', ""); } - document.getElementById('aesthetic_text_preview').innerHTML = render_enhanced_chat_instruct(preview,true); + document.getElementById('aesthetic_text_preview').innerHTML = render_aesthetic_ui(preview,true); }