speculative-simple : support MTP speculative decoding - #25679
Conversation
Example Run:Gemma 4 E2B: |
|
|
||
| const bool spec_mtp = std::find(params.speculative.types.begin(), | ||
| params.speculative.types.end(), | ||
| COMMON_SPECULATIVE_TYPE_DRAFT_MTP) != params.speculative.types.end(); | ||
| if (spec_mtp) { | ||
| cparams.ctx_type = LLAMA_CONTEXT_TYPE_MTP; | ||
| } | ||
| cparams.n_rs_seq = 0; | ||
| cparams.ctx_other = ctx_tgt; // ctx_tgt already loaded above (line 44) | ||
|
|
There was a problem hiding this comment.
With the recent refactor in #25056, it should be possible to simplify this logic here for loading the draft model. Want to give it a try? We can also do it in a follow-up PR.
There was a problem hiding this comment.
Thanks, I can see that logic now lives in common. I can switch this block to use the methods from that refactor. I can update this PR with those changes and run my on-device tests again.
There was a problem hiding this comment.
I have just pushed a new commit that updates the draft model loading logic to use the common helper functions.
5c28281 to
a016595
Compare
| // check if the context supports partial sequence removal | ||
| const bool use_ckpt_tgt = (common_context_can_seq_rm(ctx_tgt) == COMMON_CONTEXT_SEQ_RM_TYPE_FULL); | ||
| const bool use_ckpt_dft = (common_context_can_seq_rm(ctx_dft.get()) == COMMON_CONTEXT_SEQ_RM_TYPE_FULL); | ||
| const bool use_ckpt_dft = (common_context_can_seq_rm(ctx_dft) == COMMON_CONTEXT_SEQ_RM_TYPE_FULL); |
There was a problem hiding this comment.
Fix the vertical alignment here
| // eval the prompt | ||
| llama_decode(ctx_tgt, llama_batch_get_one(inp.data(), inp.size() - 1)); | ||
| llama_decode(ctx_dft.get(), llama_batch_get_one(inp.data(), inp.size() - 1)); | ||
| llama_decode(ctx_dft, llama_batch_get_one(inp.data(), inp.size() - 1)); |
|
|
||
| llama_memory_seq_rm(llama_get_memory(ctx_tgt), seq_id, n_past, -1); | ||
| llama_memory_seq_rm(llama_get_memory(ctx_dft.get()), seq_id, n_past, -1); | ||
| llama_memory_seq_rm(llama_get_memory(ctx_dft), seq_id, n_past, -1); |
a016595 to
2016af9
Compare
Need to take an extra look - the is_mem_shared should not be necessary
|
Superseded by #26904 |
Overview
Add Gemma4 MTP support to
llama-speculative-simple.Yes, AI was used to draft initial code changes which were later reviewed and updated by a human contributor.