Skip to content

Commit bdbba5d

Browse files
committed
chore: apply defaults also to models installed via gallery
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 455af5c commit bdbba5d

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

core/config/inference_defaults.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,27 @@ func MatchModelFamily(modelID string) map[string]float64 {
6767
return nil
6868
}
6969

70-
// ApplyInferenceDefaults sets recommended inference parameters on cfg based on modelID.
70+
// ApplyInferenceDefaults sets recommended inference parameters on cfg based on modelIDs.
71+
// Tries each modelID in order; the first match wins.
7172
// Only fills in parameters that are not already set (nil pointers or zero values).
72-
func ApplyInferenceDefaults(cfg *ModelConfig, modelID string) {
73-
family := MatchModelFamily(modelID)
73+
func ApplyInferenceDefaults(cfg *ModelConfig, modelIDs ...string) {
74+
var family map[string]float64
75+
var matchedID string
76+
for _, id := range modelIDs {
77+
if id == "" {
78+
continue
79+
}
80+
if f := MatchModelFamily(id); f != nil {
81+
family = f
82+
matchedID = id
83+
break
84+
}
85+
}
7486
if family == nil {
7587
return
7688
}
7789

78-
xlog.Debug("[inference_defaults] applying defaults for model", "modelID", modelID, "family", family)
90+
xlog.Debug("[inference_defaults] applying defaults for model", "modelID", matchedID, "family", family)
7991

8092
if cfg.Temperature == nil {
8193
if v, ok := family["temperature"]; ok {

core/config/model_config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,11 @@ func (cfg *ModelConfig) SetDefaults(opts ...ConfigLoaderOption) {
375375
threads := lo.threads
376376
f16 := lo.f16
377377
debug := lo.debug
378+
379+
// Apply model-family-specific inference defaults before generic fallbacks.
380+
// This ensures gallery-installed and runtime-loaded models get optimal parameters.
381+
ApplyInferenceDefaults(cfg, cfg.Name, cfg.Model)
382+
378383
// https://github.com/ggerganov/llama.cpp/blob/75cd4c77292034ecec587ecb401366f57338f7c0/common/sampling.h#L22
379384
defaultTopP := 0.95
380385
defaultTopK := 40

core/gallery/models.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,15 @@ func InstallModel(ctx context.Context, systemState *system.SystemState, nameOver
264264
return nil, fmt.Errorf("failed to unmarshal updated config YAML: %v", err)
265265
}
266266

267+
// Apply model-family-specific inference defaults so they are persisted in the config YAML.
268+
lconfig.ApplyInferenceDefaults(&modelConfig, name, modelConfig.Model)
269+
270+
// Re-marshal to include any inference defaults that were applied.
271+
updatedConfigYAML, err = yaml.Marshal(modelConfig)
272+
if err != nil {
273+
return nil, fmt.Errorf("failed to marshal config with inference defaults: %v", err)
274+
}
275+
267276
if valid, err := modelConfig.Validate(); !valid {
268277
return nil, fmt.Errorf("failed to validate updated config YAML: %v", err)
269278
}

0 commit comments

Comments
 (0)