mirror of
https://github.com/mudler/LocalAI.git
synced 2026-07-08 07:18:31 -04:00
* fix(reasoning): don't persist request-scoped reasoning_effort into model config When a model sets `reasoning_effort: none` (or any default) in its YAML without an explicit `reasoning.disable`, ApplyReasoningEffort resolves that default at request time and sets ReasoningConfig.DisableReasoning on the request-scoped config copy. The post-load thinking/marker probe then wrote that request-scoped value back into the loader's persistent config via UpdateModelConfig, making it look as though the operator had explicitly set reasoning.disable=true. From then on, per-request `reasoning_effort` overrides were silently ignored (an explicit operator disable wins over a request asking to think). DetectThinkingSupportFromBackend only fills reasoning slots that are still nil, so a slot already set here came from ApplyReasoningEffort, not the probe. Snapshot which slots were nil before the probe and only persist those, so the probe's genuine backend detection is still saved while request-time reasoning effort never leaks into the persistent config. Fixes #10622 Signed-off-by: Tai An <antai12232931@outlook.com> * test(reasoning): cover persist-guard added in this PR, extract for testability ModelInference's post-probe persistence of ReasoningConfig.DisableReasoning / DisableReasoningTagPrefill had no test: the guard logic lived inline in a closure only reachable through a live gRPC backend. Extract it into persistProbedReasoning (pure refactor, no behavior change) so it can be exercised directly against a ModelConfigLoader, then add specs covering: - a probe-filled slot (nil beforehand) gets persisted - a slot that already carried a request-scoped value (e.g. from reasoning_effort: none) is left alone, i.e. the #10622 regression stays fixed - an operator's explicit persisted disable is preserved when the guard is false - the media marker still persists unconditionally Verified red/green: reverting persistProbedReasoning to the old unconditional copy fails exactly the two guard specs. Assisted-by: Claude:claude-sonnet-5 go vet Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(reasoning): ignore os.Remove error in temp file cleanup (errcheck) Signed-off-by: Tai An <antai12232931@outlook.com> * chore: empty commit to re-trigger flaky Agent Jobs CI test Signed-off-by: Tai An <antai12232931@outlook.com> --------- Signed-off-by: Tai An <antai12232931@outlook.com> Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@users.noreply.github.com>
119 lines
4.1 KiB
Go
119 lines
4.1 KiB
Go
package backend
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
|
|
"github.com/gpustack/gguf-parser-go/util/ptr"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("thinking probe gating", func() {
|
|
It("probes tokenizer-template models when any reasoning default is still unset", func() {
|
|
cfg := &config.ModelConfig{
|
|
TemplateConfig: config.TemplateConfig{UseTokenizerTemplate: true},
|
|
}
|
|
Expect(needsThinkingProbe(cfg)).To(BeTrue())
|
|
|
|
cfg.ReasoningConfig.DisableReasoning = ptr.To(true)
|
|
Expect(needsThinkingProbe(cfg)).To(BeTrue())
|
|
|
|
cfg.ReasoningConfig.DisableReasoningTagPrefill = ptr.To(true)
|
|
Expect(needsThinkingProbe(cfg)).To(BeFalse())
|
|
})
|
|
|
|
It("does not probe when tokenizer templates are disabled", func() {
|
|
cfg := &config.ModelConfig{}
|
|
Expect(needsThinkingProbe(cfg)).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
var _ = Describe("persistProbedReasoning", func() {
|
|
const modelName = "probe-test"
|
|
|
|
// newLoaderWithConfig seeds a ModelConfigLoader with a single model config
|
|
// parsed from yamlBody, mirroring how the loader is populated from disk.
|
|
newLoaderWithConfig := func(yamlBody string) *config.ModelConfigLoader {
|
|
tmp, err := os.CreateTemp("", "persist-probed-reasoning-*.yaml")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
defer func() { _ = os.Remove(tmp.Name()) }()
|
|
|
|
_, err = tmp.WriteString(yamlBody)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(tmp.Close()).To(Succeed())
|
|
|
|
cl := config.NewModelConfigLoader("")
|
|
Expect(cl.ReadModelConfig(tmp.Name())).To(Succeed())
|
|
return cl
|
|
}
|
|
|
|
It("persists a reasoning slot the probe was allowed to fill (was nil beforehand)", func() {
|
|
cl := newLoaderWithConfig("name: probe-test\nbackend: llama-cpp\n")
|
|
|
|
probed := &config.ModelConfig{}
|
|
probed.Name = modelName
|
|
probed.ReasoningConfig.DisableReasoning = ptr.To(false) // backend detected: supports thinking
|
|
probed.ReasoningConfig.DisableReasoningTagPrefill = ptr.To(true)
|
|
|
|
persistProbedReasoning(cl, modelName, probed, true, true)
|
|
|
|
cfg, ok := cl.GetModelConfig(modelName)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(cfg.ReasoningConfig.DisableReasoning).ToNot(BeNil())
|
|
Expect(*cfg.ReasoningConfig.DisableReasoning).To(BeFalse())
|
|
Expect(cfg.ReasoningConfig.DisableReasoningTagPrefill).ToNot(BeNil())
|
|
Expect(*cfg.ReasoningConfig.DisableReasoningTagPrefill).To(BeTrue())
|
|
})
|
|
|
|
It("does not persist a slot that already carried a request-scoped value before the probe ran", func() {
|
|
cl := newLoaderWithConfig("name: probe-test\nbackend: llama-cpp\n")
|
|
|
|
probed := &config.ModelConfig{}
|
|
probed.Name = modelName
|
|
// Simulates ApplyReasoningEffort("none") having set this on the
|
|
// request-scoped copy before the probe ran - not a genuine backend
|
|
// detection, so it must never reach the persisted config (#10622).
|
|
probed.ReasoningConfig.DisableReasoning = ptr.To(true)
|
|
|
|
persistProbedReasoning(cl, modelName, probed, false, false)
|
|
|
|
cfg, ok := cl.GetModelConfig(modelName)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(cfg.ReasoningConfig.DisableReasoning).To(BeNil())
|
|
Expect(cfg.ReasoningConfig.DisableReasoningTagPrefill).To(BeNil())
|
|
})
|
|
|
|
It("preserves an operator's explicit persisted disable when the guard is false", func() {
|
|
cl := newLoaderWithConfig("name: probe-test\nbackend: llama-cpp\nreasoning:\n disable: true\n")
|
|
|
|
probed := &config.ModelConfig{}
|
|
probed.Name = modelName
|
|
// Even if the request-scoped copy ends up holding a different value,
|
|
// persistDisableReasoning=false must keep the operator's own setting.
|
|
probed.ReasoningConfig.DisableReasoning = ptr.To(false)
|
|
|
|
persistProbedReasoning(cl, modelName, probed, false, false)
|
|
|
|
cfg, ok := cl.GetModelConfig(modelName)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(cfg.ReasoningConfig.DisableReasoning).ToNot(BeNil())
|
|
Expect(*cfg.ReasoningConfig.DisableReasoning).To(BeTrue())
|
|
})
|
|
|
|
It("persists the media marker regardless of the reasoning guards", func() {
|
|
cl := newLoaderWithConfig("name: probe-test\nbackend: llama-cpp\n")
|
|
|
|
probed := &config.ModelConfig{}
|
|
probed.Name = modelName
|
|
probed.MediaMarker = "<__media__>"
|
|
|
|
persistProbedReasoning(cl, modelName, probed, false, false)
|
|
|
|
cfg, ok := cl.GetModelConfig(modelName)
|
|
Expect(ok).To(BeTrue())
|
|
Expect(cfg.MediaMarker).To(Equal("<__media__>"))
|
|
})
|
|
})
|