diff --git a/common/preset.cpp b/common/preset.cpp index 60746aad58..b4b1294777 100644 --- a/common/preset.cpp +++ b/common/preset.cpp @@ -177,6 +177,26 @@ common_presets common_presets_load(const std::string & path, common_params_conte auto key_to_opt = get_map_key_opt(ctx_params); auto ini_data = parse_ini_from_file(path); + // merge "added" into "base", preserving existing keys in "base" + auto merge_sections = [](std::map & base, const std::map & added) { + for (const auto & [key, value] : added) { + if (base.find(key) == base.end()) { + base[key] = value; + } + } + }; + + // handle the "global" section as the default preset + if (ini_data.find("*") != ini_data.end()) { + auto & global_section = ini_data["*"]; + for (auto & item : ini_data) { + merge_sections(item.second, global_section); + } + } + + // TODO: support inheritance between presets in the future + // note: server-models also need to be aware of the case where presets inherit from cached models + for (auto section : ini_data) { common_preset preset; if (section.first.empty()) { diff --git a/tools/server/README.md b/tools/server/README.md index 9a2b9b1f36..b13bf893db 100644 --- a/tools/server/README.md +++ b/tools/server/README.md @@ -1438,6 +1438,12 @@ Example: ```ini version = 1 +; (Optional) This section provides global settings shared across all presets. +; If the same key is defined in a specific preset, it will override the value in this global section. +[*] +c = 8192 +n-gpu-layer = 8 + ; If the key corresponds to an existing model on the server, ; this will be used as the default config for that model [ggml-org/MY-MODEL-GGUF:Q8_0]