char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
8e7f22b67
char/aliceai-t5-moe
1#pragma once 2 3#include "common.h" 4#include "arg.h" 5 6#include <string> 7#include <vector> 8#include <map> 9#include <set> 10 11// 12// INI preset parser and writer 13// 14 15constexprconst char * COMMON_PRESET_DEFAULT_NAME = "default" ; 16 17struct common_preset_context ; 18 19struct common_preset { 20std ::string name ; 21 22// options are stored as common_arg to string mapping, representing CLI arg and its value 23std ::map < common_arg ,std ::string > options ; 24 25// convert preset to CLI argument list 26std ::vector < std ::string > to_args (const std ::string & bin_path = "" )const ; 27 28// convert preset to INI format string 29std ::string to_ini ()const ; 30 31// TODO: maybe implement to_env() if needed 32 33// modify preset options where argument is identified by its env variable 34void set_option (const common_preset_context & ctx ,const std ::string & env ,const std ::string & value ); 35 36// unset option by its env variable 37void unset_option (const std ::string & env ); 38 39// get option value by its env variable, return false if not found 40bool get_option (const std ::string & env ,std ::string & value )const ; 41 42// merge another preset into this one, overwriting existing options 43void merge (const common_preset & other ); 44 45// apply preset options to common_params 46// optionally specify handled_keys to only apply a subset of options (identified by their env), if empty, apply all options 47void apply_to_params (common_params & params ,const std ::set < std ::string > & handled_keys = std ::set < std ::string > ())const ; 48}; 49 50// interface for multiple presets in one file 51using common_presets = std ::map < std ::string ,common_preset > ; 52 53// context for loading and editing presets 54struct common_preset_context { 55common_params default_params ;// unused for now 56common_params_context ctx_params ; 57std ::map < std ::string ,common_arg > key_to_opt ; 58 59bool filter_allowed_keys = false; 60std ::set < std ::string > allowed_keys ; 61 62// if true, options unknown to the current example are skipped instead of being an error 63// used for config files shared by all binaries, where each binary only knows a subset of options 64bool ignore_unknown_keys = false; 65 66// if only_remote_allowed is true, only accept whitelisted keys 67common_preset_context (llama_example ex ); 68 69// load presets from INI file 70common_presets load_from_ini (const std ::string & path ,common_preset & global )const ; 71 72// generate presets from cached models 73common_presets load_from_cache ()const ; 74 75// generate presets from local models directory 76// for the directory structure, see "Using multiple models" in server/README.md 77common_presets load_from_models_dir (const std ::string & models_dir )const ; 78 79// generate one preset from CLI arguments 80common_preset load_from_args (int argc ,char ** argv )const ; 81 82// cascade multiple presets if exist on both: base < added 83// if preset does not exist in base, it will be added without modification 84common_presets cascade (const common_presets & base ,const common_presets & added )const ; 85 86// apply presets over a base preset (same idea as CSS cascading) 87common_presets cascade (const common_preset & base ,const common_presets & presets )const ; 88};