Skip to content

feat(engine,cli,server): wire MTP self-speculative decoding into TextGenerator/CLI/server (#253) - #295

Merged
jamesburton merged 1 commit into
devfrom
issue/253-mtp-cli-wiring
Aug 8, 2026
Merged

feat(engine,cli,server): wire MTP self-speculative decoding into TextGenerator/CLI/server (#253)#295
jamesburton merged 1 commit into
devfrom
issue/253-mtp-cli-wiring

Conversation

@jamesburton

Copy link
Copy Markdown
Owner

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

  • `TextGenerator.cs` — new `mtpEnabled` ctor param (default `true`); a third decode-loop branch in both `Generate()` and `GenerateStreamingTokensAsync()` dispatches to `MtpSpeculativeDecoder`, gated by `_model.SupportsMtp`, greedy decoding, no logprobs, no explicit draft model. Reuses the existing generic speculative-metrics fields.
  • `RunCommand.cs` — `--no-mtp` opt-out flag, status line printed when MTP engages.
  • Server — checked first whether two-model speculative decoding has server wiring (it does: `ServerOptions.SpeculativeModel`, web-UI Load Model modal, `PropsEndpoint`, chat-completion stats) and mirrored that pattern rather than treating it as an unstarted gap: `ServerOptions.MtpEnabled` + `--mtp` parse, `ServeCommand.cs`, `ServerStartup.cs` wiring (disables the continuous-batch scheduler when MTP is active, same restriction `--speculative-model` already has), `GET /props` reports `mtp_active`.

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).

…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>
Copilot AI lite review requested due to automatic review settings August 8, 2026 20:05
@jamesburton
jamesburton merged commit b6f02cf into dev Aug 8, 2026
2 checks passed
@jamesburton
jamesburton deleted the issue/253-mtp-cli-wiring branch August 8, 2026 20:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 by SupportsMtp, greedy-only, no logprobs, and no explicit draft model.
  • Add CLI switches: run --no-mtp (opt-out) and serve --mtp (opt-in), plus server option parsing/wiring.
  • Expose server runtime state via /props (mtp_active) and document CLI/server usage in docs/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.StopInclude still represents a stop condition (with the triggering token included), so FinishReason should be Stop rather than Length. Returning Length here 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)[/]");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants