MCPcopy
hub / github.com/mudler/LocalAI / ApplyInferenceDefaults

Function ApplyInferenceDefaults

core/config/inference_defaults.go:73–128  ·  view source on GitHub ↗

ApplyInferenceDefaults sets recommended inference parameters on cfg based on modelIDs. Tries each modelID in order; the first match wins. Only fills in parameters that are not already set (nil pointers or zero values).

(cfg *ModelConfig, modelIDs ...string)

Source from the content-addressed store, hash-verified

71// Tries each modelID in order; the first match wins.
72// Only fills in parameters that are not already set (nil pointers or zero values).
73func 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 }
86 if family == nil {
87 return
88 }
89
90 xlog.Debug("[inference_defaults] applying defaults for model", "modelID", matchedID, "family", family)
91
92 if cfg.Temperature == nil {
93 if v, ok := family["temperature"]; ok {
94 cfg.Temperature = &v
95 }
96 }
97
98 if cfg.TopP == nil {
99 if v, ok := family["top_p"]; ok {
100 cfg.TopP = &v
101 }
102 }
103
104 if cfg.TopK == nil {
105 if v, ok := family["top_k"]; ok {
106 intV := int(v)
107 cfg.TopK = &intV
108 }
109 }
110
111 if cfg.MinP == nil {
112 if v, ok := family["min_p"]; ok {
113 cfg.MinP = &v
114 }
115 }
116
117 if cfg.RepeatPenalty == 0 {
118 if v, ok := family["repeat_penalty"]; ok {
119 cfg.RepeatPenalty = v
120 }
121 }
122
123 if cfg.PresencePenalty == 0 {
124 if v, ok := family["presence_penalty"]; ok {
125 cfg.PresencePenalty = v
126 }
127 }
128}

Callers 8

ImportMethod · 0.92
ImportMethod · 0.92
ImportMethod · 0.92
ImportMethod · 0.92
ImportMethod · 0.92
guessGGUFFromFileFunction · 0.85
SetDefaultsMethod · 0.85

Calls 1

MatchModelFamilyFunction · 0.85

Tested by

no test coverage detected