mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-08-25 08:14:24 +00:00
mtmd: fix silent prompt truncation on embedded NUL (#25548)
* mtmd: fix silent prompt truncation on embedded NUL mtmd_input_text carried the prompt as a bare const char* with no length, so a NUL byte in message content cut the prompt at the tokenizer boundary and dropped every later message plus the assistant marker, with no log. Add an explicit text_len and thread it through, matching llama_tokenize and the text only path. * cleanup --------- Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
This commit is contained in:
parent
0c4fa7a989
commit
4114ba18b2
4 changed files with 8 additions and 4 deletions
|
|
@ -250,7 +250,8 @@ static int eval_message(mtmd_cli_context & ctx, common_chat_msg & msg) {
|
||||||
LOG_DBG("formatted_chat.prompt: %s\n", formatted_chat.c_str());
|
LOG_DBG("formatted_chat.prompt: %s\n", formatted_chat.c_str());
|
||||||
|
|
||||||
mtmd_input_text text;
|
mtmd_input_text text;
|
||||||
text.text = formatted_chat.c_str();
|
text.text = formatted_chat.data();
|
||||||
|
text.text_len = formatted_chat.size();
|
||||||
text.add_special = add_bos;
|
text.add_special = add_bos;
|
||||||
text.parse_special = true;
|
text.parse_special = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -809,7 +809,7 @@ void mtmd_free(mtmd_context * ctx) {
|
||||||
struct mtmd_tokenizer {
|
struct mtmd_tokenizer {
|
||||||
mtmd_context * ctx;
|
mtmd_context * ctx;
|
||||||
|
|
||||||
std::string input_text;
|
std::string input_text; // note: can contain null bytes; do not use c_str()
|
||||||
bool add_special;
|
bool add_special;
|
||||||
bool parse_special;
|
bool parse_special;
|
||||||
const llama_vocab * vocab;
|
const llama_vocab * vocab;
|
||||||
|
|
@ -839,9 +839,10 @@ struct mtmd_tokenizer {
|
||||||
size_t n_bitmaps) : ctx(ctx) {
|
size_t n_bitmaps) : ctx(ctx) {
|
||||||
add_special = text->add_special;
|
add_special = text->add_special;
|
||||||
parse_special = text->parse_special;
|
parse_special = text->parse_special;
|
||||||
input_text = text->text;
|
|
||||||
vocab = ctx->vocab;
|
vocab = ctx->vocab;
|
||||||
|
|
||||||
|
input_text.assign(text->text, text->text_len);
|
||||||
|
|
||||||
std::vector<const mtmd_bitmap *> bitmaps(bmps, bmps + n_bitmaps);
|
std::vector<const mtmd_bitmap *> bitmaps(bmps, bmps + n_bitmaps);
|
||||||
auto parts_str = split_text(input_text, ctx->media_marker);
|
auto parts_str = split_text(input_text, ctx->media_marker);
|
||||||
size_t i_bm = 0;
|
size_t i_bm = 0;
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ struct mtmd_batch;
|
||||||
|
|
||||||
struct mtmd_input_text {
|
struct mtmd_input_text {
|
||||||
const char * text;
|
const char * text;
|
||||||
|
size_t text_len;
|
||||||
bool add_special;
|
bool add_special;
|
||||||
bool parse_special;
|
bool parse_special;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -705,7 +705,8 @@ server_tokens process_mtmd_prompt(mtmd_context * mctx, const std::string & promp
|
||||||
std::vector<server_tokens> inputs;
|
std::vector<server_tokens> inputs;
|
||||||
// multimodal
|
// multimodal
|
||||||
mtmd_input_text inp_txt = {
|
mtmd_input_text inp_txt = {
|
||||||
prompt.c_str(),
|
prompt.data(),
|
||||||
|
prompt.size(),
|
||||||
/* add_special */ true,
|
/* add_special */ true,
|
||||||
/* parse_special */ true,
|
/* parse_special */ true,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue