feat(sdk): add MTP speculative decoding to the llama_cpp backend#1185
feat(sdk): add MTP speculative decoding to the llama_cpp backend#1185Mengsheng Wu (mengshengwu) wants to merge 2 commits into
Conversation
Wire llama.cpp's common_speculative (draft-mtp) into the llama_cpp plugin: load an optional draft/MTP GGUF into an MTP context that shares the target KV cache (pinned to the target's device), and replace the per-token decode loop with a draft-verify loop when a draft model is configured. Draft accept counts are reported in the profile. New public config on geniex_ModelConfig (spec_draft_model, spec_n_draft) and geniex_ProfileData (draft_n_total, draft_n_accepted); mirrored across the Go, Python, and Android FFI surfaces. CLI gains --draft-model / --draft-tokens and prints the acceptance rate. Signed-off-by: Mengsheng Wu <mengshengwu@outlook.com>
Signed-off-by: Mengsheng Wu <mengshengwu@outlook.com>
3e530a8 to
155f0eb
Compare
Test resultsSummary: MTP speculative decoding runs end-to-end on X Elite GPU (Adreno/OpenCL); the draft-verify loop drafts, verifies, accepts, and reports the acceptance rate. Verified on hardware, which the Linux CI build can't exercise. Model:
Notes:
|
|
CI: all build + lint + test jobs green across linux/windows/android. The single |
|
Superseded by #1195 (generalizes to all speculative types). |
Summary
Adds Multi-Token Prediction (MTP) speculative decoding to the
llama_cppbackend, wiring llama.cpp'scommon_speculative(draft-mtp) into the plugin.ctx_type = LLAMA_CONTEXT_TYPE_MTP,ctx_other = target), pinned to the target's device.Public API (FFI change, mirrored across Go / Python / Android per CONTRIBUTING §4):
geniex_ModelConfig:spec_draft_model,spec_n_draftgeniex_ProfileData:draft_n_total,draft_n_acceptedCLI:
--draft-model/--draft-tokens; the acceptance rate is shown in the run summary. Speculative decoding is opt-in (only when a draft model is given) and llama_cpp-only (other runtimes warn and ignore it). Setup failure falls back to plain decoding.Test plan
geniex_llama_cppplugin +geniex-benchlink clean against the pinned llama.cpp submodule.mtp-drafter: draft-mtp initializes, drafts/verifies/accepts, produces coherent output, and reports the acceptance rate. Baseline (no--draft-model) and MTP paths both exercised from one binary.Note: measured acceptance on the community
gemmable-4-12bdrafter is very low (~5%), so it does not speed up on this pair — expected for a poorly-aligned drafter; the plugin faithfully reports what the drafter produces. Speedup depends on drafter quality, which is out of scope here.