mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 11:26:34 +00:00
refactor: escape newlines in prompt logs and clarify source separators (#2106)
This commit is contained in:
1 parent
0963357214
commit
fd43b542a6
7 files changed
+27
-11
No files matched your search
@@ -139,7 +139,7 @@ void example_log_printf(sd_log_level_t level, const char* file, int line, const
|
|||||||
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
|
while (!message.empty() && (message.back() == '\n' || message.back() == '\r')) {
|
||||||
message.pop_back();
|
message.pop_back();
|
||||||
}
|
}
|
||||||
message += " - " + sd_basename(file) + ":" + std::to_string(line) + '\n';
|
message += " --- " + sd_basename(file) + ":" + std::to_string(line) + '\n';
|
||||||
|
|
||||||
log_print(level, message.c_str(), log_level, log_color);
|
log_print(level, message.c_str(), log_level, log_color);
|
||||||
}
|
}
|
||||||
@@ -399,7 +399,7 @@ struct FrozenCLIPEmbedderWithCustomWords : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
||||||
@@ -817,7 +817,7 @@ struct SD3CLIPEmbedder : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
||||||
@@ -1207,7 +1207,7 @@ struct FluxCLIPEmbedder : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
||||||
@@ -1484,7 +1484,7 @@ struct T5CLIPEmbedder : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
auto on_new_token_cb = [&](std::string& str, std::vector<int32_t>& bpe_tokens) -> bool {
|
||||||
@@ -1873,7 +1873,7 @@ struct AnimaConditioner : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> qwen_tokens;
|
std::vector<int> qwen_tokens;
|
||||||
@@ -2144,7 +2144,7 @@ struct LLMEmbedder : public Conditioner {
|
|||||||
ss << "['" << item.first << "', " << item.second << "], ";
|
ss << "['" << item.first << "', " << item.second << "], ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("parse '%s' to %s", text.c_str(), ss.str().c_str());
|
LOG_VERBOSE("parse '%s' to %s", escape_newlines(text).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> tokens;
|
std::vector<int> tokens;
|
||||||
|
|||||||
+16
-1
@@ -62,6 +62,21 @@ void replace_all_chars(std::string& str, char target, char replacement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string escape_newlines(const std::string& text) {
|
||||||
|
std::string escaped;
|
||||||
|
escaped.reserve(text.size());
|
||||||
|
for (char ch : text) {
|
||||||
|
if (ch == '\n') {
|
||||||
|
escaped += "\\n";
|
||||||
|
} else if (ch == '\r') {
|
||||||
|
escaped += "\\r";
|
||||||
|
} else {
|
||||||
|
escaped += ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return escaped;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string sd_vformat(const char* fmt, va_list ap) {
|
static std::string sd_vformat(const char* fmt, va_list ap) {
|
||||||
char small[128];
|
char small[128];
|
||||||
va_list ap2;
|
va_list ap2;
|
||||||
@@ -652,7 +667,7 @@ static void sd_log_dispatch(sd_log_level_t level, const std::string& origin, con
|
|||||||
if (origin == "ggml") {
|
if (origin == "ggml") {
|
||||||
message = origin + ": " + message + '\n';
|
message = origin + ": " + message + '\n';
|
||||||
} else {
|
} else {
|
||||||
message += " - " + origin + '\n';
|
message += " --- " + origin + '\n';
|
||||||
}
|
}
|
||||||
sd_log_cb(level, message.c_str(), sd_log_cb_data);
|
sd_log_cb(level, message.c_str(), sd_log_cb_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ bool contains(const std::string& str, const std::string& substr);
|
|||||||
std::string sd_format(const char* fmt, ...);
|
std::string sd_format(const char* fmt, ...);
|
||||||
|
|
||||||
void replace_all_chars(std::string& str, char target, char replacement);
|
void replace_all_chars(std::string& str, char target, char replacement);
|
||||||
|
std::string escape_newlines(const std::string& text);
|
||||||
|
|
||||||
int round_up_to(int value, int base);
|
int round_up_to(int value, int base);
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ bool BPETokenizer::encode(const std::string& text, std::vector<int>& result, on_
|
|||||||
ss << "\"" << token << "\", ";
|
ss << "\"" << token << "\", ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("split prompt \"%s\" to %zu tokens %s", text.c_str(), bpe_tokens.size(), ss.str().c_str());
|
LOG_VERBOSE("split prompt \"%s\" to %zu tokens %s", escape_newlines(text).c_str(), bpe_tokens.size(), escape_newlines(ss.str()).c_str());
|
||||||
result = std::move(bpe_tokens);
|
result = std::move(bpe_tokens);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -735,7 +735,7 @@ bool HFTokenizer::encode(const std::string& text, std::vector<int>& tokens, on_n
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("split prompt \"%s\" to %zu tokens %s", text.c_str(), result.size(), ss.str().c_str());
|
LOG_VERBOSE("split prompt \"%s\" to %zu tokens %s", escape_newlines(text).c_str(), result.size(), escape_newlines(ss.str()).c_str());
|
||||||
tokens = std::move(result);
|
tokens = std::move(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -343,7 +343,7 @@ bool T5UniGramTokenizer::encode(const std::string& input, std::vector<int>& resu
|
|||||||
ss << "\"" << token_str << "\", ";
|
ss << "\"" << token_str << "\", ";
|
||||||
}
|
}
|
||||||
ss << "]";
|
ss << "]";
|
||||||
LOG_VERBOSE("split prompt \"%s\" to tokens %s", input.c_str(), ss.str().c_str());
|
LOG_VERBOSE("split prompt \"%s\" to tokens %s", escape_newlines(input).c_str(), escape_newlines(ss.str()).c_str());
|
||||||
|
|
||||||
result = std::move(tokens);
|
result = std::move(tokens);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in new issue
Block a user