Skip to content

Commit 78c84f7

Browse files
committed
Fix MTP text requests with mmproj loaded
1 parent 981f211 commit 78c84f7

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

tests/test-mtmd-plumbing.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ int main(int argc, char ** argv) {
8787
ok &= expect(server_context.find("params_base.n_batch = std::max(params_base.n_batch, mmproj_decode_req.min_decoder_batch_tokens)") != std::string::npos &&
8888
server_context.find("params_base.n_ubatch = std::max(params_base.n_ubatch, mmproj_decode_req.min_decoder_batch_tokens)") != std::string::npos,
8989
"server must raise batch and ubatch before context creation for full non-causal image chunks");
90+
ok &= expect(server_context.find("if (mctx && params_base.speculative.type() != COMMON_SPECULATIVE_TYPE_DFLASH) {\n GGML_ABORT(\"not supported by multimodal\");") == std::string::npos,
91+
"server must not abort non-DFlash speculative text requests just because mmproj is loaded");
92+
ok &= expect(server_context.find("slot.prompt.tokens.has_media()") != std::string::npos,
93+
"server must gate non-DFlash speculative multimodal fallback on actual media in the active prompt");
9094

9195
ok &= expect(mtmd_helper.find("const int32_t n_ubatch = llama_n_ubatch(lctx)") != std::string::npos,
9296
"mtmd image decode must inspect the decoder physical ubatch");

tools/server/server-common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ struct server_tokens {
203203

204204
bool empty() const { return tokens.empty(); }
205205

206+
bool has_media() const { return !map_idx_to_media.empty(); }
207+
206208
void clear() {
207209
map_idx_to_media.clear();
208210
tokens.clear();

tools/server/server-context.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4638,14 +4638,18 @@ struct server_context_impl {
46384638
const bool dflash_sampler_blocks_speculative =
46394639
params_base.speculative.type() == COMMON_SPECULATIVE_TYPE_DFLASH &&
46404640
slot.smpl && common_sampler_reasoning_is_forcing(slot.smpl.get());
4641+
const bool non_dflash_media_prompt =
4642+
mctx &&
4643+
params_base.speculative.type() != COMMON_SPECULATIVE_TYPE_DFLASH &&
4644+
slot.prompt.tokens.has_media();
4645+
if (non_dflash_media_prompt) {
4646+
SLT_DBG(slot, "%s", "non-DFlash speculative decoding does not support media inputs; using regular decode\n");
4647+
n_draft_max = 0;
4648+
}
46414649

46424650
if (n_draft_max > 0 && !dflash_sampler_blocks_speculative) {
46434651
const int64_t t_draft_slot_start = ggml_time_us();
46444652

4645-
if (mctx && params_base.speculative.type() != COMMON_SPECULATIVE_TYPE_DFLASH) {
4646-
GGML_ABORT("not supported by multimodal");
4647-
}
4648-
46494653
auto params_spec = slot.task->params.speculative;
46504654
const llama_tokens & cached_text_tokens = slot.prompt.tokens.get_text_tokens();
46514655
const int original_n_max = params_spec.n_max;

0 commit comments

Comments
 (0)