Skip to content

FIX: mtmd_tokenize: error - #2360

Merged
LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
askmyteapot:patch-10
Jul 24, 2026
Merged

LostRuins merged 1 commit into
LostRuins:concedo_experimentalfrom
askmyteapot:patch-10

Conversation

@askmyteapot

Copy link
Copy Markdown

DEEPSEEK4 SLOP Explanation. (Tested and is working correctly after build)

fix mtmd: missing text_len in gpttype_adapter.cpp aggregate init

Commit 4114ba1 ("mtmd: fix silent prompt truncation on embedded NUL (ggml-org#25548)") added a text_len field to mtmd_input_text, changing the struct layout from:

{ text, add_special, parse_special }

to:

{ text, text_len, add_special, parse_special }

The aggregate initialization in gpttype_adapter.cpp was never updated to account for the new field. With C++ aggregate init, the positional arguments shifted:

mtmd_input_text inp_txt = {
    mtmd_default_marker(),   // text  = "<__media__>"
    /* add_special */ false, // text_len = 0         <-- BUG
    /* parse_special */ true, // add_special = true
};
// parse_special is zero-initialized

Because text_len was 0, input_text.assign(text->text, text->text_len) in the mtmd_tokenizer constructor produced an empty string. split_text() on an empty string returned an empty vector, yielding zero media markers in the text -- but one bitmap was still provided, triggering the error:

mtmd_tokenize: error: number of media markers in text (0) does not
match number of bitmaps (1)

Fix by explicitly capturing the marker pointer and passing its length.

DEEPSEEK4 SLOP Explanation. (Tested and is working correctly after build) 

fix mtmd: missing text_len in gpttype_adapter.cpp aggregate init

Commit 4114ba1 ("mtmd: fix silent prompt truncation on embedded NUL
(ggml-org#25548)") added a `text_len` field to `mtmd_input_text`, changing the
struct layout from:

    { text, add_special, parse_special }

to:

    { text, text_len, add_special, parse_special }

The aggregate initialization in `gpttype_adapter.cpp` was never updated
to account for the new field.  With C++ aggregate init, the positional
arguments shifted:

    mtmd_input_text inp_txt = {
        mtmd_default_marker(),   // text  = "<__media__>"
        /* add_special */ false, // text_len = 0         <-- BUG
        /* parse_special */ true, // add_special = true
    };
    // parse_special is zero-initialized

Because text_len was 0, `input_text.assign(text->text, text->text_len)`
in the mtmd_tokenizer constructor produced an empty string.
`split_text()` on an empty string returned an empty vector, yielding
zero media markers in the text -- but one bitmap was still provided,
triggering the error:

    mtmd_tokenize: error: number of media markers in text (0) does not
    match number of bitmaps (1)

Fix by explicitly capturing the marker pointer and passing its length.
@LostRuins
LostRuins merged commit 917b379 into LostRuins:concedo_experimental Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants