Skip to content

spec: properly handle mtmd input for mtp - #30257

Merged
ngxson merged 2 commits into
ggml-org:masterfrom
ngxson:xsn/llama_batch_ext_mtp_vision
Oct 10, 2026
Merged

ngxson merged 2 commits into
ggml-org:masterfrom
ngxson:xsn/llama_batch_ext_mtp_vision

Conversation

@ngxson

@ngxson ngxson commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Follow-up #29385 and #29601

MTP heads can now properly decode mtmd input, no longer filling it with zeros

Testing: Acceptance rate with image input, Qwen3.5-4B-MTP, invoice, 160 tokens per prompt

prompt before (master) after (this branch)
p1 describe invoice 104 / 163 = 64% 113 / 136 = 83%
p2 list numbers 110 / 145 = 76% 111 / 142 = 78%
p3 write email 111 / 142 = 78% 113 / 136 = 83%

Requirements

@github-actions github-actions Bot added model Model specific testing Everything test related labels Oct 9, 2026
@ngxson
ngxson marked this pull request as ready for review October 9, 2026 22:41
@ngxson
ngxson requested review from a team, CISC and ggerganov as code owners October 9, 2026 22:41

@ggerganov ggerganov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also fixes GLM-5.3-Flash to not crash on image inputs when MTP is enabled.

@ngxson
ngxson merged commit 781dbc5 into ggml-org:master Oct 10, 2026
19 of 20 checks passed
ckti pushed a commit to ckti/llama.cpp-consolidated that referenced this pull request Oct 12, 2026
* spec: properly handle mtmd input for mtp

* nits
CISC pushed a commit that referenced this pull request Oct 13, 2026
mclrcha added a commit to mclrcha/llama.cpp that referenced this pull request Oct 16, 2026
153 upstream commits (merge-base 1623d8c). Conflicts (6 files) and semantic fixes:
- gated_delta_net.cu: fork kernels (column_lanes, indexed state, RDNA4 chunked WY prefill) kept; upstream GDN MMA
  path (ggml-org#29353, HIP only on RDNA3.5) runs after ours, skipped when the state gather was deferred to the op.
- ggml-cuda.cu: n_stable reset kept, warmup reset log behind GGML_CUDA_GRAPH_DEBUG (ggml-org#30327).
- llama-batch: upstream state embeddings for MTP hooks (ggml-org#30257) next to the fork embd alias; R57 extended to them:
  the allocator points at the batch state rows and a ubatch of consecutive rows reads them in place (no copies).
- llama-context: upstream sched_new (realloc callback, ggml-org#30329) also used for the second MTP scheduler.
- llama-graph: draft LM head and logits top-k kept next to build_hadamard_input / build_logits; the draft head
  applies the Hadamard input transform too.
- llama-model: load_tensors_hadamard, then build_mtp_draft_head.
- common: R59 full-ubatch warmup also sets zero state embeddings.
despc added a commit to despc/llama.cpp that referenced this pull request Oct 18, 2026
Since upstream ggml-org#30257 the MTP driver hands vision tokens to the draft
as embeddings. Two places still assumed token ids, and any prompt with
an image aborted the server:
- the deferred catch-up stored token ids only (NULL for an image), so
  the flush failed in get_sub_batch. Batches with embeddings are no
  longer deferred.
- graph_mtp asserted token input. It now takes the embeddings when the
  ubatch has no tokens, as upstream's head does.

Two image prompts on the production launcher: sensible descriptions,
draft accepted 200/296 and 183/405. Text output unchanged.

Assisted-by: Claude Opus 5.5
gsenkowski pushed a commit to gsenkowski/strix-llama.cpp that referenced this pull request Oct 19, 2026
An image chunk of a multimodal prompt reaches the MTP draft context as an
embedding-only batch (no token ids). graph_mtp asserted ubatch.token and
aborted the server ("qwen4exp MTP needs token input").

Follow ggml-org/llama.cpp ggml-org#30257 and ggml-org#30397 (closes ggml-org#30307): accept either
tokens or embeddings, take the token embedding from ubatch.embd when there
are no token ids, and size the embd input by n_embd_inp() with the hidden
state at n_embd_out(), as the other MTP graphs do. The merge of ggml-org#30397 did
not reach this fork's own copy of graph_mtp.

Builds on the CPU backend; not run with a qwen4exp model or an image prompt.

Assisted-by: Claude
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019zrr5zPyKJ6SnVE7BjRcUe
NineBallo added a commit to NineBallo/strix-llama.cpp that referenced this pull request Oct 19, 2026
An image chunk of a multimodal prompt reaches the MTP draft context as an
embedding-only batch (no token ids). graph_mtp asserted ubatch.token and
aborted the server ("qwen4exp MTP needs token input"), so every request
containing an image crashed llama-server.

Follow upstream ggml-org#30257 and the merged fix
ggml-org#30397 (closes ggml-org#30307): accept either
tokens or embeddings, take the token embedding from ubatch.embd when there
are no token ids, and size the embd input by n_embd_inp() - the width the
mtmd embeddings arrive at - with the handed-over hidden state still at
n_embd_out(), as the other MTP graphs do.

The fork's own rewrite of qwen4exp.cpp kept the assert through the
upstream syncs, so ggml-org#30397 never reached this copy of graph_mtp.
edwardyoon added a commit to edwardyoon/focus-llama that referenced this pull request Oct 25, 2026
mellum.cpp (upstream ggml-org#30612, applied cleanly during the 399-commit
fast-forward) references three infra helpers that were dropped by the
124 conflicted commits. They are added here without cherry-picking the
full upstream commits, which would not compile locally:

- crop_before_nextn() / crop_after_nextn() on llm_graph_context  (ggml-org#30017)
- nextn_flags_t / nextn_flags() on llama_model_base              (ggml-org#30097)
- 2-arg llm_graph_input_embd_h ctor (n_embd, n_embd_state)       (ggml-org#30257)

The ctor is an overload, not a replacement: the 10 models that call the
1-arg form keep working because n_embd_state defaults to n_embd, so
set_input() byte-for-byte matches their prior behavior. set_input() now
sizes the hidden-state tensor from n_embd_state (mellum's n_embd_inp()
differs from n_embd).

Verified: cmake --build --target llama passes (error 0).
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
* spec: properly handle mtmd input for mtp

* nits
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants