arg.cpp 81 KB

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