1
0

arg.cpp 83 KB

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