Skip to content

Commit fa67698

Browse files
authored
spec: fix failed to decode mtmd chunk with DFlash (ggml-org#28587)
* speculative: fix failed to decode mtmd chunk with DFlash When using DFlash w/ vision models, the drafter memory fails to allocate new tokens because images report a fixed offset. Stop copying them to allow the drafter to continue. * address PR feedback limit M-RoPE skip to images only, allow audio to pass through. Clean up comments to align to the updated implementation
1 parent 41fc758 commit fa67698

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎common/speculative.cpp‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,7 @@ struct common_speculative_impl_draft_dflash : public common_speculative_impl {
10941094

10951095
// Target prefill may contain token IDs or multimodal embeddings. Both
10961096
// produce the target-layer features used to seed the draft KV cache, so
1097-
// skipping the embedding batches leaves a hole in the draft's cache and
1098-
// the next injection fails to initialize.
1097+
// embeddings are injected too, except the pinned ones skipped below.
10991098
// TODO: revisit after https://github.com/ggml-org/llama.cpp/pull/24669 is merged
11001099
const bool has_tokens = batch_in.token != nullptr;
11011100
const bool has_embeddings = batch_in.embd != nullptr;
@@ -1131,6 +1130,13 @@ struct common_speculative_impl_draft_dflash : public common_speculative_impl {
11311130
}
11321131
const int32_t n_rows = i_batch_end[seq_id] - i_batch_beg[seq_id] + 1;
11331132

1133+
// an M-RoPE image pins all its rows to one position, so a windowed draft
1134+
// cache cannot free cells for it - skip it, the draft can jump over the gap
1135+
const bool pos_pinned = batch_in.pos[i_batch_beg[seq_id]] == batch_in.pos[i_batch_end[seq_id]];
1136+
if (has_embeddings && n_rows > 1 && pos_pinned) {
1137+
continue;
1138+
}
1139+
11341140
for (int32_t offset = 0; offset < n_rows; offset += n_ubatch) {
11351141
const int32_t n_chunk = std::min(n_ubatch, n_rows - offset);
11361142

0 commit comments

Comments
 (0)