1
0

arg.cpp 85 KB

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