arg.cpp 82 KB

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