feat(engine,cli,server): wire MTP self-speculative decoding into TextGenerator/CLI/server (#253) - #295
Merged
Merged
Conversation
…Generator/CLI/server (#253) TextGenerator gains a third decode-loop branch (mtpEnabled ctor param, default true) dispatching to MtpSpeculativeDecoder alongside the existing standard and two-model- speculative loops in both Generate and GenerateStreamingTokensAsync. Gated on SupportsMtp, greedy decoding, no logprobs, and no explicit draft model (mutually exclusive — an explicit draft model always wins). Reuses the existing generic SpeculativeDraftTokens/AcceptedTokens/AcceptanceRate timing fields, no new wire format. CLI (dotllm run): --no-mtp opt-out flag. MTP auto-detects from the loaded GGUF's MTP head and defaults on, matching this project's existing "safe machinery on by default" precedent (--no-prompt-cache, --no-warmup) rather than requiring an opt-in flag — justified by the demonstrated greedy-equivalence guarantee and the self-selecting population of users who deliberately loaded an MTP-branded GGUF. Server (dotllm serve): --mtp opt-in flag, default OFF (opposite default from run/chat) because enabling MTP also takes the continuous-batch scheduler offline for that model, same restriction --speculative-model already has. GET /props reports mtp_active. Real end-to-end validated against froggeric/Qwen3.6-27B-MTP-GGUF (Q4_K_M, CPU): default run shows speculative_draft_tokens=8/accepted=4 (MTP engaged); --no-mtp run shows 0/0 (standard loop). Both produce the same coherent output ("Paris." for "The capital of France is"), consistent with the modified-rejection-sampling greedy-equivalence guarantee already validated at the engine level. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Wires the already-implemented MTP self-speculative decoding path into user-facing surfaces (engine TextGenerator, CLI run/serve, and server startup + /props) so MTP-capable GGUFs can benefit outside of benchmarks/tests.
Changes:
- Add MTP dispatch path to
TextGenerator(default enabled) gated bySupportsMtp, greedy-only, no logprobs, and no explicit draft model. - Add CLI switches:
run --no-mtp(opt-out) andserve --mtp(opt-in), plus server option parsing/wiring. - Expose server runtime state via
/props(mtp_active) and document CLI/server usage indocs/SPECULATIVE.md.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/DotLLM.Server/ServerStartup.cs | Computes mtpActive, wires mtpEnabled into TextGenerator, and disables scheduler when MTP is active. |
| src/DotLLM.Server/ServerOptions.cs | Adds MtpEnabled option and --mtp parsing for serve. |
| src/DotLLM.Server/Models/PropsResponse.cs | Adds mtp_active field to /props response model. |
| src/DotLLM.Server/Endpoints/PropsEndpoint.cs | Populates mtp_active in /props. |
| src/DotLLM.Engine/TextGenerator.cs | Adds MTP-enabled ctor param and new MTP decode-loop branches for sync + streaming generation. |
| src/DotLLM.Cli/Commands/ServeCommand.cs | Adds --mtp flag (opt-in) and passes through to server options. |
| src/DotLLM.Cli/Commands/RunCommand.cs | Adds --no-mtp flag (opt-out) and wires into TextGenerator. |
| docs/SPECULATIVE.md | Documents CLI/server MTP usage and status notes. |
Suppressed comments (1)
src/DotLLM.Engine/TextGenerator.cs:978
- In the streaming MTP loop,
StopResult.StopIncludestill represents a stop condition (with the triggering token included), soFinishReasonshould beStoprather thanLength. ReturningLengthhere will misreport stop-sequence/EOS termination to streaming consumers.
var fr = stopResult == StopResult.StopInclude ? FinishReason.Length : FinishReason.Stop;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| onTokenGenerated?.Invoke(tokenId); | ||
| } | ||
|
|
||
| finishReason = stopResult == StopResult.StopInclude ? FinishReason.Length : FinishReason.Stop; |
| Threads = threading.EffectiveThreadCount, | ||
| SamplingDefaults = ToDto(state.SamplingDefaults), | ||
| DraftModelPath = string.IsNullOrEmpty(state.DraftModelPath) ? null : state.DraftModelPath, | ||
| MtpActive = state.Options.MtpEnabled && (state.Model?.SupportsMtp ?? false), |
Comment on lines
+666
to
+667
| if (!settings.Json && draftModel is null && !settings.NoMtp && model.SupportsMtp) | ||
| AnsiConsole.MarkupLine($"[dim]MTP self-speculative decoding: K={settings.SpeculativeK} (model carries an MTP head; disable with --no-mtp)[/]"); |
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires MTP self-speculative decoding (CPU+CUDA merged earlier this session, PRs #285/#286) into the actual user-facing paths — until now the only way to exercise it was a throwaway benchmark harness.
What's wired
Design decision: auto-detect (`run`/`chat`) vs. opt-in (`serve`)
`run`/`chat` auto-detect MTP from the loaded GGUF (opt-out via `--no-mtp`), mirroring this project's existing "safe machinery on by default" precedent (`--no-prompt-cache`, `--no-warmup`) — justified because the greedy-equivalence guarantee is already proven at the engine level (see #287, landing separately, which closes the one real correctness gap in that guarantee), and only users who deliberately downloaded an MTP-branded GGUF are ever affected.
`serve` is the opposite — opt-in via `--mtp`, default off — because engaging MTP silently disables the continuous-batch scheduler, which would be a real throughput regression for concurrent server traffic to trigger just from which GGUF happened to load.
Verified (independently re-run before this PR)
Build clean across `DotLLM.Engine`, `DotLLM.Cli`, `DotLLM.Server`. 30/30 MTP + TextGenerator unit tests pass.
Real end-to-end run against `froggeric/Qwen3.6-27B-MTP-GGUF` (Q4_K_M, CPU): default (auto-detect) produced `speculative_draft_tokens=8, accepted=4` (MTP engaged) with coherent output; `--no-mtp` produced `0/0` (standard loop) with the same coherent output — both correct and consistent with the target model's own greedy distribution.
Refs #253 (leaving open — see #266/#291-adjacent follow-ups noted in `docs/SPECULATIVE.md` if any remain, otherwise this plus #285/#286 substantially close the core ask).