MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / load_models

Method load_models

subprojects/llama.cpp/tools/server/server-models.cpp:197–308  ·  view source on GitHub ↗

TODO: allow refreshing cached model list

Source from the content-addressed store, hash-verified

195
196// TODO: allow refreshing cached model list
197void server_models::load_models() {
198 // loading models from 3 sources:
199 // 1. cached models
200 common_presets cached_models = ctx_preset.load_from_cache();
201 SRV_INF("Loaded %zu cached model presets\n", cached_models.size());
202 // 2. local models from --models-dir
203 common_presets local_models;
204 if (!base_params.models_dir.empty()) {
205 local_models = ctx_preset.load_from_models_dir(base_params.models_dir);
206 SRV_INF("Loaded %zu local model presets from %s\n", local_models.size(), base_params.models_dir.c_str());
207 }
208 // 3. custom-path models from presets
209 common_preset global = {};
210 common_presets custom_presets = {};
211 if (!base_params.models_preset.empty()) {
212 custom_presets = ctx_preset.load_from_ini(base_params.models_preset, global);
213 SRV_INF("Loaded %zu custom model presets from %s\n", custom_presets.size(), base_params.models_preset.c_str());
214 }
215
216 // cascade, apply global preset first
217 cached_models = ctx_preset.cascade(global, cached_models);
218 local_models = ctx_preset.cascade(global, local_models);
219 custom_presets = ctx_preset.cascade(global, custom_presets);
220
221 // note: if a model exists in both cached and local, local takes precedence
222 common_presets final_presets;
223 for (const auto & [name, preset] : cached_models) {
224 final_presets[name] = preset;
225 }
226 for (const auto & [name, preset] : local_models) {
227 final_presets[name] = preset;
228 }
229
230 // process custom presets from INI
231 for (const auto & [name, custom] : custom_presets) {
232 if (final_presets.find(name) != final_presets.end()) {
233 // apply custom config if exists
234 common_preset & target = final_presets[name];
235 target.merge(custom);
236 } else {
237 // otherwise add directly
238 final_presets[name] = custom;
239 }
240 }
241
242 // server base preset from CLI args take highest precedence
243 for (auto & [name, preset] : final_presets) {
244 preset.merge(base_preset);
245 }
246
247 // convert presets to server_model_meta and add to mapping
248 for (const auto & preset : final_presets) {
249 server_model_meta meta{
250 /* preset */ preset.second,
251 /* name */ preset.first,
252 /* port */ 0,
253 /* status */ SERVER_MODEL_STATUS_UNLOADED,
254 /* last_used */ 0,

Callers

nothing calls this directly

Calls 14

load_from_cacheMethod · 0.80
load_from_models_dirMethod · 0.80
load_from_iniMethod · 0.80
cascadeMethod · 0.80
get_optionMethod · 0.80
sizeMethod · 0.65
emptyMethod · 0.65
findMethod · 0.65
string_formatFunction · 0.50
loadFunction · 0.50
endMethod · 0.45
mergeMethod · 0.45

Tested by

no test coverage detected