arg.cpp 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. #include "arg.h"
  2. #include "sampling.h"
  3. #include <algorithm>
  4. #include <string>
  5. #include <vector>
  6. #include <set>
  7. #include <fstream>
  8. #include <regex>
  9. #include <cstdarg>
  10. #include <climits>
  11. #include "json-schema-to-grammar.h"
  12. using json = nlohmann::ordered_json;
  13. llama_arg & llama_arg::set_examples(std::initializer_list<enum llama_example> examples) {
  14. this->examples = std::move(examples);
  15. return *this;
  16. }
  17. llama_arg & llama_arg::set_env(const char * env) {
  18. help = help + "\n(env: " + env + ")";
  19. this->env = env;
  20. return *this;
  21. }
  22. llama_arg & llama_arg::set_sparam() {
  23. is_sparam = true;
  24. return *this;
  25. }
  26. bool llama_arg::in_example(enum llama_example ex) {
  27. return examples.find(ex) != examples.end();
  28. }
  29. bool llama_arg::get_value_from_env(std::string & output) {
  30. if (env == nullptr) return false;
  31. char * value = std::getenv(env);
  32. if (value) {
  33. output = value;
  34. return true;
  35. }
  36. return false;
  37. }
  38. bool llama_arg::has_value_from_env() {
  39. return env != nullptr && std::getenv(env);
  40. }
  41. static std::vector<std::string> break_str_into_lines(std::string input, size_t max_char_per_line) {
  42. std::vector<std::string> result;
  43. std::istringstream iss(input);
  44. std::string line;
  45. auto add_line = [&](const std::string& l) {
  46. if (l.length() <= max_char_per_line) {
  47. result.push_back(l);
  48. } else {
  49. std::istringstream line_stream(l);
  50. std::string word, current_line;
  51. while (line_stream >> word) {
  52. if (current_line.length() + !current_line.empty() + word.length() > max_char_per_line) {
  53. if (!current_line.empty()) result.push_back(current_line);
  54. current_line = word;
  55. } else {
  56. current_line += (!current_line.empty() ? " " : "") + word;
  57. }
  58. }
  59. if (!current_line.empty()) result.push_back(current_line);
  60. }
  61. };
  62. while (std::getline(iss, line)) {
  63. add_line(line);
  64. }
  65. return result;
  66. }
  67. std::string llama_arg::to_string() {
  68. // params for printing to console
  69. const static int n_leading_spaces = 40;
  70. const static int n_char_per_line_help = 70; // TODO: detect this based on current console
  71. std::string leading_spaces(n_leading_spaces, ' ');
  72. std::ostringstream ss;
  73. for (const auto arg : args) {
  74. if (arg == args.front()) {
  75. if (args.size() == 1) {
  76. ss << arg;
  77. } else {
  78. // first arg is usually abbreviation, we need padding to make it more beautiful
  79. auto tmp = std::string(arg) + ", ";
  80. auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
  81. ss << tmp << spaces;
  82. }
  83. } else {
  84. ss << arg << (arg != args.back() ? ", " : "");
  85. }
  86. }
  87. if (value_hint) ss << " " << value_hint;
  88. if (value_hint_2) ss << " " << value_hint_2;
  89. if (ss.tellp() > n_leading_spaces - 3) {
  90. // current line is too long, add new line
  91. ss << "\n" << leading_spaces;
  92. } else {
  93. // padding between arg and help, same line
  94. ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
  95. }
  96. const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
  97. for (const auto & line : help_lines) {
  98. ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
  99. }
  100. return ss.str();
  101. }
  102. //
  103. // utils
  104. //
  105. #ifdef __GNUC__
  106. #ifdef __MINGW32__
  107. #define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__)))
  108. #else
  109. #define LLAMA_COMMON_ATTRIBUTE_FORMAT(...) __attribute__((format(printf, __VA_ARGS__)))
  110. #endif
  111. #else
  112. #define LLAMA_COMMON_ATTRIBUTE_FORMAT(...)
  113. #endif
  114. LLAMA_COMMON_ATTRIBUTE_FORMAT(1, 2)
  115. static std::string format(const char * fmt, ...) {
  116. va_list ap;
  117. va_list ap2;
  118. va_start(ap, fmt);
  119. va_copy(ap2, ap);
  120. int size = vsnprintf(NULL, 0, fmt, ap);
  121. GGML_ASSERT(size >= 0 && size < INT_MAX); // NOLINT
  122. std::vector<char> buf(size + 1);
  123. int size2 = vsnprintf(buf.data(), size + 1, fmt, ap2);
  124. GGML_ASSERT(size2 == size);
  125. va_end(ap2);
  126. va_end(ap);
  127. return std::string(buf.data(), size);
  128. }
  129. static void gpt_params_handle_model_default(gpt_params & params) {
  130. if (!params.hf_repo.empty()) {
  131. // short-hand to avoid specifying --hf-file -> default it to --model
  132. if (params.hf_file.empty()) {
  133. if (params.model.empty()) {
  134. throw std::invalid_argument("error: --hf-repo requires either --hf-file or --model\n");
  135. }
  136. params.hf_file = params.model;
  137. } else if (params.model.empty()) {
  138. params.model = fs_get_cache_file(string_split(params.hf_file, '/').back());
  139. }
  140. } else if (!params.model_url.empty()) {
  141. if (params.model.empty()) {
  142. auto f = string_split(params.model_url, '#').front();
  143. f = string_split(f, '?').front();
  144. params.model = fs_get_cache_file(string_split(f, '/').back());
  145. }
  146. } else if (params.model.empty()) {
  147. params.model = DEFAULT_MODEL_PATH;
  148. }
  149. }
  150. //
  151. // CLI argument parsing functions
  152. //
  153. static bool gpt_params_parse_ex(int argc, char ** argv, gpt_params_context & ctx_arg) {
  154. std::string arg;
  155. const std::string arg_prefix = "--";
  156. gpt_params & params = ctx_arg.params;
  157. std::unordered_map<std::string, llama_arg *> arg_to_options;
  158. for (auto & opt : ctx_arg.options) {
  159. for (const auto & arg : opt.args) {
  160. arg_to_options[arg] = &opt;
  161. }
  162. }
  163. // handle environment variables
  164. for (auto & opt : ctx_arg.options) {
  165. std::string value;
  166. if (opt.get_value_from_env(value)) {
  167. try {
  168. if (opt.handler_void && (value == "1" || value == "true")) {
  169. opt.handler_void(params);
  170. }
  171. if (opt.handler_int) {
  172. opt.handler_int(params, std::stoi(value));
  173. }
  174. if (opt.handler_string) {
  175. opt.handler_string(params, value);
  176. continue;
  177. }
  178. } catch (std::exception & e) {
  179. throw std::invalid_argument(format(
  180. "error while handling environment variable \"%s\": %s\n\n", opt.env, e.what()));
  181. }
  182. }
  183. }
  184. // handle command line arguments
  185. auto check_arg = [&](int i) {
  186. if (i+1 >= argc) {
  187. throw std::invalid_argument("expected value for argument");
  188. }
  189. };
  190. for (int i = 1; i < argc; i++) {
  191. const std::string arg_prefix = "--";
  192. std::string arg = argv[i];
  193. if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
  194. std::replace(arg.begin(), arg.end(), '_', '-');
  195. }
  196. if (arg_to_options.find(arg) == arg_to_options.end()) {
  197. throw std::invalid_argument(format("error: invalid argument: %s", arg.c_str()));
  198. }
  199. auto opt = *arg_to_options[arg];
  200. if (opt.has_value_from_env()) {
  201. fprintf(stderr, "warn: %s environment variable is set, but will be overwritten by command line argument %s\n", opt.env, arg.c_str());
  202. }
  203. try {
  204. if (opt.handler_void) {
  205. opt.handler_void(params);
  206. continue;
  207. }
  208. // arg with single value
  209. check_arg(i);
  210. std::string val = argv[++i];
  211. if (opt.handler_int) {
  212. opt.handler_int(params, std::stoi(val));
  213. continue;
  214. }
  215. if (opt.handler_string) {
  216. opt.handler_string(params, val);
  217. continue;
  218. }
  219. // arg with 2 values
  220. check_arg(i);
  221. std::string val2 = argv[++i];
  222. if (opt.handler_str_str) {
  223. opt.handler_str_str(params, val, val2);
  224. continue;
  225. }
  226. } catch (std::exception & e) {
  227. throw std::invalid_argument(format(
  228. "error while handling argument \"%s\": %s\n\n"
  229. "usage:\n%s\n\nto show complete usage, run with -h",
  230. arg.c_str(), e.what(), arg_to_options[arg]->to_string().c_str()));
  231. }
  232. }
  233. postprocess_cpu_params(params.cpuparams, nullptr);
  234. postprocess_cpu_params(params.cpuparams_batch, &params.cpuparams);
  235. postprocess_cpu_params(params.draft_cpuparams, &params.cpuparams);
  236. postprocess_cpu_params(params.draft_cpuparams_batch, &params.cpuparams_batch);
  237. if (params.prompt_cache_all && (params.interactive || params.interactive_first)) {
  238. throw std::invalid_argument("error: --prompt-cache-all not supported in interactive mode yet\n");
  239. }
  240. gpt_params_handle_model_default(params);
  241. if (params.escape) {
  242. string_process_escapes(params.prompt);
  243. string_process_escapes(params.input_prefix);
  244. string_process_escapes(params.input_suffix);
  245. for (auto & antiprompt : params.antiprompt) {
  246. string_process_escapes(antiprompt);
  247. }
  248. }
  249. if (!params.kv_overrides.empty()) {
  250. params.kv_overrides.emplace_back();
  251. params.kv_overrides.back().key[0] = 0;
  252. }
  253. return true;
  254. }
  255. static void gpt_params_print_usage(gpt_params_context & ctx_arg) {
  256. auto print_options = [](std::vector<llama_arg *> & options) {
  257. for (llama_arg * opt : options) {
  258. printf("%s", opt->to_string().c_str());
  259. }
  260. };
  261. std::vector<llama_arg *> common_options;
  262. std::vector<llama_arg *> sparam_options;
  263. std::vector<llama_arg *> specific_options;
  264. for (auto & opt : ctx_arg.options) {
  265. // in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
  266. if (opt.is_sparam) {
  267. sparam_options.push_back(&opt);
  268. } else if (opt.in_example(ctx_arg.ex)) {
  269. specific_options.push_back(&opt);
  270. } else {
  271. common_options.push_back(&opt);
  272. }
  273. }
  274. printf("----- common params -----\n\n");
  275. print_options(common_options);
  276. printf("\n\n----- sampling params -----\n\n");
  277. print_options(sparam_options);
  278. // TODO: maybe convert enum llama_example to string
  279. printf("\n\n----- example-specific params -----\n\n");
  280. print_options(specific_options);
  281. }
  282. bool gpt_params_parse(int argc, char ** argv, gpt_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  283. auto ctx_arg = gpt_params_parser_init(params, ex, print_usage);
  284. const gpt_params params_org = ctx_arg.params; // the example can modify the default params
  285. try {
  286. if (!gpt_params_parse_ex(argc, argv, ctx_arg)) {
  287. ctx_arg.params = params_org;
  288. return false;
  289. }
  290. if (ctx_arg.params.usage) {
  291. gpt_params_print_usage(ctx_arg);
  292. if (ctx_arg.print_usage) {
  293. ctx_arg.print_usage(argc, argv);
  294. }
  295. exit(0);
  296. }
  297. } catch (const std::invalid_argument & ex) {
  298. fprintf(stderr, "%s\n", ex.what());
  299. ctx_arg.params = params_org;
  300. return false;
  301. }
  302. return true;
  303. }
  304. gpt_params_context gpt_params_parser_init(gpt_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  305. gpt_params_context ctx_arg(params);
  306. ctx_arg.print_usage = print_usage;
  307. ctx_arg.ex = ex;
  308. std::string sampler_type_chars;
  309. std::string sampler_type_names;
  310. for (const auto & sampler : params.sparams.samplers) {
  311. sampler_type_chars += gpt_sampler_type_to_chr(sampler);
  312. sampler_type_names += gpt_sampler_type_to_str(sampler) + ";";
  313. }
  314. sampler_type_names.pop_back();
  315. /**
  316. * filter options by example
  317. * rules:
  318. * - all examples inherit options from LLAMA_EXAMPLE_COMMON
  319. * - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example
  320. * - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example
  321. */
  322. auto add_opt = [&](llama_arg arg) {
  323. if (arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) {
  324. ctx_arg.options.push_back(std::move(arg));
  325. }
  326. };
  327. add_opt(llama_arg(
  328. {"-h", "--help", "--usage"},
  329. "print usage and exit",
  330. [](gpt_params & params) {
  331. params.usage = true;
  332. }
  333. ));
  334. add_opt(llama_arg(
  335. {"--version"},
  336. "show version and build info",
  337. [](gpt_params &) {
  338. fprintf(stderr, "version: %d (%s)\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT);
  339. fprintf(stderr, "built with %s for %s\n", LLAMA_COMPILER, LLAMA_BUILD_TARGET);
  340. exit(0);
  341. }
  342. ));
  343. add_opt(llama_arg(
  344. {"-v", "--verbose"},
  345. "print verbose information",
  346. [](gpt_params & params) {
  347. params.verbosity = 1;
  348. }
  349. ));
  350. add_opt(llama_arg(
  351. {"--verbosity"}, "N",
  352. format("set specific verbosity level (default: %d)", params.verbosity),
  353. [](gpt_params & params, int value) {
  354. params.verbosity = value;
  355. }
  356. ));
  357. add_opt(llama_arg(
  358. {"--verbose-prompt"},
  359. format("print a verbose prompt before generation (default: %s)", params.verbose_prompt ? "true" : "false"),
  360. [](gpt_params & params) {
  361. params.verbose_prompt = true;
  362. }
  363. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  364. add_opt(llama_arg(
  365. {"--no-display-prompt"},
  366. format("don't print prompt at generation (default: %s)", !params.display_prompt ? "true" : "false"),
  367. [](gpt_params & params) {
  368. params.display_prompt = false;
  369. }
  370. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  371. add_opt(llama_arg(
  372. {"-co", "--color"},
  373. format("colorise output to distinguish prompt and user input from generations (default: %s)", params.use_color ? "true" : "false"),
  374. [](gpt_params & params) {
  375. params.use_color = true;
  376. }
  377. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
  378. add_opt(llama_arg(
  379. {"-t", "--threads"}, "N",
  380. format("number of threads to use during generation (default: %d)", params.cpuparams.n_threads),
  381. [](gpt_params & params, int value) {
  382. params.cpuparams.n_threads = value;
  383. if (params.cpuparams.n_threads <= 0) {
  384. params.cpuparams.n_threads = std::thread::hardware_concurrency();
  385. }
  386. }
  387. ).set_env("LLAMA_ARG_THREADS"));
  388. add_opt(llama_arg(
  389. {"-tb", "--threads-batch"}, "N",
  390. "number of threads to use during batch and prompt processing (default: same as --threads)",
  391. [](gpt_params & params, int value) {
  392. params.cpuparams_batch.n_threads = value;
  393. if (params.cpuparams_batch.n_threads <= 0) {
  394. params.cpuparams_batch.n_threads = std::thread::hardware_concurrency();
  395. }
  396. }
  397. ));
  398. add_opt(llama_arg(
  399. {"-td", "--threads-draft"}, "N",
  400. "number of threads to use during generation (default: same as --threads)",
  401. [](gpt_params & params, int value) {
  402. params.draft_cpuparams.n_threads = value;
  403. if (params.draft_cpuparams.n_threads <= 0) {
  404. params.draft_cpuparams.n_threads = std::thread::hardware_concurrency();
  405. }
  406. }
  407. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  408. add_opt(llama_arg(
  409. {"-tbd", "--threads-batch-draft"}, "N",
  410. "number of threads to use during batch and prompt processing (default: same as --threads-draft)",
  411. [](gpt_params & params, int value) {
  412. params.draft_cpuparams_batch.n_threads = value;
  413. if (params.draft_cpuparams_batch.n_threads <= 0) {
  414. params.draft_cpuparams_batch.n_threads = std::thread::hardware_concurrency();
  415. }
  416. }
  417. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  418. add_opt(llama_arg(
  419. {"-C", "--cpu-mask"}, "M",
  420. "CPU affinity mask: arbitrarily long hex. Complements cpu-range (default: \"\")",
  421. [](gpt_params & params, const std::string & mask) {
  422. params.cpuparams.mask_valid = true;
  423. if (!parse_cpu_mask(mask, params.cpuparams.cpumask)) {
  424. throw std::invalid_argument("invalid cpumask");
  425. }
  426. }
  427. ));
  428. add_opt(llama_arg(
  429. {"-Cr", "--cpu-range"}, "lo-hi",
  430. "range of CPUs for affinity. Complements --cpu-mask",
  431. [](gpt_params & params, const std::string & range) {
  432. params.cpuparams.mask_valid = true;
  433. if (!parse_cpu_range(range, params.cpuparams.cpumask)) {
  434. throw std::invalid_argument("invalid range");
  435. }
  436. }
  437. ));
  438. add_opt(llama_arg(
  439. {"--cpu-strict"}, "<0|1>",
  440. format("use strict CPU placement (default: %u)\n", (unsigned) params.cpuparams.strict_cpu),
  441. [](gpt_params & params, const std::string & value) {
  442. params.cpuparams.strict_cpu = std::stoul(value);
  443. }
  444. ));
  445. add_opt(llama_arg(
  446. {"--prio"}, "N",
  447. format("set process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.cpuparams.priority),
  448. [](gpt_params & params, int prio) {
  449. if (prio < 0 || prio > 3) {
  450. throw std::invalid_argument("invalid value");
  451. }
  452. params.cpuparams.priority = (enum ggml_sched_priority) prio;
  453. }
  454. ));
  455. add_opt(llama_arg(
  456. {"--poll"}, "<0...100>",
  457. format("use polling level to wait for work (0 - no polling, default: %u)\n", (unsigned) params.cpuparams.poll),
  458. [](gpt_params & params, const std::string & value) {
  459. params.cpuparams.poll = std::stoul(value);
  460. }
  461. ));
  462. add_opt(llama_arg(
  463. {"-Cb", "--cpu-mask-batch"}, "M",
  464. "CPU affinity mask: arbitrarily long hex. Complements cpu-range-batch (default: same as --cpu-mask)",
  465. [](gpt_params & params, const std::string & mask) {
  466. params.cpuparams_batch.mask_valid = true;
  467. if (!parse_cpu_mask(mask, params.cpuparams_batch.cpumask)) {
  468. throw std::invalid_argument("invalid cpumask");
  469. }
  470. }
  471. ));
  472. add_opt(llama_arg(
  473. {"-Crb", "--cpu-range-batch"}, "lo-hi",
  474. "ranges of CPUs for affinity. Complements --cpu-mask-batch",
  475. [](gpt_params & params, const std::string & range) {
  476. params.cpuparams_batch.mask_valid = true;
  477. if (!parse_cpu_range(range, params.cpuparams_batch.cpumask)) {
  478. throw std::invalid_argument("invalid range");
  479. }
  480. }
  481. ));
  482. add_opt(llama_arg(
  483. {"--cpu-strict-batch"}, "<0|1>",
  484. "use strict CPU placement (default: same as --cpu-strict)",
  485. [](gpt_params & params, int value) {
  486. params.cpuparams_batch.strict_cpu = value;
  487. }
  488. ));
  489. add_opt(llama_arg(
  490. {"--prio-batch"}, "N",
  491. format("set process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.cpuparams_batch.priority),
  492. [](gpt_params & params, int prio) {
  493. if (prio < 0 || prio > 3) {
  494. throw std::invalid_argument("invalid value");
  495. }
  496. params.cpuparams_batch.priority = (enum ggml_sched_priority) prio;
  497. }
  498. ));
  499. add_opt(llama_arg(
  500. {"--poll-batch"}, "<0|1>",
  501. "use polling to wait for work (default: same as --poll)",
  502. [](gpt_params & params, int value) {
  503. params.cpuparams_batch.poll = value;
  504. }
  505. ));
  506. add_opt(llama_arg(
  507. {"-Cd", "--cpu-mask-draft"}, "M",
  508. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  509. [](gpt_params & params, const std::string & mask) {
  510. params.draft_cpuparams.mask_valid = true;
  511. if (!parse_cpu_mask(mask, params.draft_cpuparams.cpumask)) {
  512. throw std::invalid_argument("invalid cpumask");
  513. }
  514. }
  515. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  516. add_opt(llama_arg(
  517. {"-Crd", "--cpu-range-draft"}, "lo-hi",
  518. "Ranges of CPUs for affinity. Complements --cpu-mask-draft",
  519. [](gpt_params & params, const std::string & range) {
  520. params.draft_cpuparams.mask_valid = true;
  521. if (!parse_cpu_range(range, params.draft_cpuparams.cpumask)) {
  522. throw std::invalid_argument("invalid range");
  523. }
  524. }
  525. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  526. add_opt(llama_arg(
  527. {"--cpu-strict-draft"}, "<0|1>",
  528. "Use strict CPU placement for draft model (default: same as --cpu-strict)",
  529. [](gpt_params & params, int value) {
  530. params.draft_cpuparams.strict_cpu = value;
  531. }
  532. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  533. add_opt(llama_arg(
  534. {"--prio-draft"}, "N",
  535. format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.draft_cpuparams.priority),
  536. [](gpt_params & params, int prio) {
  537. if (prio < 0 || prio > 3) {
  538. throw std::invalid_argument("invalid value");
  539. }
  540. params.draft_cpuparams.priority = (enum ggml_sched_priority) prio;
  541. }
  542. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  543. add_opt(llama_arg(
  544. {"--poll-draft"}, "<0|1>",
  545. "Use polling to wait for draft model work (default: same as --poll])",
  546. [](gpt_params & params, int value) {
  547. params.draft_cpuparams.poll = value;
  548. }
  549. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  550. add_opt(llama_arg(
  551. {"-Cbd", "--cpu-mask-batch-draft"}, "M",
  552. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  553. [](gpt_params & params, const std::string & mask) {
  554. params.draft_cpuparams_batch.mask_valid = true;
  555. if (!parse_cpu_mask(mask, params.draft_cpuparams_batch.cpumask)) {
  556. throw std::invalid_argument("invalid cpumask");
  557. }
  558. }
  559. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  560. add_opt(llama_arg(
  561. {"-Crbd", "--cpu-range-batch-draft"}, "lo-hi",
  562. "Ranges of CPUs for affinity. Complements --cpu-mask-draft-batch)",
  563. [](gpt_params & params, const std::string & range) {
  564. params.draft_cpuparams_batch.mask_valid = true;
  565. if (!parse_cpu_range(range, params.draft_cpuparams_batch.cpumask)) {
  566. throw std::invalid_argument("invalid cpumask");
  567. }
  568. }
  569. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  570. add_opt(llama_arg(
  571. {"--cpu-strict-batch-draft"}, "<0|1>",
  572. "Use strict CPU placement for draft model (default: --cpu-strict-draft)",
  573. [](gpt_params & params, int value) {
  574. params.draft_cpuparams_batch.strict_cpu = value;
  575. }
  576. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  577. add_opt(llama_arg(
  578. {"--prio-batch-draft"}, "N",
  579. format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.draft_cpuparams_batch.priority),
  580. [](gpt_params & params, int prio) {
  581. if (prio < 0 || prio > 3) {
  582. throw std::invalid_argument("invalid value");
  583. }
  584. params.draft_cpuparams_batch.priority = (enum ggml_sched_priority) prio;
  585. }
  586. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  587. add_opt(llama_arg(
  588. {"--poll-batch-draft"}, "<0|1>",
  589. "Use polling to wait for draft model work (default: --poll-draft)",
  590. [](gpt_params & params, int value) {
  591. params.draft_cpuparams_batch.poll = value;
  592. }
  593. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  594. add_opt(llama_arg(
  595. {"--draft"}, "N",
  596. format("number of tokens to draft for speculative decoding (default: %d)", params.n_draft),
  597. [](gpt_params & params, int value) {
  598. params.n_draft = value;
  599. }
  600. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP}));
  601. add_opt(llama_arg(
  602. {"-ps", "--p-split"}, "N",
  603. format("speculative decoding split probability (default: %.1f)", (double)params.p_split),
  604. [](gpt_params & params, const std::string & value) {
  605. params.p_split = std::stof(value);
  606. }
  607. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  608. add_opt(llama_arg(
  609. {"-lcs", "--lookup-cache-static"}, "FNAME",
  610. "path to static lookup cache to use for lookup decoding (not updated by generation)",
  611. [](gpt_params & params, const std::string & value) {
  612. params.lookup_cache_static = value;
  613. }
  614. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  615. add_opt(llama_arg(
  616. {"-lcd", "--lookup-cache-dynamic"}, "FNAME",
  617. "path to dynamic lookup cache to use for lookup decoding (updated by generation)",
  618. [](gpt_params & params, const std::string & value) {
  619. params.lookup_cache_dynamic = value;
  620. }
  621. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  622. add_opt(llama_arg(
  623. {"-c", "--ctx-size"}, "N",
  624. format("size of the prompt context (default: %d, 0 = loaded from model)", params.n_ctx),
  625. [](gpt_params & params, int value) {
  626. params.n_ctx = value;
  627. }
  628. ).set_env("LLAMA_ARG_CTX_SIZE"));
  629. add_opt(llama_arg(
  630. {"-n", "--predict", "--n-predict"}, "N",
  631. format("number of tokens to predict (default: %d, -1 = infinity, -2 = until context filled)", params.n_predict),
  632. [](gpt_params & params, int value) {
  633. params.n_predict = value;
  634. }
  635. ).set_env("LLAMA_ARG_N_PREDICT"));
  636. add_opt(llama_arg(
  637. {"-b", "--batch-size"}, "N",
  638. format("logical maximum batch size (default: %d)", params.n_batch),
  639. [](gpt_params & params, int value) {
  640. params.n_batch = value;
  641. }
  642. ).set_env("LLAMA_ARG_BATCH"));
  643. add_opt(llama_arg(
  644. {"-ub", "--ubatch-size"}, "N",
  645. format("physical maximum batch size (default: %d)", params.n_ubatch),
  646. [](gpt_params & params, int value) {
  647. params.n_ubatch = value;
  648. }
  649. ).set_env("LLAMA_ARG_UBATCH"));
  650. add_opt(llama_arg(
  651. {"--keep"}, "N",
  652. format("number of tokens to keep from the initial prompt (default: %d, -1 = all)", params.n_keep),
  653. [](gpt_params & params, int value) {
  654. params.n_keep = value;
  655. }
  656. ));
  657. add_opt(llama_arg(
  658. {"--chunks"}, "N",
  659. format("max number of chunks to process (default: %d, -1 = all)", params.n_chunks),
  660. [](gpt_params & params, int value) {
  661. params.n_chunks = value;
  662. }
  663. ).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_PERPLEXITY, LLAMA_EXAMPLE_RETRIEVAL}));
  664. add_opt(llama_arg(
  665. {"-fa", "--flash-attn"},
  666. format("enable Flash Attention (default: %s)", params.flash_attn ? "enabled" : "disabled"),
  667. [](gpt_params & params) {
  668. params.flash_attn = true;
  669. }
  670. ).set_env("LLAMA_ARG_FLASH_ATTN"));
  671. add_opt(llama_arg(
  672. {"-p", "--prompt"}, "PROMPT",
  673. ex == LLAMA_EXAMPLE_MAIN
  674. ? "prompt to start generation with\nif -cnv is set, this will be used as system prompt"
  675. : "prompt to start generation with",
  676. [](gpt_params & params, const std::string & value) {
  677. params.prompt = value;
  678. }
  679. ));
  680. add_opt(llama_arg(
  681. {"--no-perf"},
  682. format("disable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"),
  683. [](gpt_params & params) {
  684. params.no_perf = true;
  685. params.sparams.no_perf = true;
  686. }
  687. ).set_env("LLAMA_ARG_NO_PERF"));
  688. add_opt(llama_arg(
  689. {"-f", "--file"}, "FNAME",
  690. "a file containing the prompt (default: none)",
  691. [](gpt_params & params, const std::string & value) {
  692. std::ifstream file(value);
  693. if (!file) {
  694. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  695. }
  696. // store the external file name in params
  697. params.prompt_file = value;
  698. std::copy(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>(), back_inserter(params.prompt));
  699. if (!params.prompt.empty() && params.prompt.back() == '\n') {
  700. params.prompt.pop_back();
  701. }
  702. }
  703. ));
  704. add_opt(llama_arg(
  705. {"--in-file"}, "FNAME",
  706. "an input file (repeat to specify multiple files)",
  707. [](gpt_params & params, const std::string & value) {
  708. std::ifstream file(value);
  709. if (!file) {
  710. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  711. }
  712. params.in_files.push_back(value);
  713. }
  714. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  715. add_opt(llama_arg(
  716. {"-bf", "--binary-file"}, "FNAME",
  717. "binary file containing the prompt (default: none)",
  718. [](gpt_params & params, const std::string & value) {
  719. std::ifstream file(value, std::ios::binary);
  720. if (!file) {
  721. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  722. }
  723. // store the external file name in params
  724. params.prompt_file = value;
  725. std::ostringstream ss;
  726. ss << file.rdbuf();
  727. params.prompt = ss.str();
  728. fprintf(stderr, "Read %zu bytes from binary file %s\n", params.prompt.size(), value.c_str());
  729. }
  730. ));
  731. add_opt(llama_arg(
  732. {"-e", "--escape"},
  733. format("process escapes sequences (\\n, \\r, \\t, \\', \\\", \\\\) (default: %s)", params.escape ? "true" : "false"),
  734. [](gpt_params & params) {
  735. params.escape = true;
  736. }
  737. ));
  738. add_opt(llama_arg(
  739. {"--no-escape"},
  740. "do not process escape sequences",
  741. [](gpt_params & params) {
  742. params.escape = false;
  743. }
  744. ));
  745. add_opt(llama_arg(
  746. {"-ptc", "--print-token-count"}, "N",
  747. format("print token count every N tokens (default: %d)", params.n_print),
  748. [](gpt_params & params, int value) {
  749. params.n_print = value;
  750. }
  751. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  752. add_opt(llama_arg(
  753. {"--prompt-cache"}, "FNAME",
  754. "file to cache prompt state for faster startup (default: none)",
  755. [](gpt_params & params, const std::string & value) {
  756. params.path_prompt_cache = value;
  757. }
  758. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  759. add_opt(llama_arg(
  760. {"--prompt-cache-all"},
  761. "if specified, saves user input and generations to cache as well\n",
  762. [](gpt_params & params) {
  763. params.prompt_cache_all = true;
  764. }
  765. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  766. add_opt(llama_arg(
  767. {"--prompt-cache-ro"},
  768. "if specified, uses the prompt cache but does not update it",
  769. [](gpt_params & params) {
  770. params.prompt_cache_ro = true;
  771. }
  772. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  773. add_opt(llama_arg(
  774. {"-r", "--reverse-prompt"}, "PROMPT",
  775. "halt generation at PROMPT, return control in interactive mode\n",
  776. [](gpt_params & params, const std::string & value) {
  777. params.antiprompt.emplace_back(value);
  778. }
  779. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  780. add_opt(llama_arg(
  781. {"-sp", "--special"},
  782. format("special tokens output enabled (default: %s)", params.special ? "true" : "false"),
  783. [](gpt_params & params) {
  784. params.special = true;
  785. }
  786. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}));
  787. add_opt(llama_arg(
  788. {"-cnv", "--conversation"},
  789. format(
  790. "run in conversation mode:\n"
  791. "- does not print special tokens and suffix/prefix\n"
  792. "- interactive mode is also enabled\n"
  793. "(default: %s)",
  794. params.conversation ? "true" : "false"
  795. ),
  796. [](gpt_params & params) {
  797. params.conversation = true;
  798. }
  799. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  800. add_opt(llama_arg(
  801. {"-i", "--interactive"},
  802. format("run in interactive mode (default: %s)", params.interactive ? "true" : "false"),
  803. [](gpt_params & params) {
  804. params.interactive = true;
  805. }
  806. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  807. add_opt(llama_arg(
  808. {"-if", "--interactive-first"},
  809. format("run in interactive mode and wait for input right away (default: %s)", params.interactive_first ? "true" : "false"),
  810. [](gpt_params & params) {
  811. params.interactive_first = true;
  812. }
  813. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  814. add_opt(llama_arg(
  815. {"-mli", "--multiline-input"},
  816. "allows you to write or paste multiple lines without ending each in '\\'",
  817. [](gpt_params & params) {
  818. params.multiline_input = true;
  819. }
  820. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  821. add_opt(llama_arg(
  822. {"--in-prefix-bos"},
  823. "prefix BOS to user inputs, preceding the `--in-prefix` string",
  824. [](gpt_params & params) {
  825. params.input_prefix_bos = true;
  826. params.enable_chat_template = false;
  827. }
  828. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  829. add_opt(llama_arg(
  830. {"--in-prefix"}, "STRING",
  831. "string to prefix user inputs with (default: empty)",
  832. [](gpt_params & params, const std::string & value) {
  833. params.input_prefix = value;
  834. params.enable_chat_template = false;
  835. }
  836. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  837. add_opt(llama_arg(
  838. {"--in-suffix"}, "STRING",
  839. "string to suffix after user inputs with (default: empty)",
  840. [](gpt_params & params, const std::string & value) {
  841. params.input_suffix = value;
  842. params.enable_chat_template = false;
  843. }
  844. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  845. add_opt(llama_arg(
  846. {"--no-warmup"},
  847. "skip warming up the model with an empty run",
  848. [](gpt_params & params) {
  849. params.warmup = false;
  850. }
  851. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  852. add_opt(llama_arg(
  853. {"--spm-infill"},
  854. format(
  855. "use Suffix/Prefix/Middle pattern for infill (instead of Prefix/Suffix/Middle) as some models prefer this. (default: %s)",
  856. params.spm_infill ? "enabled" : "disabled"
  857. ),
  858. [](gpt_params & params) {
  859. params.spm_infill = true;
  860. }
  861. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_INFILL}));
  862. add_opt(llama_arg(
  863. {"--samplers"}, "SAMPLERS",
  864. format("samplers that will be used for generation in the order, separated by \';\'\n(default: %s)", sampler_type_names.c_str()),
  865. [](gpt_params & params, const std::string & value) {
  866. const auto sampler_names = string_split(value, ';');
  867. params.sparams.samplers = gpt_sampler_types_from_names(sampler_names, true);
  868. }
  869. ).set_sparam());
  870. add_opt(llama_arg(
  871. {"-s", "--seed"}, "SEED",
  872. format("RNG seed (default: %u, use random seed for %u)", params.sparams.seed, LLAMA_DEFAULT_SEED),
  873. [](gpt_params & params, const std::string & value) {
  874. params.sparams.seed = std::stoul(value);
  875. }
  876. ).set_sparam());
  877. add_opt(llama_arg(
  878. {"--sampling-seq"}, "SEQUENCE",
  879. format("simplified sequence for samplers that will be used (default: %s)", sampler_type_chars.c_str()),
  880. [](gpt_params & params, const std::string & value) {
  881. params.sparams.samplers = gpt_sampler_types_from_chars(value);
  882. }
  883. ).set_sparam());
  884. add_opt(llama_arg(
  885. {"--ignore-eos"},
  886. "ignore end of stream token and continue generating (implies --logit-bias EOS-inf)",
  887. [](gpt_params & params) {
  888. params.sparams.ignore_eos = true;
  889. }
  890. ).set_sparam());
  891. add_opt(llama_arg(
  892. {"--penalize-nl"},
  893. format("penalize newline tokens (default: %s)", params.sparams.penalize_nl ? "true" : "false"),
  894. [](gpt_params & params) {
  895. params.sparams.penalize_nl = true;
  896. }
  897. ).set_sparam());
  898. add_opt(llama_arg(
  899. {"--temp"}, "N",
  900. format("temperature (default: %.1f)", (double)params.sparams.temp),
  901. [](gpt_params & params, const std::string & value) {
  902. params.sparams.temp = std::stof(value);
  903. params.sparams.temp = std::max(params.sparams.temp, 0.0f);
  904. }
  905. ).set_sparam());
  906. add_opt(llama_arg(
  907. {"--top-k"}, "N",
  908. format("top-k sampling (default: %d, 0 = disabled)", params.sparams.top_k),
  909. [](gpt_params & params, int value) {
  910. params.sparams.top_k = value;
  911. }
  912. ).set_sparam());
  913. add_opt(llama_arg(
  914. {"--top-p"}, "N",
  915. format("top-p sampling (default: %.1f, 1.0 = disabled)", (double)params.sparams.top_p),
  916. [](gpt_params & params, const std::string & value) {
  917. params.sparams.top_p = std::stof(value);
  918. }
  919. ).set_sparam());
  920. add_opt(llama_arg(
  921. {"--min-p"}, "N",
  922. format("min-p sampling (default: %.1f, 0.0 = disabled)", (double)params.sparams.min_p),
  923. [](gpt_params & params, const std::string & value) {
  924. params.sparams.min_p = std::stof(value);
  925. }
  926. ).set_sparam());
  927. add_opt(llama_arg(
  928. {"--tfs"}, "N",
  929. format("tail free sampling, parameter z (default: %.1f, 1.0 = disabled)", (double)params.sparams.tfs_z),
  930. [](gpt_params & params, const std::string & value) {
  931. params.sparams.tfs_z = std::stof(value);
  932. }
  933. ).set_sparam());
  934. add_opt(llama_arg(
  935. {"--typical"}, "N",
  936. format("locally typical sampling, parameter p (default: %.1f, 1.0 = disabled)", (double)params.sparams.typ_p),
  937. [](gpt_params & params, const std::string & value) {
  938. params.sparams.typ_p = std::stof(value);
  939. }
  940. ).set_sparam());
  941. add_opt(llama_arg(
  942. {"--repeat-last-n"}, "N",
  943. format("last n tokens to consider for penalize (default: %d, 0 = disabled, -1 = ctx_size)", params.sparams.penalty_last_n),
  944. [](gpt_params & params, int value) {
  945. params.sparams.penalty_last_n = value;
  946. params.sparams.n_prev = std::max(params.sparams.n_prev, params.sparams.penalty_last_n);
  947. }
  948. ).set_sparam());
  949. add_opt(llama_arg(
  950. {"--repeat-penalty"}, "N",
  951. format("penalize repeat sequence of tokens (default: %.1f, 1.0 = disabled)", (double)params.sparams.penalty_repeat),
  952. [](gpt_params & params, const std::string & value) {
  953. params.sparams.penalty_repeat = std::stof(value);
  954. }
  955. ).set_sparam());
  956. add_opt(llama_arg(
  957. {"--presence-penalty"}, "N",
  958. format("repeat alpha presence penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_present),
  959. [](gpt_params & params, const std::string & value) {
  960. params.sparams.penalty_present = std::stof(value);
  961. }
  962. ).set_sparam());
  963. add_opt(llama_arg(
  964. {"--frequency-penalty"}, "N",
  965. format("repeat alpha frequency penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_freq),
  966. [](gpt_params & params, const std::string & value) {
  967. params.sparams.penalty_freq = std::stof(value);
  968. }
  969. ).set_sparam());
  970. add_opt(llama_arg(
  971. {"--dynatemp-range"}, "N",
  972. format("dynamic temperature range (default: %.1f, 0.0 = disabled)", (double)params.sparams.dynatemp_range),
  973. [](gpt_params & params, const std::string & value) {
  974. params.sparams.dynatemp_range = std::stof(value);
  975. }
  976. ).set_sparam());
  977. add_opt(llama_arg(
  978. {"--dynatemp-exp"}, "N",
  979. format("dynamic temperature exponent (default: %.1f)", (double)params.sparams.dynatemp_exponent),
  980. [](gpt_params & params, const std::string & value) {
  981. params.sparams.dynatemp_exponent = std::stof(value);
  982. }
  983. ).set_sparam());
  984. add_opt(llama_arg(
  985. {"--mirostat"}, "N",
  986. format("use Mirostat sampling.\nTop K, Nucleus, Tail Free and Locally Typical samplers are ignored if used.\n"
  987. "(default: %d, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)", params.sparams.mirostat),
  988. [](gpt_params & params, int value) {
  989. params.sparams.mirostat = value;
  990. }
  991. ).set_sparam());
  992. add_opt(llama_arg(
  993. {"--mirostat-lr"}, "N",
  994. format("Mirostat learning rate, parameter eta (default: %.1f)", (double)params.sparams.mirostat_eta),
  995. [](gpt_params & params, const std::string & value) {
  996. params.sparams.mirostat_eta = std::stof(value);
  997. }
  998. ).set_sparam());
  999. add_opt(llama_arg(
  1000. {"--mirostat-ent"}, "N",
  1001. format("Mirostat target entropy, parameter tau (default: %.1f)", (double)params.sparams.mirostat_tau),
  1002. [](gpt_params & params, const std::string & value) {
  1003. params.sparams.mirostat_tau = std::stof(value);
  1004. }
  1005. ).set_sparam());
  1006. add_opt(llama_arg(
  1007. {"-l", "--logit-bias"}, "TOKEN_ID(+/-)BIAS",
  1008. "modifies the likelihood of token appearing in the completion,\n"
  1009. "i.e. `--logit-bias 15043+1` to increase likelihood of token ' Hello',\n"
  1010. "or `--logit-bias 15043-1` to decrease likelihood of token ' Hello'",
  1011. [](gpt_params & params, const std::string & value) {
  1012. std::stringstream ss(value);
  1013. llama_token key;
  1014. char sign;
  1015. std::string value_str;
  1016. try {
  1017. if (ss >> key && ss >> sign && std::getline(ss, value_str) && (sign == '+' || sign == '-')) {
  1018. const float bias = std::stof(value_str) * ((sign == '-') ? -1.0f : 1.0f);
  1019. params.sparams.logit_bias.push_back({key, bias});
  1020. } else {
  1021. throw std::invalid_argument("invalid input format");
  1022. }
  1023. } catch (const std::exception&) {
  1024. throw std::invalid_argument("invalid input format");
  1025. }
  1026. }
  1027. ).set_sparam());
  1028. add_opt(llama_arg(
  1029. {"--grammar"}, "GRAMMAR",
  1030. format("BNF-like grammar to constrain generations (see samples in grammars/ dir) (default: '%s')", params.sparams.grammar.c_str()),
  1031. [](gpt_params & params, const std::string & value) {
  1032. params.sparams.grammar = value;
  1033. }
  1034. ).set_sparam());
  1035. add_opt(llama_arg(
  1036. {"--grammar-file"}, "FNAME",
  1037. "file to read grammar from",
  1038. [](gpt_params & params, const std::string & value) {
  1039. std::ifstream file(value);
  1040. if (!file) {
  1041. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  1042. }
  1043. std::copy(
  1044. std::istreambuf_iterator<char>(file),
  1045. std::istreambuf_iterator<char>(),
  1046. std::back_inserter(params.sparams.grammar)
  1047. );
  1048. }
  1049. ).set_sparam());
  1050. add_opt(llama_arg(
  1051. {"-j", "--json-schema"}, "SCHEMA",
  1052. "JSON schema to constrain generations (https://json-schema.org/), e.g. `{}` for any JSON object\nFor schemas w/ external $refs, use --grammar + example/json_schema_to_grammar.py instead",
  1053. [](gpt_params & params, const std::string & value) {
  1054. params.sparams.grammar = json_schema_to_grammar(json::parse(value));
  1055. }
  1056. ).set_sparam());
  1057. add_opt(llama_arg(
  1058. {"--pooling"}, "{none,mean,cls,last}",
  1059. "pooling type for embeddings, use model default if unspecified",
  1060. [](gpt_params & params, const std::string & value) {
  1061. /**/ if (value == "none") { params.pooling_type = LLAMA_POOLING_TYPE_NONE; }
  1062. else if (value == "mean") { params.pooling_type = LLAMA_POOLING_TYPE_MEAN; }
  1063. else if (value == "cls") { params.pooling_type = LLAMA_POOLING_TYPE_CLS; }
  1064. else if (value == "last") { params.pooling_type = LLAMA_POOLING_TYPE_LAST; }
  1065. else { throw std::invalid_argument("invalid value"); }
  1066. }
  1067. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1068. add_opt(llama_arg(
  1069. {"--attention"}, "{causal,non,causal}",
  1070. "attention type for embeddings, use model default if unspecified",
  1071. [](gpt_params & params, const std::string & value) {
  1072. /**/ if (value == "causal") { params.attention_type = LLAMA_ATTENTION_TYPE_CAUSAL; }
  1073. else if (value == "non-causal") { params.attention_type = LLAMA_ATTENTION_TYPE_NON_CAUSAL; }
  1074. else { throw std::invalid_argument("invalid value"); }
  1075. }
  1076. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1077. add_opt(llama_arg(
  1078. {"--rope-scaling"}, "{none,linear,yarn}",
  1079. "RoPE frequency scaling method, defaults to linear unless specified by the model",
  1080. [](gpt_params & params, const std::string & value) {
  1081. /**/ if (value == "none") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_NONE; }
  1082. else if (value == "linear") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_LINEAR; }
  1083. else if (value == "yarn") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_YARN; }
  1084. else { throw std::invalid_argument("invalid value"); }
  1085. }
  1086. ));
  1087. add_opt(llama_arg(
  1088. {"--rope-scale"}, "N",
  1089. "RoPE context scaling factor, expands context by a factor of N",
  1090. [](gpt_params & params, const std::string & value) {
  1091. params.rope_freq_scale = 1.0f / std::stof(value);
  1092. }
  1093. ));
  1094. add_opt(llama_arg(
  1095. {"--rope-freq-base"}, "N",
  1096. "RoPE base frequency, used by NTK-aware scaling (default: loaded from model)",
  1097. [](gpt_params & params, const std::string & value) {
  1098. params.rope_freq_base = std::stof(value);
  1099. }
  1100. ));
  1101. add_opt(llama_arg(
  1102. {"--rope-freq-scale"}, "N",
  1103. "RoPE frequency scaling factor, expands context by a factor of 1/N",
  1104. [](gpt_params & params, const std::string & value) {
  1105. params.rope_freq_scale = std::stof(value);
  1106. }
  1107. ));
  1108. add_opt(llama_arg(
  1109. {"--yarn-orig-ctx"}, "N",
  1110. format("YaRN: original context size of model (default: %d = model training context size)", params.yarn_orig_ctx),
  1111. [](gpt_params & params, int value) {
  1112. params.yarn_orig_ctx = value;
  1113. }
  1114. ));
  1115. add_opt(llama_arg(
  1116. {"--yarn-ext-factor"}, "N",
  1117. format("YaRN: extrapolation mix factor (default: %.1f, 0.0 = full interpolation)", (double)params.yarn_ext_factor),
  1118. [](gpt_params & params, const std::string & value) {
  1119. params.yarn_ext_factor = std::stof(value);
  1120. }
  1121. ));
  1122. add_opt(llama_arg(
  1123. {"--yarn-attn-factor"}, "N",
  1124. format("YaRN: scale sqrt(t) or attention magnitude (default: %.1f)", (double)params.yarn_attn_factor),
  1125. [](gpt_params & params, const std::string & value) {
  1126. params.yarn_attn_factor = std::stof(value);
  1127. }
  1128. ));
  1129. add_opt(llama_arg(
  1130. {"--yarn-beta-slow"}, "N",
  1131. format("YaRN: high correction dim or alpha (default: %.1f)", (double)params.yarn_beta_slow),
  1132. [](gpt_params & params, const std::string & value) {
  1133. params.yarn_beta_slow = std::stof(value);
  1134. }
  1135. ));
  1136. add_opt(llama_arg(
  1137. {"--yarn-beta-fast"}, "N",
  1138. format("YaRN: low correction dim or beta (default: %.1f)", (double)params.yarn_beta_fast),
  1139. [](gpt_params & params, const std::string & value) {
  1140. params.yarn_beta_fast = std::stof(value);
  1141. }
  1142. ));
  1143. add_opt(llama_arg(
  1144. {"-gan", "--grp-attn-n"}, "N",
  1145. format("group-attention factor (default: %d)", params.grp_attn_n),
  1146. [](gpt_params & params, int value) {
  1147. params.grp_attn_n = value;
  1148. }
  1149. ));
  1150. add_opt(llama_arg(
  1151. {"-gaw", "--grp-attn-w"}, "N",
  1152. format("group-attention width (default: %.1f)", (double)params.grp_attn_w),
  1153. [](gpt_params & params, int value) {
  1154. params.grp_attn_w = value;
  1155. }
  1156. ));
  1157. add_opt(llama_arg(
  1158. {"-dkvc", "--dump-kv-cache"},
  1159. "verbose print of the KV cache",
  1160. [](gpt_params & params) {
  1161. params.dump_kv_cache = true;
  1162. }
  1163. ));
  1164. add_opt(llama_arg(
  1165. {"-nkvo", "--no-kv-offload"},
  1166. "disable KV offload",
  1167. [](gpt_params & params) {
  1168. params.no_kv_offload = true;
  1169. }
  1170. ));
  1171. add_opt(llama_arg(
  1172. {"-ctk", "--cache-type-k"}, "TYPE",
  1173. format("KV cache data type for K (default: %s)", params.cache_type_k.c_str()),
  1174. [](gpt_params & params, const std::string & value) {
  1175. // TODO: get the type right here
  1176. params.cache_type_k = value;
  1177. }
  1178. ));
  1179. add_opt(llama_arg(
  1180. {"-ctv", "--cache-type-v"}, "TYPE",
  1181. format("KV cache data type for V (default: %s)", params.cache_type_v.c_str()),
  1182. [](gpt_params & params, const std::string & value) {
  1183. // TODO: get the type right here
  1184. params.cache_type_v = value;
  1185. }
  1186. ));
  1187. add_opt(llama_arg(
  1188. {"--perplexity", "--all-logits"},
  1189. format("return logits for all tokens in the batch (default: %s)", params.logits_all ? "true" : "false"),
  1190. [](gpt_params & params) {
  1191. params.logits_all = true;
  1192. }
  1193. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1194. add_opt(llama_arg(
  1195. {"--hellaswag"},
  1196. "compute HellaSwag score over random tasks from datafile supplied with -f",
  1197. [](gpt_params & params) {
  1198. params.hellaswag = true;
  1199. }
  1200. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1201. add_opt(llama_arg(
  1202. {"--hellaswag-tasks"}, "N",
  1203. format("number of tasks to use when computing the HellaSwag score (default: %zu)", params.hellaswag_tasks),
  1204. [](gpt_params & params, int value) {
  1205. params.hellaswag_tasks = value;
  1206. }
  1207. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1208. add_opt(llama_arg(
  1209. {"--winogrande"},
  1210. "compute Winogrande score over random tasks from datafile supplied with -f",
  1211. [](gpt_params & params) {
  1212. params.winogrande = true;
  1213. }
  1214. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1215. add_opt(llama_arg(
  1216. {"--winogrande-tasks"}, "N",
  1217. format("number of tasks to use when computing the Winogrande score (default: %zu)", params.winogrande_tasks),
  1218. [](gpt_params & params, int value) {
  1219. params.winogrande_tasks = value;
  1220. }
  1221. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1222. add_opt(llama_arg(
  1223. {"--multiple-choice"},
  1224. "compute multiple choice score over random tasks from datafile supplied with -f",
  1225. [](gpt_params & params) {
  1226. params.multiple_choice = true;
  1227. }
  1228. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1229. add_opt(llama_arg(
  1230. {"--multiple-choice-tasks"}, "N",
  1231. format("number of tasks to use when computing the multiple choice score (default: %zu)", params.multiple_choice_tasks),
  1232. [](gpt_params & params, int value) {
  1233. params.multiple_choice_tasks = value;
  1234. }
  1235. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1236. add_opt(llama_arg(
  1237. {"--kl-divergence"},
  1238. "computes KL-divergence to logits provided via --kl-divergence-base",
  1239. [](gpt_params & params) {
  1240. params.kl_divergence = true;
  1241. }
  1242. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1243. add_opt(llama_arg(
  1244. {"--save-all-logits", "--kl-divergence-base"}, "FNAME",
  1245. "set logits file",
  1246. [](gpt_params & params, const std::string & value) {
  1247. params.logits_file = value;
  1248. }
  1249. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1250. add_opt(llama_arg(
  1251. {"--ppl-stride"}, "N",
  1252. format("stride for perplexity calculation (default: %d)", params.ppl_stride),
  1253. [](gpt_params & params, int value) {
  1254. params.ppl_stride = value;
  1255. }
  1256. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1257. add_opt(llama_arg(
  1258. {"--ppl-output-type"}, "<0|1>",
  1259. format("output type for perplexity calculation (default: %d)", params.ppl_output_type),
  1260. [](gpt_params & params, int value) {
  1261. params.ppl_output_type = value;
  1262. }
  1263. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1264. add_opt(llama_arg(
  1265. {"-dt", "--defrag-thold"}, "N",
  1266. format("KV cache defragmentation threshold (default: %.1f, < 0 - disabled)", (double)params.defrag_thold),
  1267. [](gpt_params & params, const std::string & value) {
  1268. params.defrag_thold = std::stof(value);
  1269. }
  1270. ).set_env("LLAMA_ARG_DEFRAG_THOLD"));
  1271. add_opt(llama_arg(
  1272. {"-np", "--parallel"}, "N",
  1273. format("number of parallel sequences to decode (default: %d)", params.n_parallel),
  1274. [](gpt_params & params, int value) {
  1275. params.n_parallel = value;
  1276. }
  1277. ));
  1278. add_opt(llama_arg(
  1279. {"-ns", "--sequences"}, "N",
  1280. format("number of sequences to decode (default: %d)", params.n_sequences),
  1281. [](gpt_params & params, int value) {
  1282. params.n_sequences = value;
  1283. }
  1284. ).set_examples({LLAMA_EXAMPLE_PARALLEL}));
  1285. add_opt(llama_arg(
  1286. {"-cb", "--cont-batching"},
  1287. format("enable continuous batching (a.k.a dynamic batching) (default: %s)", params.cont_batching ? "enabled" : "disabled"),
  1288. [](gpt_params & params) {
  1289. params.cont_batching = true;
  1290. }
  1291. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CONT_BATCHING"));
  1292. add_opt(llama_arg(
  1293. {"-nocb", "--no-cont-batching"},
  1294. "disable continuous batching",
  1295. [](gpt_params & params) {
  1296. params.cont_batching = false;
  1297. }
  1298. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_CONT_BATCHING"));
  1299. add_opt(llama_arg(
  1300. {"--mmproj"}, "FILE",
  1301. "path to a multimodal projector file for LLaVA. see examples/llava/README.md",
  1302. [](gpt_params & params, const std::string & value) {
  1303. params.mmproj = value;
  1304. }
  1305. ).set_examples({LLAMA_EXAMPLE_LLAVA}));
  1306. add_opt(llama_arg(
  1307. {"--image"}, "FILE",
  1308. "path to an image file. use with multimodal models. Specify multiple times for batching",
  1309. [](gpt_params & params, const std::string & value) {
  1310. params.image.emplace_back(value);
  1311. }
  1312. ).set_examples({LLAMA_EXAMPLE_LLAVA}));
  1313. #ifdef GGML_USE_RPC
  1314. add_opt(llama_arg(
  1315. {"--rpc"}, "SERVERS",
  1316. "comma separated list of RPC servers",
  1317. [](gpt_params & params, const std::string & value) {
  1318. params.rpc_servers = value;
  1319. }
  1320. ));
  1321. #endif
  1322. add_opt(llama_arg(
  1323. {"--mlock"},
  1324. "force system to keep model in RAM rather than swapping or compressing",
  1325. [](gpt_params & params) {
  1326. params.use_mlock = true;
  1327. }
  1328. ));
  1329. add_opt(llama_arg(
  1330. {"--no-mmap"},
  1331. "do not memory-map model (slower load but may reduce pageouts if not using mlock)",
  1332. [](gpt_params & params) {
  1333. params.use_mmap = false;
  1334. }
  1335. ));
  1336. add_opt(llama_arg(
  1337. {"--numa"}, "TYPE",
  1338. "attempt optimizations that help on some NUMA systems\n"
  1339. "- distribute: spread execution evenly over all nodes\n"
  1340. "- isolate: only spawn threads on CPUs on the node that execution started on\n"
  1341. "- numactl: use the CPU map provided by numactl\n"
  1342. "if run without this previously, it is recommended to drop the system page cache before using this\n"
  1343. "see https://github.com/ggerganov/llama.cpp/issues/1437",
  1344. [](gpt_params & params, const std::string & value) {
  1345. /**/ if (value == "distribute" || value == "") { params.numa = GGML_NUMA_STRATEGY_DISTRIBUTE; }
  1346. else if (value == "isolate") { params.numa = GGML_NUMA_STRATEGY_ISOLATE; }
  1347. else if (value == "numactl") { params.numa = GGML_NUMA_STRATEGY_NUMACTL; }
  1348. else { throw std::invalid_argument("invalid value"); }
  1349. }
  1350. ));
  1351. add_opt(llama_arg(
  1352. {"-ngl", "--gpu-layers", "--n-gpu-layers"}, "N",
  1353. "number of layers to store in VRAM",
  1354. [](gpt_params & params, int value) {
  1355. params.n_gpu_layers = value;
  1356. if (!llama_supports_gpu_offload()) {
  1357. fprintf(stderr, "warning: not compiled with GPU offload support, --gpu-layers option will be ignored\n");
  1358. fprintf(stderr, "warning: see main README.md for information on enabling GPU BLAS support\n");
  1359. }
  1360. }
  1361. ).set_env("LLAMA_ARG_N_GPU_LAYERS"));
  1362. add_opt(llama_arg(
  1363. {"-ngld", "--gpu-layers-draft", "--n-gpu-layers-draft"}, "N",
  1364. "number of layers to store in VRAM for the draft model",
  1365. [](gpt_params & params, int value) {
  1366. params.n_gpu_layers_draft = value;
  1367. if (!llama_supports_gpu_offload()) {
  1368. fprintf(stderr, "warning: not compiled with GPU offload support, --gpu-layers-draft option will be ignored\n");
  1369. fprintf(stderr, "warning: see main README.md for information on enabling GPU BLAS support\n");
  1370. }
  1371. }
  1372. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  1373. add_opt(llama_arg(
  1374. {"-sm", "--split-mode"}, "{none,layer,row}",
  1375. "how to split the model across multiple GPUs, one of:\n"
  1376. "- none: use one GPU only\n"
  1377. "- layer (default): split layers and KV across GPUs\n"
  1378. "- row: split rows across GPUs",
  1379. [](gpt_params & params, const std::string & value) {
  1380. std::string arg_next = value;
  1381. if (arg_next == "none") {
  1382. params.split_mode = LLAMA_SPLIT_MODE_NONE;
  1383. } else if (arg_next == "layer") {
  1384. params.split_mode = LLAMA_SPLIT_MODE_LAYER;
  1385. } else if (arg_next == "row") {
  1386. #ifdef GGML_USE_SYCL
  1387. fprintf(stderr, "warning: The split mode value:[row] is not supported by llama.cpp with SYCL. It's developing.\nExit!\n");
  1388. exit(1);
  1389. #endif // GGML_USE_SYCL
  1390. params.split_mode = LLAMA_SPLIT_MODE_ROW;
  1391. } else {
  1392. throw std::invalid_argument("invalid value");
  1393. }
  1394. if (!llama_supports_gpu_offload()) {
  1395. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the split mode has no effect.\n");
  1396. }
  1397. }
  1398. ));
  1399. add_opt(llama_arg(
  1400. {"-ts", "--tensor-split"}, "N0,N1,N2,...",
  1401. "fraction of the model to offload to each GPU, comma-separated list of proportions, e.g. 3,1",
  1402. [](gpt_params & params, const std::string & value) {
  1403. std::string arg_next = value;
  1404. // split string by , and /
  1405. const std::regex regex{ R"([,/]+)" };
  1406. std::sregex_token_iterator it{ arg_next.begin(), arg_next.end(), regex, -1 };
  1407. std::vector<std::string> split_arg{ it, {} };
  1408. if (split_arg.size() >= llama_max_devices()) {
  1409. throw std::invalid_argument(
  1410. format("got %d input configs, but system only has %d devices", (int)split_arg.size(), (int)llama_max_devices())
  1411. );
  1412. }
  1413. for (size_t i = 0; i < llama_max_devices(); ++i) {
  1414. if (i < split_arg.size()) {
  1415. params.tensor_split[i] = std::stof(split_arg[i]);
  1416. } else {
  1417. params.tensor_split[i] = 0.0f;
  1418. }
  1419. }
  1420. if (!llama_supports_gpu_offload()) {
  1421. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting a tensor split has no effect.\n");
  1422. }
  1423. }
  1424. ));
  1425. add_opt(llama_arg(
  1426. {"-mg", "--main-gpu"}, "INDEX",
  1427. format("the GPU to use for the model (with split-mode = none), or for intermediate results and KV (with split-mode = row) (default: %d)", params.main_gpu),
  1428. [](gpt_params & params, int value) {
  1429. params.main_gpu = value;
  1430. if (!llama_supports_gpu_offload()) {
  1431. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the main GPU has no effect.\n");
  1432. }
  1433. }
  1434. ));
  1435. add_opt(llama_arg(
  1436. {"--check-tensors"},
  1437. format("check model tensor data for invalid values (default: %s)", params.check_tensors ? "true" : "false"),
  1438. [](gpt_params & params) {
  1439. params.check_tensors = true;
  1440. }
  1441. ));
  1442. add_opt(llama_arg(
  1443. {"--override-kv"}, "KEY=TYPE:VALUE",
  1444. "advanced option to override model metadata by key. may be specified multiple times.\n"
  1445. "types: int, float, bool, str. example: --override-kv tokenizer.ggml.add_bos_token=bool:false",
  1446. [](gpt_params & params, const std::string & value) {
  1447. if (!string_parse_kv_override(value.c_str(), params.kv_overrides)) {
  1448. throw std::runtime_error(format("error: Invalid type for KV override: %s\n", value.c_str()));
  1449. }
  1450. }
  1451. ));
  1452. add_opt(llama_arg(
  1453. {"--lora"}, "FNAME",
  1454. "path to LoRA adapter (can be repeated to use multiple adapters)",
  1455. [](gpt_params & params, const std::string & value) {
  1456. params.lora_adapters.push_back({ std::string(value), 1.0 });
  1457. }
  1458. // we define this arg on both COMMON and EXPORT_LORA, so when showing help message of export-lora, it will be categorized as "example-specific" arg
  1459. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
  1460. add_opt(llama_arg(
  1461. {"--lora-scaled"}, "FNAME", "SCALE",
  1462. "path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
  1463. [](gpt_params & params, const std::string & fname, const std::string & scale) {
  1464. params.lora_adapters.push_back({ fname, std::stof(scale) });
  1465. }
  1466. // we define this arg on both COMMON and EXPORT_LORA, so when showing help message of export-lora, it will be categorized as "example-specific" arg
  1467. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
  1468. add_opt(llama_arg(
  1469. {"--control-vector"}, "FNAME",
  1470. "add a control vector\nnote: this argument can be repeated to add multiple control vectors",
  1471. [](gpt_params & params, const std::string & value) {
  1472. params.control_vectors.push_back({ 1.0f, value, });
  1473. }
  1474. ));
  1475. add_opt(llama_arg(
  1476. {"--control-vector-scaled"}, "FNAME", "SCALE",
  1477. "add a control vector with user defined scaling SCALE\n"
  1478. "note: this argument can be repeated to add multiple scaled control vectors",
  1479. [](gpt_params & params, const std::string & fname, const std::string & scale) {
  1480. params.control_vectors.push_back({ std::stof(scale), fname });
  1481. }
  1482. ));
  1483. add_opt(llama_arg(
  1484. {"--control-vector-layer-range"}, "START", "END",
  1485. "layer range to apply the control vector(s) to, start and end inclusive",
  1486. [](gpt_params & params, const std::string & start, const std::string & end) {
  1487. params.control_vector_layer_start = std::stoi(start);
  1488. params.control_vector_layer_end = std::stoi(end);
  1489. }
  1490. ));
  1491. add_opt(llama_arg(
  1492. {"-a", "--alias"}, "STRING",
  1493. "set alias for model name (to be used by REST API)",
  1494. [](gpt_params & params, const std::string & value) {
  1495. params.model_alias = value;
  1496. }
  1497. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1498. add_opt(llama_arg(
  1499. {"-m", "--model"}, "FNAME",
  1500. ex == LLAMA_EXAMPLE_EXPORT_LORA
  1501. ? std::string("model path from which to load base model")
  1502. : format(
  1503. "model path (default: `models/$filename` with filename from `--hf-file` "
  1504. "or `--model-url` if set, otherwise %s)", DEFAULT_MODEL_PATH
  1505. ),
  1506. [](gpt_params & params, const std::string & value) {
  1507. params.model = value;
  1508. }
  1509. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}).set_env("LLAMA_ARG_MODEL"));
  1510. add_opt(llama_arg(
  1511. {"-md", "--model-draft"}, "FNAME",
  1512. "draft model for speculative decoding (default: unused)",
  1513. [](gpt_params & params, const std::string & value) {
  1514. params.model_draft = value;
  1515. }
  1516. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  1517. add_opt(llama_arg(
  1518. {"-mu", "--model-url"}, "MODEL_URL",
  1519. "model download url (default: unused)",
  1520. [](gpt_params & params, const std::string & value) {
  1521. params.model_url = value;
  1522. }
  1523. ).set_env("LLAMA_ARG_MODEL_URL"));
  1524. add_opt(llama_arg(
  1525. {"-hfr", "--hf-repo"}, "REPO",
  1526. "Hugging Face model repository (default: unused)",
  1527. [](gpt_params & params, const std::string & value) {
  1528. params.hf_repo = value;
  1529. }
  1530. ).set_env("LLAMA_ARG_HF_REPO"));
  1531. add_opt(llama_arg(
  1532. {"-hff", "--hf-file"}, "FILE",
  1533. "Hugging Face model file (default: unused)",
  1534. [](gpt_params & params, const std::string & value) {
  1535. params.hf_file = value;
  1536. }
  1537. ).set_env("LLAMA_ARG_HF_FILE"));
  1538. add_opt(llama_arg(
  1539. {"-hft", "--hf-token"}, "TOKEN",
  1540. "Hugging Face access token (default: value from HF_TOKEN environment variable)",
  1541. [](gpt_params & params, const std::string & value) {
  1542. params.hf_token = value;
  1543. }
  1544. ).set_env("HF_TOKEN"));
  1545. add_opt(llama_arg(
  1546. {"--context-file"}, "FNAME",
  1547. "file to load context from (repeat to specify multiple files)",
  1548. [](gpt_params & params, const std::string & value) {
  1549. std::ifstream file(value, std::ios::binary);
  1550. if (!file) {
  1551. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  1552. }
  1553. params.context_files.push_back(value);
  1554. }
  1555. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  1556. add_opt(llama_arg(
  1557. {"--chunk-size"}, "N",
  1558. format("minimum length of embedded text chunks (default: %d)", params.chunk_size),
  1559. [](gpt_params & params, int value) {
  1560. params.chunk_size = value;
  1561. }
  1562. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  1563. add_opt(llama_arg(
  1564. {"--chunk-separator"}, "STRING",
  1565. format("separator between chunks (default: '%s')", params.chunk_separator.c_str()),
  1566. [](gpt_params & params, const std::string & value) {
  1567. params.chunk_separator = value;
  1568. }
  1569. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  1570. add_opt(llama_arg(
  1571. {"--junk"}, "N",
  1572. format("number of times to repeat the junk text (default: %d)", params.n_junk),
  1573. [](gpt_params & params, int value) {
  1574. params.n_junk = value;
  1575. }
  1576. ).set_examples({LLAMA_EXAMPLE_PASSKEY}));
  1577. add_opt(llama_arg(
  1578. {"--pos"}, "N",
  1579. format("position of the passkey in the junk text (default: %d)", params.i_pos),
  1580. [](gpt_params & params, int value) {
  1581. params.i_pos = value;
  1582. }
  1583. ).set_examples({LLAMA_EXAMPLE_PASSKEY}));
  1584. add_opt(llama_arg(
  1585. {"-o", "--output", "--output-file"}, "FNAME",
  1586. format("output file (default: '%s')",
  1587. ex == LLAMA_EXAMPLE_EXPORT_LORA
  1588. ? params.lora_outfile.c_str()
  1589. : ex == LLAMA_EXAMPLE_CVECTOR_GENERATOR
  1590. ? params.cvector_outfile.c_str()
  1591. : params.out_file.c_str()),
  1592. [](gpt_params & params, const std::string & value) {
  1593. params.out_file = value;
  1594. params.cvector_outfile = value;
  1595. params.lora_outfile = value;
  1596. }
  1597. ).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA}));
  1598. add_opt(llama_arg(
  1599. {"-ofreq", "--output-frequency"}, "N",
  1600. format("output the imatrix every N iterations (default: %d)", params.n_out_freq),
  1601. [](gpt_params & params, int value) {
  1602. params.n_out_freq = value;
  1603. }
  1604. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1605. add_opt(llama_arg(
  1606. {"--save-frequency"}, "N",
  1607. format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),
  1608. [](gpt_params & params, int value) {
  1609. params.n_save_freq = value;
  1610. }
  1611. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1612. add_opt(llama_arg(
  1613. {"--process-output"},
  1614. format("collect data for the output tensor (default: %s)", params.process_output ? "true" : "false"),
  1615. [](gpt_params & params) {
  1616. params.process_output = true;
  1617. }
  1618. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1619. add_opt(llama_arg(
  1620. {"--no-ppl"},
  1621. format("do not compute perplexity (default: %s)", params.compute_ppl ? "true" : "false"),
  1622. [](gpt_params & params) {
  1623. params.compute_ppl = false;
  1624. }
  1625. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1626. add_opt(llama_arg(
  1627. {"--chunk", "--from-chunk"}, "N",
  1628. format("start processing the input from chunk N (default: %d)", params.i_chunk),
  1629. [](gpt_params & params, int value) {
  1630. params.i_chunk = value;
  1631. }
  1632. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1633. add_opt(llama_arg(
  1634. {"-pps"},
  1635. format("is the prompt shared across parallel sequences (default: %s)", params.is_pp_shared ? "true" : "false"),
  1636. [](gpt_params & params) {
  1637. params.is_pp_shared = true;
  1638. }
  1639. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1640. add_opt(llama_arg(
  1641. {"-npp"}, "n0,n1,...",
  1642. "number of prompt tokens",
  1643. [](gpt_params & params, const std::string & value) {
  1644. auto p = string_split<int>(value, ',');
  1645. params.n_pp.insert(params.n_pp.end(), p.begin(), p.end());
  1646. }
  1647. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1648. add_opt(llama_arg(
  1649. {"-ntg"}, "n0,n1,...",
  1650. "number of text generation tokens",
  1651. [](gpt_params & params, const std::string & value) {
  1652. auto p = string_split<int>(value, ',');
  1653. params.n_tg.insert(params.n_tg.end(), p.begin(), p.end());
  1654. }
  1655. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1656. add_opt(llama_arg(
  1657. {"-npl"}, "n0,n1,...",
  1658. "number of parallel prompts",
  1659. [](gpt_params & params, const std::string & value) {
  1660. auto p = string_split<int>(value, ',');
  1661. params.n_pl.insert(params.n_pl.end(), p.begin(), p.end());
  1662. }
  1663. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1664. add_opt(llama_arg(
  1665. {"--embd-normalize"}, "N",
  1666. format("normalisation for embendings (default: %d) (-1=none, 0=max absolute int16, 1=taxicab, 2=euclidean, >2=p-norm)", params.embd_normalize),
  1667. [](gpt_params & params, int value) {
  1668. params.embd_normalize = value;
  1669. }
  1670. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1671. add_opt(llama_arg(
  1672. {"--embd-output-format"}, "FORMAT",
  1673. "empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix",
  1674. [](gpt_params & params, const std::string & value) {
  1675. params.embd_out = value;
  1676. }
  1677. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1678. add_opt(llama_arg(
  1679. {"--embd-separator"}, "STRING",
  1680. "separator of embendings (default \\n) for example \"<#sep#>\"",
  1681. [](gpt_params & params, const std::string & value) {
  1682. params.embd_sep = value;
  1683. }
  1684. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1685. add_opt(llama_arg(
  1686. {"--host"}, "HOST",
  1687. format("ip address to listen (default: %s)", params.hostname.c_str()),
  1688. [](gpt_params & params, const std::string & value) {
  1689. params.hostname = value;
  1690. }
  1691. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_HOST"));
  1692. add_opt(llama_arg(
  1693. {"--port"}, "PORT",
  1694. format("port to listen (default: %d)", params.port),
  1695. [](gpt_params & params, int value) {
  1696. params.port = value;
  1697. }
  1698. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_PORT"));
  1699. add_opt(llama_arg(
  1700. {"--path"}, "PATH",
  1701. format("path to serve static files from (default: %s)", params.public_path.c_str()),
  1702. [](gpt_params & params, const std::string & value) {
  1703. params.public_path = value;
  1704. }
  1705. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1706. add_opt(llama_arg(
  1707. {"--embedding", "--embeddings"},
  1708. format("restrict to only support embedding use case; use only with dedicated embedding models (default: %s)", params.embedding ? "enabled" : "disabled"),
  1709. [](gpt_params & params) {
  1710. params.embedding = true;
  1711. }
  1712. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_EMBEDDINGS"));
  1713. add_opt(llama_arg(
  1714. {"--api-key"}, "KEY",
  1715. "API key to use for authentication (default: none)",
  1716. [](gpt_params & params, const std::string & value) {
  1717. params.api_keys.push_back(value);
  1718. }
  1719. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_API_KEY"));
  1720. add_opt(llama_arg(
  1721. {"--api-key-file"}, "FNAME",
  1722. "path to file containing API keys (default: none)",
  1723. [](gpt_params & params, const std::string & value) {
  1724. std::ifstream key_file(value);
  1725. if (!key_file) {
  1726. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  1727. }
  1728. std::string key;
  1729. while (std::getline(key_file, key)) {
  1730. if (!key.empty()) {
  1731. params.api_keys.push_back(key);
  1732. }
  1733. }
  1734. key_file.close();
  1735. }
  1736. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1737. add_opt(llama_arg(
  1738. {"--ssl-key-file"}, "FNAME",
  1739. "path to file a PEM-encoded SSL private key",
  1740. [](gpt_params & params, const std::string & value) {
  1741. params.ssl_file_key = value;
  1742. }
  1743. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1744. add_opt(llama_arg(
  1745. {"--ssl-cert-file"}, "FNAME",
  1746. "path to file a PEM-encoded SSL certificate",
  1747. [](gpt_params & params, const std::string & value) {
  1748. params.ssl_file_cert = value;
  1749. }
  1750. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1751. add_opt(llama_arg(
  1752. {"-to", "--timeout"}, "N",
  1753. format("server read/write timeout in seconds (default: %d)", params.timeout_read),
  1754. [](gpt_params & params, int value) {
  1755. params.timeout_read = value;
  1756. params.timeout_write = value;
  1757. }
  1758. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1759. add_opt(llama_arg(
  1760. {"--threads-http"}, "N",
  1761. format("number of threads used to process HTTP requests (default: %d)", params.n_threads_http),
  1762. [](gpt_params & params, int value) {
  1763. params.n_threads_http = value;
  1764. }
  1765. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_THREADS_HTTP"));
  1766. add_opt(llama_arg(
  1767. {"-spf", "--system-prompt-file"}, "FNAME",
  1768. "set a file to load a system prompt (initial prompt of all slots), this is useful for chat applications",
  1769. [](gpt_params & params, const std::string & value) {
  1770. std::ifstream file(value);
  1771. if (!file) {
  1772. throw std::runtime_error(format("error: failed to open file '%s'\n", value.c_str()));
  1773. }
  1774. std::string system_prompt;
  1775. std::copy(
  1776. std::istreambuf_iterator<char>(file),
  1777. std::istreambuf_iterator<char>(),
  1778. std::back_inserter(system_prompt)
  1779. );
  1780. params.system_prompt = system_prompt;
  1781. }
  1782. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1783. add_opt(llama_arg(
  1784. {"--log-format"}, "{text, json}",
  1785. "log output format: json or text (default: json)",
  1786. [](gpt_params & params, const std::string & value) {
  1787. if (value == "json") {
  1788. params.log_json = true;
  1789. } else if (value == "text") {
  1790. params.log_json = false;
  1791. } else {
  1792. throw std::invalid_argument("invalid value");
  1793. }
  1794. }
  1795. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1796. add_opt(llama_arg(
  1797. {"--metrics"},
  1798. format("enable prometheus compatible metrics endpoint (default: %s)", params.endpoint_metrics ? "enabled" : "disabled"),
  1799. [](gpt_params & params) {
  1800. params.endpoint_metrics = true;
  1801. }
  1802. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_METRICS"));
  1803. add_opt(llama_arg(
  1804. {"--no-slots"},
  1805. format("disables slots monitoring endpoint (default: %s)", params.endpoint_slots ? "enabled" : "disabled"),
  1806. [](gpt_params & params) {
  1807. params.endpoint_slots = false;
  1808. }
  1809. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_ENDPOINT_SLOTS"));
  1810. add_opt(llama_arg(
  1811. {"--slot-save-path"}, "PATH",
  1812. "path to save slot kv cache (default: disabled)",
  1813. [](gpt_params & params, const std::string & value) {
  1814. params.slot_save_path = value;
  1815. // if doesn't end with DIRECTORY_SEPARATOR, add it
  1816. if (!params.slot_save_path.empty() && params.slot_save_path[params.slot_save_path.size() - 1] != DIRECTORY_SEPARATOR) {
  1817. params.slot_save_path += DIRECTORY_SEPARATOR;
  1818. }
  1819. }
  1820. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1821. add_opt(llama_arg(
  1822. {"--chat-template"}, "JINJA_TEMPLATE",
  1823. "set custom jinja chat template (default: template taken from model's metadata)\n"
  1824. "if suffix/prefix are specified, template will be disabled\n"
  1825. "only commonly used templates are accepted:\nhttps://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template",
  1826. [](gpt_params & params, const std::string & value) {
  1827. if (!llama_chat_verify_template(value)) {
  1828. throw std::runtime_error(format(
  1829. "error: the supplied chat template is not supported: %s\n"
  1830. "note: llama.cpp does not use jinja parser, we only support commonly used templates\n",
  1831. value.c_str()
  1832. ));
  1833. }
  1834. params.chat_template = value;
  1835. }
  1836. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
  1837. add_opt(llama_arg(
  1838. {"-sps", "--slot-prompt-similarity"}, "SIMILARITY",
  1839. format("how much the prompt of a request must match the prompt of a slot in order to use that slot (default: %.2f, 0.0 = disabled)\n", params.slot_prompt_similarity),
  1840. [](gpt_params & params, const std::string & value) {
  1841. params.slot_prompt_similarity = std::stof(value);
  1842. }
  1843. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1844. add_opt(llama_arg(
  1845. {"--lora-init-without-apply"},
  1846. format("load LoRA adapters without applying them (apply later via POST /lora-adapters) (default: %s)", params.lora_init_without_apply ? "enabled" : "disabled"),
  1847. [](gpt_params & params) {
  1848. params.lora_init_without_apply = true;
  1849. }
  1850. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1851. add_opt(llama_arg(
  1852. {"--simple-io"},
  1853. "use basic IO for better compatibility in subprocesses and limited consoles",
  1854. [](gpt_params & params) {
  1855. params.simple_io = true;
  1856. }
  1857. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
  1858. add_opt(llama_arg(
  1859. {"-ld", "--logdir"}, "LOGDIR",
  1860. "path under which to save YAML logs (no logging if unset)",
  1861. [](gpt_params & params, const std::string & value) {
  1862. params.logdir = value;
  1863. if (params.logdir.back() != DIRECTORY_SEPARATOR) {
  1864. params.logdir += DIRECTORY_SEPARATOR;
  1865. }
  1866. }
  1867. ));
  1868. add_opt(llama_arg(
  1869. {"--positive-file"}, "FNAME",
  1870. format("positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str()),
  1871. [](gpt_params & params, const std::string & value) {
  1872. params.cvector_positive_file = value;
  1873. }
  1874. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1875. add_opt(llama_arg(
  1876. {"--negative-file"}, "FNAME",
  1877. format("negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str()),
  1878. [](gpt_params & params, const std::string & value) {
  1879. params.cvector_negative_file = value;
  1880. }
  1881. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1882. add_opt(llama_arg(
  1883. {"--pca-batch"}, "N",
  1884. format("batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch),
  1885. [](gpt_params & params, int value) {
  1886. params.n_pca_batch = value;
  1887. }
  1888. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1889. add_opt(llama_arg(
  1890. {"--pca-iter"}, "N",
  1891. format("number of iterations used for PCA (default: %d)", params.n_pca_iterations),
  1892. [](gpt_params & params, int value) {
  1893. params.n_pca_iterations = value;
  1894. }
  1895. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1896. add_opt(llama_arg(
  1897. {"--method"}, "{pca, mean}",
  1898. "dimensionality reduction method to be used (default: pca)",
  1899. [](gpt_params & params, const std::string & value) {
  1900. /**/ if (value == "pca") { params.cvector_dimre_method = DIMRE_METHOD_PCA; }
  1901. else if (value == "mean") { params.cvector_dimre_method = DIMRE_METHOD_MEAN; }
  1902. else { throw std::invalid_argument("invalid value"); }
  1903. }
  1904. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1905. add_opt(llama_arg(
  1906. {"--output-format"}, "{md,jsonl}",
  1907. "output format for batched-bench results (default: md)",
  1908. [](gpt_params & params, const std::string & value) {
  1909. /**/ if (value == "jsonl") { params.batched_bench_output_jsonl = true; }
  1910. else if (value == "md") { params.batched_bench_output_jsonl = false; }
  1911. else { std::invalid_argument("invalid value"); }
  1912. }
  1913. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1914. #ifndef LOG_DISABLE_LOGS
  1915. // TODO: make this looks less weird
  1916. add_opt(llama_arg(
  1917. {"--log-test"},
  1918. "Log test",
  1919. [](gpt_params &) { log_param_single_parse("--log-test"); }
  1920. ));
  1921. add_opt(llama_arg(
  1922. {"--log-disable"},
  1923. "Log disable",
  1924. [](gpt_params &) { log_param_single_parse("--log-disable"); }
  1925. ));
  1926. add_opt(llama_arg(
  1927. {"--log-enable"},
  1928. "Log enable",
  1929. [](gpt_params &) { log_param_single_parse("--log-enable"); }
  1930. ));
  1931. add_opt(llama_arg(
  1932. {"--log-new"},
  1933. "Log new",
  1934. [](gpt_params &) { log_param_single_parse("--log-new"); }
  1935. ));
  1936. add_opt(llama_arg(
  1937. {"--log-append"},
  1938. "Log append",
  1939. [](gpt_params &) { log_param_single_parse("--log-append"); }
  1940. ));
  1941. add_opt(llama_arg(
  1942. {"--log-file"}, "FNAME",
  1943. "Log file",
  1944. [](gpt_params &, const std::string & value) { log_param_pair_parse(false, "--log-file", value); }
  1945. ));
  1946. #endif // LOG_DISABLE_LOGS
  1947. return ctx_arg;
  1948. }