Skip to content

Commit 67f80a1

Browse files
localai-botmudler
andauthored
fix(mtp): don't auto-enable self-spec MTP for draft-only assistant GGUFs (#10208)
Gemma4 MTP (ggml-org/llama.cpp#23398) registers the prediction head as a separate `gemma4-assistant` architecture. That assistant GGUF still carries `<arch>.nextn_predict_layers`, so the architecture-agnostic detection in HasEmbeddedMTPHead matched it and appended the `spec_type:draft-mtp` defaults. Unlike the DeepSeek/Qwen embedded-head models, an assistant checkpoint cannot self-speculate: it is a draft model that requires a paired target context (`ctx_other`) and throws if loaded alone. Auto-applying the self-spec defaults to a standalone assistant import therefore produces a broken config. Guard the detection against draft-only assistant architectures (the `-assistant` suffix is upstream's naming convention) so importing one no longer yields a self-speculation config. Two-model target+draft pairing remains expressible manually via `draft_model:` and is left to a follow-up. Assisted-by: Claude:claude-opus-4-8 [Claude Code] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>
1 parent a7cb587 commit 67f80a1

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

core/config/mtp.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,26 @@ func MTPSpecOptions() []string {
3030
return out
3131
}
3232

33-
// HasEmbeddedMTPHead reports whether the parsed GGUF declares a Multi-Token
34-
// Prediction head. Detection reads `<arch>.nextn_predict_layers`, which is
35-
// what `gguf_writer.add_nextn_predict_layers(n)` emits in upstream's
33+
// isDraftOnlyAssistantArch reports whether an architecture names a standalone
34+
// MTP *draft* model rather than a self-speculating trunk. Upstream's Gemma4 MTP
35+
// (ggml-org/llama.cpp#23398) registers the head as a separate `gemma4-assistant`
36+
// architecture whose GGUF still carries `nextn_predict_layers`, but which cannot
37+
// run alone: it requires a paired target context (`ctx_other`). Such archs must
38+
// not trigger the embedded-head self-speculation defaults. The `-assistant`
39+
// suffix is upstream's naming convention for these draft-only checkpoints.
40+
func isDraftOnlyAssistantArch(arch string) bool {
41+
return strings.HasSuffix(arch, "-assistant")
42+
}
43+
44+
// HasEmbeddedMTPHead reports whether the parsed GGUF declares a self-speculating
45+
// Multi-Token Prediction head. Detection reads `<arch>.nextn_predict_layers`,
46+
// which is what `gguf_writer.add_nextn_predict_layers(n)` emits in upstream's
3647
// `conversion/qwen.py` MTP mixin. A positive layer count means the head is
3748
// present in the same GGUF as the trunk.
49+
//
50+
// Draft-only assistant architectures (e.g. Gemma4's `gemma4-assistant`) carry
51+
// the same key but are separate draft checkpoints meant to be paired with a
52+
// target model, so they are deliberately excluded here.
3853
func HasEmbeddedMTPHead(f *gguf.GGUFFile) (uint32, bool) {
3954
if f == nil {
4055
return 0, false
@@ -43,6 +58,9 @@ func HasEmbeddedMTPHead(f *gguf.GGUFFile) (uint32, bool) {
4358
if arch == "" {
4459
return 0, false
4560
}
61+
if isDraftOnlyAssistantArch(arch) {
62+
return 0, false
63+
}
4664
v, ok := f.Header.MetadataKV.Get(arch + ".nextn_predict_layers")
4765
if !ok {
4866
return 0, false

core/config/mtp_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,33 @@ package config_test
33
import (
44
. "github.com/mudler/LocalAI/core/config"
55

6+
gguf "github.com/gpustack/gguf-parser-go"
67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
89
)
910

11+
// ggufWithArch fabricates a minimal in-memory GGUF carrying the given
12+
// `general.architecture` and a positive `<arch>.nextn_predict_layers` count,
13+
// so HasEmbeddedMTPHead can be exercised without a real model file.
14+
func ggufWithArch(arch string, nextn uint32) *gguf.GGUFFile {
15+
return &gguf.GGUFFile{
16+
Header: gguf.GGUFHeader{
17+
MetadataKV: gguf.GGUFMetadataKVs{
18+
{
19+
Key: "general.architecture",
20+
ValueType: gguf.GGUFMetadataValueTypeString,
21+
Value: arch,
22+
},
23+
{
24+
Key: arch + ".nextn_predict_layers",
25+
ValueType: gguf.GGUFMetadataValueTypeUint32,
26+
Value: nextn,
27+
},
28+
},
29+
},
30+
}
31+
}
32+
1033
var _ = Describe("MTP auto-defaults", func() {
1134
Context("MTPSpecOptions", func() {
1235
It("returns the upstream-recommended speculative tuple", func() {
@@ -82,5 +105,20 @@ var _ = Describe("MTP auto-defaults", func() {
82105
Expect(ok).To(BeFalse())
83106
Expect(n).To(BeZero())
84107
})
108+
109+
It("detects a same-GGUF embedded head (DeepSeek/Qwen style)", func() {
110+
n, ok := HasEmbeddedMTPHead(ggufWithArch("qwen3moe", 1))
111+
Expect(ok).To(BeTrue())
112+
Expect(n).To(Equal(uint32(1)))
113+
})
114+
115+
It("ignores a gemma4-assistant draft-only model", func() {
116+
// The assistant GGUF carries nextn_predict_layers but is a separate
117+
// draft model that requires a paired target (ctx_other); it cannot
118+
// self-speculate, so it must not trigger the embedded-head defaults.
119+
n, ok := HasEmbeddedMTPHead(ggufWithArch("gemma4-assistant", 48))
120+
Expect(ok).To(BeFalse())
121+
Expect(n).To(BeZero())
122+
})
85123
})
86124
})

0 commit comments

Comments
 (0)