From 2d9a90b652dd70147ec2d13e1b47a11e842d6443 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Fri, 1 Mar 2024 18:15:20 +0800 Subject: [PATCH] try to fix ci compile errors (+1 squashed commits) Squashed commits: [d0d49663] fixed log multiline (+1 squashed commits) Squashed commits: [81a8befe] try to fix linux build error (+1 squashed commits) Squashed commits: [22850dda] try to fix build (+1 squashed commits) Squashed commits: [b8294611] missing type --- gpttype_adapter.cpp | 8 ++++---- klite.embd | 6 +++--- otherarch/sdcpp/sdtype_adapter.cpp | 26 ++++++-------------------- otherarch/sdcpp/stable-diffusion.cpp | 17 ++++++++++------- otherarch/sdcpp/util.cpp | 19 +++++++++++++++++++ otherarch/sdcpp/util.h | 14 ++++++++++---- 6 files changed, 52 insertions(+), 38 deletions(-) diff --git a/gpttype_adapter.cpp b/gpttype_adapter.cpp index 263fe3af8..c675b2ef0 100644 --- a/gpttype_adapter.cpp +++ b/gpttype_adapter.cpp @@ -1437,7 +1437,7 @@ bool gpttype_generate_abort() { if(kcpp_params==nullptr) { - printf("\nWarning: KCPP not initialized!\n"); + printf("\nWarning: KCPP text generation not initialized!\n"); } stopper_unused_tokens = remaining_tokens; remaining_tokens = 0; @@ -1449,7 +1449,7 @@ std::vector gpttype_get_token_arr(const std::string & input) std::vector toks; if(kcpp_params==nullptr) { - printf("\nWarning: KCPP not initialized!\n"); + printf("\nWarning: KCPP text generation not initialized!\n"); return toks; } if(debugmode==1) @@ -1469,7 +1469,7 @@ const std::string & gpttype_get_pending_output() { if(kcpp_params==nullptr) { - printf("\nWarning: KCPP not initialized!\n"); + printf("\nWarning: KCPP text generation not initialized!\n"); return concat_output_reader_copy_poll; } concat_output_mtx.lock(); @@ -1500,7 +1500,7 @@ generation_outputs gpttype_generate(const generation_inputs inputs) if(kcpp_params==nullptr) { - printf("\nWarning: KCPP not initialized!\n"); + printf("\nWarning: KCPP text generation not initialized!\n"); output.text = nullptr; output.status = 0; generation_finished = true; diff --git a/klite.embd b/klite.embd index cc11d1fe1..ae4a1ebcb 100644 --- a/klite.embd +++ b/klite.embd @@ -3509,7 +3509,7 @@ Current version: 118 image_styles: "", image_negprompt: "", grammar:"", - tokenstreammode: (localflag?1:0), //0=off,1=pollstream,2=sse + tokenstreammode: (localflag?2:0), //0=off,1=pollstream,2=sse generate_images_mode: (localflag?0:1), //0=off, 1=horde, 2=a1111, 3=dalle generate_images_model: "stable_diffusion", //"" is disabled and "*" is all, anything else is the model name pulled from stable horde img_autogen: false, @@ -13989,10 +13989,10 @@ Current version: 118
Token Streaming ?Attempts to use token streaming if supported. Not available on Horde.
+ class="helptext">Use token streaming for partial responses. SSE is smoother but less well-supported. Poll is chunkier but more reliable. Not available on Horde.
diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index bfc4129e7..3341c53be 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -6,6 +6,9 @@ #include #include +#include +#include + #include "model_adapter.h" #include "stable-diffusion.cpp" @@ -135,24 +138,10 @@ std::string base64_encode(const unsigned char* data, unsigned int data_length) { return encoded; } -static void sd_logger_callback(enum sd_log_level_t level, const char* log, void* data) { - SDParams* params = (SDParams*)data; - if (!params->verbose && level <= SD_LOG_DEBUG) { - return; - } - if (level <= SD_LOG_INFO) { - fputs(log, stdout); - fflush(stdout); - } else { - fputs(log, stderr); - fflush(stderr); - } -} - static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv; bool sdtype_load_model(const sd_load_model_inputs inputs) { - printf("\nImage Gen - Load Safetensors Image Model: %s\n",inputs.model_filename); + printf("\nImage Generation Init - Load Safetensors Model: %s\n",inputs.model_filename); //duplicated from expose.cpp int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices @@ -189,10 +178,7 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { sddebugmode = inputs.debugmode; - if(sddebugmode==1) - { - sd_set_log_callback(sd_logger_callback, (void*)sd_params); - } + set_log_message(sddebugmode==1); bool vae_decode_only = false; bool free_param = false; @@ -245,7 +231,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) if(sd_ctx == nullptr || sd_params == nullptr) { - printf("\nError: KCPP SD is not initialized!\n"); + printf("\nWarning: KCPP image generation not initialized!\n"); output.data = ""; output.status = 0; return output; diff --git a/otherarch/sdcpp/stable-diffusion.cpp b/otherarch/sdcpp/stable-diffusion.cpp index 3c4855157..c9fb18300 100644 --- a/otherarch/sdcpp/stable-diffusion.cpp +++ b/otherarch/sdcpp/stable-diffusion.cpp @@ -15,6 +15,9 @@ #include "unet.hpp" #include "vae.hpp" +#include +#include + const char* model_version_to_str[] = { "1.x", "2.x", @@ -487,7 +490,7 @@ public: // } int64_t t1 = ggml_time_ms(); - LOG_DEBUG("computing condition graph completed, taking %" PRId64 " ms", t1 - t0); + LOG_DEBUG("computing condition graph completed, taking %d ms", (int)(t1 - t0)); ggml_tensor* result = ggml_dup_tensor(work_ctx, hidden_states); { float original_mean = ggml_tensor_mean(hidden_states); @@ -628,7 +631,7 @@ public: print_ggml_tensor(y); } int64_t t1 = ggml_time_ms(); - LOG_DEBUG("computing svd condition graph completed, taking %" PRId64 " ms", t1 - t0); + LOG_DEBUG("computing svd condition graph completed, taking %d ms",(int)(t1 - t0)); return {c_crossattn, c_concat, y}; } @@ -1392,7 +1395,7 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx, uc_vector = uncond_pair.second; // [adm_in_channels, ] } t1 = ggml_time_ms(); - LOG_INFO("get_learned_condition completed, taking %" PRId64 " ms", t1 - t0); + LOG_INFO("get_learned_condition completed, taking %d ms", (int)(t1 - t0)); if (sd_ctx->sd->free_params_immediately) { sd_ctx->sd->cond_stage_model->free_params_buffer(); @@ -1446,7 +1449,7 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx, sd_ctx->sd->diffusion_model->free_params_buffer(); } int64_t t3 = ggml_time_ms(); - LOG_INFO("generating %" PRId64 " latent images completed, taking %.2fs", final_latents.size(), (t3 - t1) * 1.0f / 1000); + LOG_INFO("generating %d latent images completed, taking %.2fs", final_latents.size(), (t3 - t1) * 1.0f / 1000); LOG_INFO("decoding %zu latents", final_latents.size()); std::vector decoded_images; // collect decoded images @@ -1458,7 +1461,7 @@ sd_image_t* txt2img(sd_ctx_t* sd_ctx, decoded_images.push_back(img); } int64_t t2 = ggml_time_ms(); - LOG_INFO("latent %" PRId64 " decoded, taking %.2fs", i + 1, (t2 - t1) * 1.0f / 1000); + LOG_INFO("latent %d decoded, taking %.2fs", i + 1, (t2 - t1) * 1.0f / 1000); } int64_t t4 = ggml_time_ms(); @@ -1577,7 +1580,7 @@ sd_image_t* img2img(sd_ctx_t* sd_ctx, uc_vector = uncond_pair.second; // [adm_in_channels, ] } int64_t t2 = ggml_time_ms(); - LOG_INFO("get_learned_condition completed, taking %" PRId64 " ms", t2 - t1); + LOG_INFO("get_learned_condition completed, taking %d ms", (int)(t2 - t1)); if (sd_ctx->sd->free_params_immediately) { sd_ctx->sd->cond_stage_model->free_params_buffer(); } @@ -1710,7 +1713,7 @@ SD_API sd_image_t* img2vid(sd_ctx_t* sd_ctx, uc_vector = ggml_dup_tensor(work_ctx, c_vector); int64_t t1 = ggml_time_ms(); - LOG_INFO("get_learned_condition completed, taking %" PRId64 " ms", t1 - t0); + LOG_INFO("get_learned_condition completed, taking %d ms", (int)(t1 - t0)); if (sd_ctx->sd->free_params_immediately) { sd_ctx->sd->clip_vision->free_params_buffer(); } diff --git a/otherarch/sdcpp/util.cpp b/otherarch/sdcpp/util.cpp index 23f9fab2f..6c5f4b52b 100644 --- a/otherarch/sdcpp/util.cpp +++ b/otherarch/sdcpp/util.cpp @@ -12,6 +12,9 @@ #include #include "preprocessing.hpp" +#include +#include + #if defined(__APPLE__) && defined(__MACH__) #include #include @@ -253,6 +256,22 @@ void* sd_log_cb_data = NULL; #define LOG_BUFFER_SIZE 1024 +static bool do_log = true; +void log_message(const char* format, ...) { + if (do_log) { + printf("\n"); + va_list args; + va_start(args, format); + vprintf(format, args); + va_end(args); + fflush(stdout); + } +} +void set_log_message(bool log) +{ + do_log = log; +} + void log_printf(sd_log_level_t level, const char* file, int line, const char* format, ...) { va_list args; va_start(args, format); diff --git a/otherarch/sdcpp/util.h b/otherarch/sdcpp/util.h index c562ba5d1..4ba74b4ba 100644 --- a/otherarch/sdcpp/util.h +++ b/otherarch/sdcpp/util.h @@ -44,8 +44,14 @@ void log_printf(sd_log_level_t level, const char* file, int line, const char* fo std::string trim(const std::string& s); -#define LOG_DEBUG(format, ...) log_printf(SD_LOG_DEBUG, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define LOG_INFO(format, ...) log_printf(SD_LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define LOG_WARN(format, ...) log_printf(SD_LOG_WARN, __FILE__, __LINE__, format, ##__VA_ARGS__) -#define LOG_ERROR(format, ...) log_printf(SD_LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__) +void log_message(const char* format, ...); +void set_log_message(bool log); +#define LOG_DEBUG(...) log_message(__VA_ARGS__) +#define LOG_INFO(...) log_message(__VA_ARGS__) +#define LOG_WARN(...) log_message(__VA_ARGS__) +#define LOG_ERROR(...) log_message(__VA_ARGS__) +// #define LOG_DEBUG(format, ...) log_printf(SD_LOG_DEBUG, __FILE__, __LINE__, format, ##__VA_ARGS__) +// #define LOG_INFO(format, ...) log_printf(SD_LOG_INFO, __FILE__, __LINE__, format, ##__VA_ARGS__) +// #define LOG_WARN(format, ...) log_printf(SD_LOG_WARN, __FILE__, __LINE__, format, ##__VA_ARGS__) +// #define LOG_ERROR(format, ...) log_printf(SD_LOG_ERROR, __FILE__, __LINE__, format, ##__VA_ARGS__) #endif // __UTIL_H__