Skip to content

Commit 78f8ee7

Browse files
Anai-Guorichiejp
authored andcommitted
fix(runtime-settings): apply persisted threads/context_size/f16 at startup (#10853)
ApplyRuntimeSettings persists the performance settings (threads, context_size, f16) on the live /api/settings path, but the startup loader loadRuntimeSettingsFromFile never read them back, so a value saved via the Middleware UI was silently ignored on the next restart: the model booted with the CLI/physical-core default and GET /api/settings echoed that default instead of the saved value (#10845). Threads needs special handling: unlike context_size/f16, WithThreads eagerly resolves an unset (0) value to xsysinfo.CPUPhysicalCores() at option-apply time, so options.Threads is never 0 in the loader and the usual "== default" heuristic cannot tell an env/CLI value from the physical-core fallback. Detect LOCALAI_THREADS/THREADS explicitly so the env still wins over the persisted file value. Signed-off-by: Anai-Guo <Anai-Guo@users.noreply.github.com> Co-authored-by: Anai-Guo <Anai-Guo@users.noreply.github.com> Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent 0878c7d commit 78f8ee7

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

core/application/startup.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,36 @@ func loadRuntimeSettingsFromFile(options *config.ApplicationConfig) {
675675
options.AgentJobRetentionDays = *settings.AgentJobRetentionDays
676676
}
677677
}
678+
679+
// Performance settings (threads / context size / f16). ApplyRuntimeSettings
680+
// already persists these on the live /api/settings path, but the startup
681+
// loader dropped them, so a value saved via the Middleware UI was silently
682+
// ignored on restart (the model booted with the CLI/physical-core default).
683+
//
684+
// Threads is special: unlike ContextSize/F16, WithThreads eagerly resolves
685+
// an unset (0) value to xsysinfo.CPUPhysicalCores() at option-apply time
686+
// (see application_config.go), so options.Threads is never 0 here and the
687+
// usual "== default" heuristic can't distinguish an env/CLI value from the
688+
// physical-core fallback. Detect the env/CLI explicitly so
689+
// LOCALAI_THREADS/THREADS still win over the persisted file value.
690+
if settings.Threads != nil {
691+
if os.Getenv("LOCALAI_THREADS") == "" && os.Getenv("THREADS") == "" {
692+
options.Threads = *settings.Threads
693+
}
694+
}
695+
if settings.ContextSize != nil {
696+
// Only apply if current value is default (0), suggesting it wasn't set from env var
697+
if options.ContextSize == 0 {
698+
options.ContextSize = *settings.ContextSize
699+
}
700+
}
701+
if settings.F16 != nil {
702+
// Only apply if current value is default (false), suggesting it wasn't set from env var
703+
if !options.F16 {
704+
options.F16 = *settings.F16
705+
}
706+
}
707+
678708
if !options.WatchDogIdle && !options.WatchDogBusy {
679709
if settings.WatchdogEnabled != nil && *settings.WatchdogEnabled {
680710
options.WatchDog = true

0 commit comments

Comments
 (0)