Implementation:Ggml org Llama cpp Preset
| Knowledge Sources | |
|---|---|
| Domains | Configuration |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Implements the INI-based preset system for loading, saving, and cascading model configuration presets in llama.cpp.
Description
Presets store CLI argument/value pairs (common_arg to string mappings) that can be serialized to/from INI format. The common_preset_context manages loading presets from multiple sources: INI files (parsed via PEG parser), cached model manifests, local model directories, and CLI arguments. Remote preset security is enforced via a whitelist of allowed options (model URLs, sampling params, etc.) to prevent file-writing arguments from being set remotely. Preset cascading works like CSS: base presets can be overridden by more specific ones.
Usage
Use this module for the multi-model preset system where the server can manage multiple model configurations. Presets are loaded from files, cached models, or model directories and applied via a cascading priority system.
Code Reference
Source Location
- Repository: Ggml_org_Llama_cpp
- File: common/preset.cpp
- Lines: 1-483
Signature
static std::string rm_leading_dashes(const std::string & str);
static std::set<std::string> get_remote_preset_whitelist(
const std::map<std::string, common_arg> & key_to_opt);
std::vector<std::string> common_preset::to_args(const std::string & bin_path) const;
// common_preset_context manages loading from multiple sources
// common_preset::to_ini() serializes to INI format
Import
#include "arg.h"
#include "preset.h"
#include "peg-parser.h"
#include "log.h"
#include "download.h"
#include <fstream>
#include <sstream>
#include <filesystem>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| bin_path | std::string | No | Binary path to prepend to generated argument list |
| key_to_opt | std::map<std::string, common_arg> | Yes | Map of option keys to their argument definitions for whitelist filtering |
| ini_file | std::string (path) | No | Path to an INI preset file to load |
| options | map<common_arg, string> | Yes | Key-value pairs of CLI argument settings in the preset |
Outputs
| Name | Type | Description |
|---|---|---|
| args | std::vector<std::string> | CLI argument list generated from preset options via to_args |
| ini_string | std::string | INI-formatted serialization of the preset via to_ini |
| whitelist | std::set<std::string> | Set of allowed option keys for remote preset security |
Usage Examples
#include "preset.h"
// Convert a preset to CLI arguments
common_preset preset;
// ... populate preset options ...
std::vector<std::string> args = preset.to_args("/usr/local/bin/llama-server");
// args = ["/usr/local/bin/llama-server", "--model-url", "https://...", "--temp", "0.7", ...]
// Serialize preset to INI format
std::string ini = preset.to_ini();
// [preset]
// model-url = https://...
// temp = 0.7
// Load presets with cascading priority
common_preset_context ctx;
// Presets from files, model directories, and CLI are merged with cascading priority