arg.cpp 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  1. #include "arg.h"
  2. #include "log.h"
  3. #include "sampling.h"
  4. #include <algorithm>
  5. #include <climits>
  6. #include <cstdarg>
  7. #include <fstream>
  8. #include <regex>
  9. #include <set>
  10. #include <string>
  11. #include <thread>
  12. #include <vector>
  13. #include "json-schema-to-grammar.h"
  14. using json = nlohmann::ordered_json;
  15. common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
  16. this->examples = std::move(examples);
  17. return *this;
  18. }
  19. common_arg & common_arg::set_env(const char * env) {
  20. help = help + "\n(env: " + env + ")";
  21. this->env = env;
  22. return *this;
  23. }
  24. common_arg & common_arg::set_sparam() {
  25. is_sparam = true;
  26. return *this;
  27. }
  28. bool common_arg::in_example(enum llama_example ex) {
  29. return examples.find(ex) != examples.end();
  30. }
  31. bool common_arg::get_value_from_env(std::string & output) {
  32. if (env == nullptr) return false;
  33. char * value = std::getenv(env);
  34. if (value) {
  35. output = value;
  36. return true;
  37. }
  38. return false;
  39. }
  40. bool common_arg::has_value_from_env() {
  41. return env != nullptr && std::getenv(env);
  42. }
  43. static std::vector<std::string> break_str_into_lines(std::string input, size_t max_char_per_line) {
  44. std::vector<std::string> result;
  45. std::istringstream iss(input);
  46. std::string line;
  47. auto add_line = [&](const std::string& l) {
  48. if (l.length() <= max_char_per_line) {
  49. result.push_back(l);
  50. } else {
  51. std::istringstream line_stream(l);
  52. std::string word, current_line;
  53. while (line_stream >> word) {
  54. if (current_line.length() + !current_line.empty() + word.length() > max_char_per_line) {
  55. if (!current_line.empty()) result.push_back(current_line);
  56. current_line = word;
  57. } else {
  58. current_line += (!current_line.empty() ? " " : "") + word;
  59. }
  60. }
  61. if (!current_line.empty()) result.push_back(current_line);
  62. }
  63. };
  64. while (std::getline(iss, line)) {
  65. add_line(line);
  66. }
  67. return result;
  68. }
  69. std::string common_arg::to_string() {
  70. // params for printing to console
  71. const static int n_leading_spaces = 40;
  72. const static int n_char_per_line_help = 70; // TODO: detect this based on current console
  73. std::string leading_spaces(n_leading_spaces, ' ');
  74. std::ostringstream ss;
  75. for (const auto arg : args) {
  76. if (arg == args.front()) {
  77. if (args.size() == 1) {
  78. ss << arg;
  79. } else {
  80. // first arg is usually abbreviation, we need padding to make it more beautiful
  81. auto tmp = std::string(arg) + ", ";
  82. auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
  83. ss << tmp << spaces;
  84. }
  85. } else {
  86. ss << arg << (arg != args.back() ? ", " : "");
  87. }
  88. }
  89. if (value_hint) ss << " " << value_hint;
  90. if (value_hint_2) ss << " " << value_hint_2;
  91. if (ss.tellp() > n_leading_spaces - 3) {
  92. // current line is too long, add new line
  93. ss << "\n" << leading_spaces;
  94. } else {
  95. // padding between arg and help, same line
  96. ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
  97. }
  98. const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
  99. for (const auto & line : help_lines) {
  100. ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
  101. }
  102. return ss.str();
  103. }
  104. //
  105. // utils
  106. //
  107. #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 common_params_handle_model_default(common_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 common_params_parse_ex(int argc, char ** argv, common_params_context & ctx_arg) {
  156. std::string arg;
  157. const std::string arg_prefix = "--";
  158. common_params & params = ctx_arg.params;
  159. std::unordered_map<std::string, common_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. common_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 common_params_print_usage(common_params_context & ctx_arg) {
  261. auto print_options = [](std::vector<common_arg *> & options) {
  262. for (common_arg * opt : options) {
  263. printf("%s", opt->to_string().c_str());
  264. }
  265. };
  266. std::vector<common_arg *> common_options;
  267. std::vector<common_arg *> sparam_options;
  268. std::vector<common_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 common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  288. auto ctx_arg = common_params_parser_init(params, ex, print_usage);
  289. const common_params params_org = ctx_arg.params; // the example can modify the default params
  290. try {
  291. if (!common_params_parse_ex(argc, argv, ctx_arg)) {
  292. ctx_arg.params = params_org;
  293. return false;
  294. }
  295. if (ctx_arg.params.usage) {
  296. common_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. common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  310. common_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 += common_sampler_type_to_chr(sampler);
  317. sampler_type_names += common_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 = [&](common_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(common_arg(
  333. {"-h", "--help", "--usage"},
  334. "print usage and exit",
  335. [](common_params & params) {
  336. params.usage = true;
  337. }
  338. ));
  339. add_opt(common_arg(
  340. {"--version"},
  341. "show version and build info",
  342. [](common_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(common_arg(
  349. {"--verbose-prompt"},
  350. format("print a verbose prompt before generation (default: %s)", params.verbose_prompt ? "true" : "false"),
  351. [](common_params & params) {
  352. params.verbose_prompt = true;
  353. }
  354. ));
  355. add_opt(common_arg(
  356. {"--no-display-prompt"},
  357. format("don't print prompt at generation (default: %s)", !params.display_prompt ? "true" : "false"),
  358. [](common_params & params) {
  359. params.display_prompt = false;
  360. }
  361. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  362. add_opt(common_arg(
  363. {"-co", "--color"},
  364. format("colorise output to distinguish prompt and user input from generations (default: %s)", params.use_color ? "true" : "false"),
  365. [](common_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(common_arg(
  370. {"-t", "--threads"}, "N",
  371. format("number of threads to use during generation (default: %d)", params.cpuparams.n_threads),
  372. [](common_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(common_arg(
  380. {"-tb", "--threads-batch"}, "N",
  381. "number of threads to use during batch and prompt processing (default: same as --threads)",
  382. [](common_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(common_arg(
  390. {"-td", "--threads-draft"}, "N",
  391. "number of threads to use during generation (default: same as --threads)",
  392. [](common_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(common_arg(
  400. {"-tbd", "--threads-batch-draft"}, "N",
  401. "number of threads to use during batch and prompt processing (default: same as --threads-draft)",
  402. [](common_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(common_arg(
  410. {"-C", "--cpu-mask"}, "M",
  411. "CPU affinity mask: arbitrarily long hex. Complements cpu-range (default: \"\")",
  412. [](common_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(common_arg(
  420. {"-Cr", "--cpu-range"}, "lo-hi",
  421. "range of CPUs for affinity. Complements --cpu-mask",
  422. [](common_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(common_arg(
  430. {"--cpu-strict"}, "<0|1>",
  431. format("use strict CPU placement (default: %u)\n", (unsigned) params.cpuparams.strict_cpu),
  432. [](common_params & params, const std::string & value) {
  433. params.cpuparams.strict_cpu = std::stoul(value);
  434. }
  435. ));
  436. add_opt(common_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. [](common_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(common_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. [](common_params & params, const std::string & value) {
  450. params.cpuparams.poll = std::stoul(value);
  451. }
  452. ));
  453. add_opt(common_arg(
  454. {"-Cb", "--cpu-mask-batch"}, "M",
  455. "CPU affinity mask: arbitrarily long hex. Complements cpu-range-batch (default: same as --cpu-mask)",
  456. [](common_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(common_arg(
  464. {"-Crb", "--cpu-range-batch"}, "lo-hi",
  465. "ranges of CPUs for affinity. Complements --cpu-mask-batch",
  466. [](common_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(common_arg(
  474. {"--cpu-strict-batch"}, "<0|1>",
  475. "use strict CPU placement (default: same as --cpu-strict)",
  476. [](common_params & params, int value) {
  477. params.cpuparams_batch.strict_cpu = value;
  478. }
  479. ));
  480. add_opt(common_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. [](common_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(common_arg(
  491. {"--poll-batch"}, "<0|1>",
  492. "use polling to wait for work (default: same as --poll)",
  493. [](common_params & params, int value) {
  494. params.cpuparams_batch.poll = value;
  495. }
  496. ));
  497. add_opt(common_arg(
  498. {"-Cd", "--cpu-mask-draft"}, "M",
  499. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  500. [](common_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(common_arg(
  508. {"-Crd", "--cpu-range-draft"}, "lo-hi",
  509. "Ranges of CPUs for affinity. Complements --cpu-mask-draft",
  510. [](common_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(common_arg(
  518. {"--cpu-strict-draft"}, "<0|1>",
  519. "Use strict CPU placement for draft model (default: same as --cpu-strict)",
  520. [](common_params & params, int value) {
  521. params.draft_cpuparams.strict_cpu = value;
  522. }
  523. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  524. add_opt(common_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. [](common_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(common_arg(
  535. {"--poll-draft"}, "<0|1>",
  536. "Use polling to wait for draft model work (default: same as --poll])",
  537. [](common_params & params, int value) {
  538. params.draft_cpuparams.poll = value;
  539. }
  540. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  541. add_opt(common_arg(
  542. {"-Cbd", "--cpu-mask-batch-draft"}, "M",
  543. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  544. [](common_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(common_arg(
  552. {"-Crbd", "--cpu-range-batch-draft"}, "lo-hi",
  553. "Ranges of CPUs for affinity. Complements --cpu-mask-draft-batch)",
  554. [](common_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(common_arg(
  562. {"--cpu-strict-batch-draft"}, "<0|1>",
  563. "Use strict CPU placement for draft model (default: --cpu-strict-draft)",
  564. [](common_params & params, int value) {
  565. params.draft_cpuparams_batch.strict_cpu = value;
  566. }
  567. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  568. add_opt(common_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. [](common_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(common_arg(
  579. {"--poll-batch-draft"}, "<0|1>",
  580. "Use polling to wait for draft model work (default: --poll-draft)",
  581. [](common_params & params, int value) {
  582. params.draft_cpuparams_batch.poll = value;
  583. }
  584. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  585. add_opt(common_arg(
  586. {"--draft"}, "N",
  587. format("number of tokens to draft for speculative decoding (default: %d)", params.n_draft),
  588. [](common_params & params, int value) {
  589. params.n_draft = value;
  590. }
  591. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP}));
  592. add_opt(common_arg(
  593. {"-ps", "--p-split"}, "N",
  594. format("speculative decoding split probability (default: %.1f)", (double)params.p_split),
  595. [](common_params & params, const std::string & value) {
  596. params.p_split = std::stof(value);
  597. }
  598. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  599. add_opt(common_arg(
  600. {"-lcs", "--lookup-cache-static"}, "FNAME",
  601. "path to static lookup cache to use for lookup decoding (not updated by generation)",
  602. [](common_params & params, const std::string & value) {
  603. params.lookup_cache_static = value;
  604. }
  605. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  606. add_opt(common_arg(
  607. {"-lcd", "--lookup-cache-dynamic"}, "FNAME",
  608. "path to dynamic lookup cache to use for lookup decoding (updated by generation)",
  609. [](common_params & params, const std::string & value) {
  610. params.lookup_cache_dynamic = value;
  611. }
  612. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  613. add_opt(common_arg(
  614. {"-c", "--ctx-size"}, "N",
  615. format("size of the prompt context (default: %d, 0 = loaded from model)", params.n_ctx),
  616. [](common_params & params, int value) {
  617. params.n_ctx = value;
  618. }
  619. ).set_env("LLAMA_ARG_CTX_SIZE"));
  620. add_opt(common_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. [](common_params & params, int value) {
  624. params.n_predict = value;
  625. }
  626. ).set_env("LLAMA_ARG_N_PREDICT"));
  627. add_opt(common_arg(
  628. {"-b", "--batch-size"}, "N",
  629. format("logical maximum batch size (default: %d)", params.n_batch),
  630. [](common_params & params, int value) {
  631. params.n_batch = value;
  632. }
  633. ).set_env("LLAMA_ARG_BATCH"));
  634. add_opt(common_arg(
  635. {"-ub", "--ubatch-size"}, "N",
  636. format("physical maximum batch size (default: %d)", params.n_ubatch),
  637. [](common_params & params, int value) {
  638. params.n_ubatch = value;
  639. }
  640. ).set_env("LLAMA_ARG_UBATCH"));
  641. add_opt(common_arg(
  642. {"--keep"}, "N",
  643. format("number of tokens to keep from the initial prompt (default: %d, -1 = all)", params.n_keep),
  644. [](common_params & params, int value) {
  645. params.n_keep = value;
  646. }
  647. ));
  648. add_opt(common_arg(
  649. {"--no-context-shift"},
  650. format("disables context shift on inifinite text generation (default: %s)", params.ctx_shift ? "disabled" : "enabled"),
  651. [](common_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(common_arg(
  656. {"--chunks"}, "N",
  657. format("max number of chunks to process (default: %d, -1 = all)", params.n_chunks),
  658. [](common_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(common_arg(
  663. {"-fa", "--flash-attn"},
  664. format("enable Flash Attention (default: %s)", params.flash_attn ? "enabled" : "disabled"),
  665. [](common_params & params) {
  666. params.flash_attn = true;
  667. }
  668. ).set_env("LLAMA_ARG_FLASH_ATTN"));
  669. add_opt(common_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. [](common_params & params, const std::string & value) {
  675. params.prompt = value;
  676. }
  677. ));
  678. add_opt(common_arg(
  679. {"--no-perf"},
  680. format("disable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"),
  681. [](common_params & params) {
  682. params.no_perf = true;
  683. params.sparams.no_perf = true;
  684. }
  685. ).set_env("LLAMA_ARG_NO_PERF"));
  686. add_opt(common_arg(
  687. {"-f", "--file"}, "FNAME",
  688. "a file containing the prompt (default: none)",
  689. [](common_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(common_arg(
  703. {"--in-file"}, "FNAME",
  704. "an input file (repeat to specify multiple files)",
  705. [](common_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(common_arg(
  714. {"-bf", "--binary-file"}, "FNAME",
  715. "binary file containing the prompt (default: none)",
  716. [](common_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(common_arg(
  730. {"-e", "--escape"},
  731. format("process escapes sequences (\\n, \\r, \\t, \\', \\\", \\\\) (default: %s)", params.escape ? "true" : "false"),
  732. [](common_params & params) {
  733. params.escape = true;
  734. }
  735. ));
  736. add_opt(common_arg(
  737. {"--no-escape"},
  738. "do not process escape sequences",
  739. [](common_params & params) {
  740. params.escape = false;
  741. }
  742. ));
  743. add_opt(common_arg(
  744. {"-ptc", "--print-token-count"}, "N",
  745. format("print token count every N tokens (default: %d)", params.n_print),
  746. [](common_params & params, int value) {
  747. params.n_print = value;
  748. }
  749. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  750. add_opt(common_arg(
  751. {"--prompt-cache"}, "FNAME",
  752. "file to cache prompt state for faster startup (default: none)",
  753. [](common_params & params, const std::string & value) {
  754. params.path_prompt_cache = value;
  755. }
  756. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  757. add_opt(common_arg(
  758. {"--prompt-cache-all"},
  759. "if specified, saves user input and generations to cache as well\n",
  760. [](common_params & params) {
  761. params.prompt_cache_all = true;
  762. }
  763. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  764. add_opt(common_arg(
  765. {"--prompt-cache-ro"},
  766. "if specified, uses the prompt cache but does not update it",
  767. [](common_params & params) {
  768. params.prompt_cache_ro = true;
  769. }
  770. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  771. add_opt(common_arg(
  772. {"-r", "--reverse-prompt"}, "PROMPT",
  773. "halt generation at PROMPT, return control in interactive mode\n",
  774. [](common_params & params, const std::string & value) {
  775. params.antiprompt.emplace_back(value);
  776. }
  777. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  778. add_opt(common_arg(
  779. {"-sp", "--special"},
  780. format("special tokens output enabled (default: %s)", params.special ? "true" : "false"),
  781. [](common_params & params) {
  782. params.special = true;
  783. }
  784. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}));
  785. add_opt(common_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. [](common_params & params) {
  795. params.conversation = true;
  796. }
  797. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  798. add_opt(common_arg(
  799. {"-i", "--interactive"},
  800. format("run in interactive mode (default: %s)", params.interactive ? "true" : "false"),
  801. [](common_params & params) {
  802. params.interactive = true;
  803. }
  804. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  805. add_opt(common_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. [](common_params & params) {
  809. params.interactive_first = true;
  810. }
  811. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  812. add_opt(common_arg(
  813. {"-mli", "--multiline-input"},
  814. "allows you to write or paste multiple lines without ending each in '\\'",
  815. [](common_params & params) {
  816. params.multiline_input = true;
  817. }
  818. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  819. add_opt(common_arg(
  820. {"--in-prefix-bos"},
  821. "prefix BOS to user inputs, preceding the `--in-prefix` string",
  822. [](common_params & params) {
  823. params.input_prefix_bos = true;
  824. params.enable_chat_template = false;
  825. }
  826. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  827. add_opt(common_arg(
  828. {"--in-prefix"}, "STRING",
  829. "string to prefix user inputs with (default: empty)",
  830. [](common_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(common_arg(
  836. {"--in-suffix"}, "STRING",
  837. "string to suffix after user inputs with (default: empty)",
  838. [](common_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(common_arg(
  844. {"--no-warmup"},
  845. "skip warming up the model with an empty run",
  846. [](common_params & params) {
  847. params.warmup = false;
  848. }
  849. ).set_examples({LLAMA_EXAMPLE_MAIN}));
  850. add_opt(common_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. [](common_params & params) {
  857. params.spm_infill = true;
  858. }
  859. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_INFILL}));
  860. add_opt(common_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. [](common_params & params, const std::string & value) {
  864. const auto sampler_names = string_split(value, ';');
  865. params.sparams.samplers = common_sampler_types_from_names(sampler_names, true);
  866. }
  867. ).set_sparam());
  868. add_opt(common_arg(
  869. {"-s", "--seed"}, "SEED",
  870. format("RNG seed (default: %d, use random seed for %d)", params.sparams.seed, LLAMA_DEFAULT_SEED),
  871. [](common_params & params, const std::string & value) {
  872. params.sparams.seed = std::stoul(value);
  873. }
  874. ).set_sparam());
  875. add_opt(common_arg(
  876. {"--sampling-seq"}, "SEQUENCE",
  877. format("simplified sequence for samplers that will be used (default: %s)", sampler_type_chars.c_str()),
  878. [](common_params & params, const std::string & value) {
  879. params.sparams.samplers = common_sampler_types_from_chars(value);
  880. }
  881. ).set_sparam());
  882. add_opt(common_arg(
  883. {"--ignore-eos"},
  884. "ignore end of stream token and continue generating (implies --logit-bias EOS-inf)",
  885. [](common_params & params) {
  886. params.sparams.ignore_eos = true;
  887. }
  888. ).set_sparam());
  889. add_opt(common_arg(
  890. {"--penalize-nl"},
  891. format("penalize newline tokens (default: %s)", params.sparams.penalize_nl ? "true" : "false"),
  892. [](common_params & params) {
  893. params.sparams.penalize_nl = true;
  894. }
  895. ).set_sparam());
  896. add_opt(common_arg(
  897. {"--temp"}, "N",
  898. format("temperature (default: %.1f)", (double)params.sparams.temp),
  899. [](common_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(common_arg(
  905. {"--top-k"}, "N",
  906. format("top-k sampling (default: %d, 0 = disabled)", params.sparams.top_k),
  907. [](common_params & params, int value) {
  908. params.sparams.top_k = value;
  909. }
  910. ).set_sparam());
  911. add_opt(common_arg(
  912. {"--top-p"}, "N",
  913. format("top-p sampling (default: %.1f, 1.0 = disabled)", (double)params.sparams.top_p),
  914. [](common_params & params, const std::string & value) {
  915. params.sparams.top_p = std::stof(value);
  916. }
  917. ).set_sparam());
  918. add_opt(common_arg(
  919. {"--min-p"}, "N",
  920. format("min-p sampling (default: %.1f, 0.0 = disabled)", (double)params.sparams.min_p),
  921. [](common_params & params, const std::string & value) {
  922. params.sparams.min_p = std::stof(value);
  923. }
  924. ).set_sparam());
  925. add_opt(common_arg(
  926. {"--tfs"}, "N",
  927. format("tail free sampling, parameter z (default: %.1f, 1.0 = disabled)", (double)params.sparams.tfs_z),
  928. [](common_params & params, const std::string & value) {
  929. params.sparams.tfs_z = std::stof(value);
  930. }
  931. ).set_sparam());
  932. add_opt(common_arg(
  933. {"--typical"}, "N",
  934. format("locally typical sampling, parameter p (default: %.1f, 1.0 = disabled)", (double)params.sparams.typ_p),
  935. [](common_params & params, const std::string & value) {
  936. params.sparams.typ_p = std::stof(value);
  937. }
  938. ).set_sparam());
  939. add_opt(common_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. [](common_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(common_arg(
  948. {"--repeat-penalty"}, "N",
  949. format("penalize repeat sequence of tokens (default: %.1f, 1.0 = disabled)", (double)params.sparams.penalty_repeat),
  950. [](common_params & params, const std::string & value) {
  951. params.sparams.penalty_repeat = std::stof(value);
  952. }
  953. ).set_sparam());
  954. add_opt(common_arg(
  955. {"--presence-penalty"}, "N",
  956. format("repeat alpha presence penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_present),
  957. [](common_params & params, const std::string & value) {
  958. params.sparams.penalty_present = std::stof(value);
  959. }
  960. ).set_sparam());
  961. add_opt(common_arg(
  962. {"--frequency-penalty"}, "N",
  963. format("repeat alpha frequency penalty (default: %.1f, 0.0 = disabled)", (double)params.sparams.penalty_freq),
  964. [](common_params & params, const std::string & value) {
  965. params.sparams.penalty_freq = std::stof(value);
  966. }
  967. ).set_sparam());
  968. add_opt(common_arg(
  969. {"--dynatemp-range"}, "N",
  970. format("dynamic temperature range (default: %.1f, 0.0 = disabled)", (double)params.sparams.dynatemp_range),
  971. [](common_params & params, const std::string & value) {
  972. params.sparams.dynatemp_range = std::stof(value);
  973. }
  974. ).set_sparam());
  975. add_opt(common_arg(
  976. {"--dynatemp-exp"}, "N",
  977. format("dynamic temperature exponent (default: %.1f)", (double)params.sparams.dynatemp_exponent),
  978. [](common_params & params, const std::string & value) {
  979. params.sparams.dynatemp_exponent = std::stof(value);
  980. }
  981. ).set_sparam());
  982. add_opt(common_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. [](common_params & params, int value) {
  987. params.sparams.mirostat = value;
  988. }
  989. ).set_sparam());
  990. add_opt(common_arg(
  991. {"--mirostat-lr"}, "N",
  992. format("Mirostat learning rate, parameter eta (default: %.1f)", (double)params.sparams.mirostat_eta),
  993. [](common_params & params, const std::string & value) {
  994. params.sparams.mirostat_eta = std::stof(value);
  995. }
  996. ).set_sparam());
  997. add_opt(common_arg(
  998. {"--mirostat-ent"}, "N",
  999. format("Mirostat target entropy, parameter tau (default: %.1f)", (double)params.sparams.mirostat_tau),
  1000. [](common_params & params, const std::string & value) {
  1001. params.sparams.mirostat_tau = std::stof(value);
  1002. }
  1003. ).set_sparam());
  1004. add_opt(common_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. [](common_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(common_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. [](common_params & params, const std::string & value) {
  1030. params.sparams.grammar = value;
  1031. }
  1032. ).set_sparam());
  1033. add_opt(common_arg(
  1034. {"--grammar-file"}, "FNAME",
  1035. "file to read grammar from",
  1036. [](common_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(common_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. [](common_params & params, const std::string & value) {
  1052. params.sparams.grammar = json_schema_to_grammar(json::parse(value));
  1053. }
  1054. ).set_sparam());
  1055. add_opt(common_arg(
  1056. {"--pooling"}, "{none,mean,cls,last,rank}",
  1057. "pooling type for embeddings, use model default if unspecified",
  1058. [](common_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(common_arg(
  1068. {"--attention"}, "{causal,non,causal}",
  1069. "attention type for embeddings, use model default if unspecified",
  1070. [](common_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(common_arg(
  1077. {"--rope-scaling"}, "{none,linear,yarn}",
  1078. "RoPE frequency scaling method, defaults to linear unless specified by the model",
  1079. [](common_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(common_arg(
  1087. {"--rope-scale"}, "N",
  1088. "RoPE context scaling factor, expands context by a factor of N",
  1089. [](common_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(common_arg(
  1094. {"--rope-freq-base"}, "N",
  1095. "RoPE base frequency, used by NTK-aware scaling (default: loaded from model)",
  1096. [](common_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(common_arg(
  1101. {"--rope-freq-scale"}, "N",
  1102. "RoPE frequency scaling factor, expands context by a factor of 1/N",
  1103. [](common_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(common_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. [](common_params & params, int value) {
  1111. params.yarn_orig_ctx = value;
  1112. }
  1113. ).set_env("LLAMA_ARG_YARN_ORIG_CTX"));
  1114. add_opt(common_arg(
  1115. {"--yarn-ext-factor"}, "N",
  1116. format("YaRN: extrapolation mix factor (default: %.1f, 0.0 = full interpolation)", (double)params.yarn_ext_factor),
  1117. [](common_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(common_arg(
  1122. {"--yarn-attn-factor"}, "N",
  1123. format("YaRN: scale sqrt(t) or attention magnitude (default: %.1f)", (double)params.yarn_attn_factor),
  1124. [](common_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(common_arg(
  1129. {"--yarn-beta-slow"}, "N",
  1130. format("YaRN: high correction dim or alpha (default: %.1f)", (double)params.yarn_beta_slow),
  1131. [](common_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(common_arg(
  1136. {"--yarn-beta-fast"}, "N",
  1137. format("YaRN: low correction dim or beta (default: %.1f)", (double)params.yarn_beta_fast),
  1138. [](common_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(common_arg(
  1143. {"-gan", "--grp-attn-n"}, "N",
  1144. format("group-attention factor (default: %d)", params.grp_attn_n),
  1145. [](common_params & params, int value) {
  1146. params.grp_attn_n = value;
  1147. }
  1148. ).set_env("LLAMA_ARG_GRP_ATTN_N"));
  1149. add_opt(common_arg(
  1150. {"-gaw", "--grp-attn-w"}, "N",
  1151. format("group-attention width (default: %.1f)", (double)params.grp_attn_w),
  1152. [](common_params & params, int value) {
  1153. params.grp_attn_w = value;
  1154. }
  1155. ).set_env("LLAMA_ARG_GRP_ATTN_W"));
  1156. add_opt(common_arg(
  1157. {"-dkvc", "--dump-kv-cache"},
  1158. "verbose print of the KV cache",
  1159. [](common_params & params) {
  1160. params.dump_kv_cache = true;
  1161. }
  1162. ));
  1163. add_opt(common_arg(
  1164. {"-nkvo", "--no-kv-offload"},
  1165. "disable KV offload",
  1166. [](common_params & params) {
  1167. params.no_kv_offload = true;
  1168. }
  1169. ).set_env("LLAMA_ARG_NO_KV_OFFLOAD"));
  1170. add_opt(common_arg(
  1171. {"-ctk", "--cache-type-k"}, "TYPE",
  1172. format("KV cache data type for K (default: %s)", params.cache_type_k.c_str()),
  1173. [](common_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(common_arg(
  1179. {"-ctv", "--cache-type-v"}, "TYPE",
  1180. format("KV cache data type for V (default: %s)", params.cache_type_v.c_str()),
  1181. [](common_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(common_arg(
  1187. {"--perplexity", "--all-logits"},
  1188. format("return logits for all tokens in the batch (default: %s)", params.logits_all ? "true" : "false"),
  1189. [](common_params & params) {
  1190. params.logits_all = true;
  1191. }
  1192. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1193. add_opt(common_arg(
  1194. {"--hellaswag"},
  1195. "compute HellaSwag score over random tasks from datafile supplied with -f",
  1196. [](common_params & params) {
  1197. params.hellaswag = true;
  1198. }
  1199. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1200. add_opt(common_arg(
  1201. {"--hellaswag-tasks"}, "N",
  1202. format("number of tasks to use when computing the HellaSwag score (default: %zu)", params.hellaswag_tasks),
  1203. [](common_params & params, int value) {
  1204. params.hellaswag_tasks = value;
  1205. }
  1206. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1207. add_opt(common_arg(
  1208. {"--winogrande"},
  1209. "compute Winogrande score over random tasks from datafile supplied with -f",
  1210. [](common_params & params) {
  1211. params.winogrande = true;
  1212. }
  1213. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1214. add_opt(common_arg(
  1215. {"--winogrande-tasks"}, "N",
  1216. format("number of tasks to use when computing the Winogrande score (default: %zu)", params.winogrande_tasks),
  1217. [](common_params & params, int value) {
  1218. params.winogrande_tasks = value;
  1219. }
  1220. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1221. add_opt(common_arg(
  1222. {"--multiple-choice"},
  1223. "compute multiple choice score over random tasks from datafile supplied with -f",
  1224. [](common_params & params) {
  1225. params.multiple_choice = true;
  1226. }
  1227. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1228. add_opt(common_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. [](common_params & params, int value) {
  1232. params.multiple_choice_tasks = value;
  1233. }
  1234. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1235. add_opt(common_arg(
  1236. {"--kl-divergence"},
  1237. "computes KL-divergence to logits provided via --kl-divergence-base",
  1238. [](common_params & params) {
  1239. params.kl_divergence = true;
  1240. }
  1241. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1242. add_opt(common_arg(
  1243. {"--save-all-logits", "--kl-divergence-base"}, "FNAME",
  1244. "set logits file",
  1245. [](common_params & params, const std::string & value) {
  1246. params.logits_file = value;
  1247. }
  1248. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1249. add_opt(common_arg(
  1250. {"--ppl-stride"}, "N",
  1251. format("stride for perplexity calculation (default: %d)", params.ppl_stride),
  1252. [](common_params & params, int value) {
  1253. params.ppl_stride = value;
  1254. }
  1255. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1256. add_opt(common_arg(
  1257. {"--ppl-output-type"}, "<0|1>",
  1258. format("output type for perplexity calculation (default: %d)", params.ppl_output_type),
  1259. [](common_params & params, int value) {
  1260. params.ppl_output_type = value;
  1261. }
  1262. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1263. add_opt(common_arg(
  1264. {"-dt", "--defrag-thold"}, "N",
  1265. format("KV cache defragmentation threshold (default: %.1f, < 0 - disabled)", (double)params.defrag_thold),
  1266. [](common_params & params, const std::string & value) {
  1267. params.defrag_thold = std::stof(value);
  1268. }
  1269. ).set_env("LLAMA_ARG_DEFRAG_THOLD"));
  1270. add_opt(common_arg(
  1271. {"-np", "--parallel"}, "N",
  1272. format("number of parallel sequences to decode (default: %d)", params.n_parallel),
  1273. [](common_params & params, int value) {
  1274. params.n_parallel = value;
  1275. }
  1276. ).set_env("LLAMA_ARG_N_PARALLEL"));
  1277. add_opt(common_arg(
  1278. {"-ns", "--sequences"}, "N",
  1279. format("number of sequences to decode (default: %d)", params.n_sequences),
  1280. [](common_params & params, int value) {
  1281. params.n_sequences = value;
  1282. }
  1283. ).set_examples({LLAMA_EXAMPLE_PARALLEL}));
  1284. add_opt(common_arg(
  1285. {"-cb", "--cont-batching"},
  1286. format("enable continuous batching (a.k.a dynamic batching) (default: %s)", params.cont_batching ? "enabled" : "disabled"),
  1287. [](common_params & params) {
  1288. params.cont_batching = true;
  1289. }
  1290. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CONT_BATCHING"));
  1291. add_opt(common_arg(
  1292. {"-nocb", "--no-cont-batching"},
  1293. "disable continuous batching",
  1294. [](common_params & params) {
  1295. params.cont_batching = false;
  1296. }
  1297. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_CONT_BATCHING"));
  1298. add_opt(common_arg(
  1299. {"--mmproj"}, "FILE",
  1300. "path to a multimodal projector file for LLaVA. see examples/llava/README.md",
  1301. [](common_params & params, const std::string & value) {
  1302. params.mmproj = value;
  1303. }
  1304. ).set_examples({LLAMA_EXAMPLE_LLAVA}));
  1305. add_opt(common_arg(
  1306. {"--image"}, "FILE",
  1307. "path to an image file. use with multimodal models. Specify multiple times for batching",
  1308. [](common_params & params, const std::string & value) {
  1309. params.image.emplace_back(value);
  1310. }
  1311. ).set_examples({LLAMA_EXAMPLE_LLAVA}));
  1312. if (llama_supports_rpc()) {
  1313. add_opt(common_arg(
  1314. {"--rpc"}, "SERVERS",
  1315. "comma separated list of RPC servers",
  1316. [](common_params & params, const std::string & value) {
  1317. params.rpc_servers = value;
  1318. }
  1319. ).set_env("LLAMA_ARG_RPC"));
  1320. }
  1321. add_opt(common_arg(
  1322. {"--mlock"},
  1323. "force system to keep model in RAM rather than swapping or compressing",
  1324. [](common_params & params) {
  1325. params.use_mlock = true;
  1326. }
  1327. ).set_env("LLAMA_ARG_MLOCK"));
  1328. add_opt(common_arg(
  1329. {"--no-mmap"},
  1330. "do not memory-map model (slower load but may reduce pageouts if not using mlock)",
  1331. [](common_params & params) {
  1332. params.use_mmap = false;
  1333. }
  1334. ).set_env("LLAMA_ARG_NO_MMAP"));
  1335. add_opt(common_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. [](common_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(common_arg(
  1351. {"-ngl", "--gpu-layers", "--n-gpu-layers"}, "N",
  1352. "number of layers to store in VRAM",
  1353. [](common_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(common_arg(
  1362. {"-ngld", "--gpu-layers-draft", "--n-gpu-layers-draft"}, "N",
  1363. "number of layers to store in VRAM for the draft model",
  1364. [](common_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(common_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. [](common_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(common_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. [](common_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(common_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. [](common_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(common_arg(
  1435. {"--check-tensors"},
  1436. format("check model tensor data for invalid values (default: %s)", params.check_tensors ? "true" : "false"),
  1437. [](common_params & params) {
  1438. params.check_tensors = true;
  1439. }
  1440. ));
  1441. add_opt(common_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. [](common_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(common_arg(
  1452. {"--lora"}, "FNAME",
  1453. "path to LoRA adapter (can be repeated to use multiple adapters)",
  1454. [](common_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(common_arg(
  1460. {"--lora-scaled"}, "FNAME", "SCALE",
  1461. "path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
  1462. [](common_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(common_arg(
  1468. {"--control-vector"}, "FNAME",
  1469. "add a control vector\nnote: this argument can be repeated to add multiple control vectors",
  1470. [](common_params & params, const std::string & value) {
  1471. params.control_vectors.push_back({ 1.0f, value, });
  1472. }
  1473. ));
  1474. add_opt(common_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. [](common_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(common_arg(
  1483. {"--control-vector-layer-range"}, "START", "END",
  1484. "layer range to apply the control vector(s) to, start and end inclusive",
  1485. [](common_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(common_arg(
  1491. {"-a", "--alias"}, "STRING",
  1492. "set alias for model name (to be used by REST API)",
  1493. [](common_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(common_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. [](common_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(common_arg(
  1510. {"-md", "--model-draft"}, "FNAME",
  1511. "draft model for speculative decoding (default: unused)",
  1512. [](common_params & params, const std::string & value) {
  1513. params.model_draft = value;
  1514. }
  1515. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  1516. add_opt(common_arg(
  1517. {"-mu", "--model-url"}, "MODEL_URL",
  1518. "model download url (default: unused)",
  1519. [](common_params & params, const std::string & value) {
  1520. params.model_url = value;
  1521. }
  1522. ).set_env("LLAMA_ARG_MODEL_URL"));
  1523. add_opt(common_arg(
  1524. {"-hfr", "--hf-repo"}, "REPO",
  1525. "Hugging Face model repository (default: unused)",
  1526. [](common_params & params, const std::string & value) {
  1527. params.hf_repo = value;
  1528. }
  1529. ).set_env("LLAMA_ARG_HF_REPO"));
  1530. add_opt(common_arg(
  1531. {"-hff", "--hf-file"}, "FILE",
  1532. "Hugging Face model file (default: unused)",
  1533. [](common_params & params, const std::string & value) {
  1534. params.hf_file = value;
  1535. }
  1536. ).set_env("LLAMA_ARG_HF_FILE"));
  1537. add_opt(common_arg(
  1538. {"-hft", "--hf-token"}, "TOKEN",
  1539. "Hugging Face access token (default: value from HF_TOKEN environment variable)",
  1540. [](common_params & params, const std::string & value) {
  1541. params.hf_token = value;
  1542. }
  1543. ).set_env("HF_TOKEN"));
  1544. add_opt(common_arg(
  1545. {"--context-file"}, "FNAME",
  1546. "file to load context from (repeat to specify multiple files)",
  1547. [](common_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(common_arg(
  1556. {"--chunk-size"}, "N",
  1557. format("minimum length of embedded text chunks (default: %d)", params.chunk_size),
  1558. [](common_params & params, int value) {
  1559. params.chunk_size = value;
  1560. }
  1561. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  1562. add_opt(common_arg(
  1563. {"--chunk-separator"}, "STRING",
  1564. format("separator between chunks (default: '%s')", params.chunk_separator.c_str()),
  1565. [](common_params & params, const std::string & value) {
  1566. params.chunk_separator = value;
  1567. }
  1568. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  1569. add_opt(common_arg(
  1570. {"--junk"}, "N",
  1571. format("number of times to repeat the junk text (default: %d)", params.n_junk),
  1572. [](common_params & params, int value) {
  1573. params.n_junk = value;
  1574. }
  1575. ).set_examples({LLAMA_EXAMPLE_PASSKEY}));
  1576. add_opt(common_arg(
  1577. {"--pos"}, "N",
  1578. format("position of the passkey in the junk text (default: %d)", params.i_pos),
  1579. [](common_params & params, int value) {
  1580. params.i_pos = value;
  1581. }
  1582. ).set_examples({LLAMA_EXAMPLE_PASSKEY}));
  1583. add_opt(common_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. [](common_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(common_arg(
  1598. {"-ofreq", "--output-frequency"}, "N",
  1599. format("output the imatrix every N iterations (default: %d)", params.n_out_freq),
  1600. [](common_params & params, int value) {
  1601. params.n_out_freq = value;
  1602. }
  1603. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1604. add_opt(common_arg(
  1605. {"--save-frequency"}, "N",
  1606. format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),
  1607. [](common_params & params, int value) {
  1608. params.n_save_freq = value;
  1609. }
  1610. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1611. add_opt(common_arg(
  1612. {"--process-output"},
  1613. format("collect data for the output tensor (default: %s)", params.process_output ? "true" : "false"),
  1614. [](common_params & params) {
  1615. params.process_output = true;
  1616. }
  1617. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1618. add_opt(common_arg(
  1619. {"--no-ppl"},
  1620. format("do not compute perplexity (default: %s)", params.compute_ppl ? "true" : "false"),
  1621. [](common_params & params) {
  1622. params.compute_ppl = false;
  1623. }
  1624. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1625. add_opt(common_arg(
  1626. {"--chunk", "--from-chunk"}, "N",
  1627. format("start processing the input from chunk N (default: %d)", params.i_chunk),
  1628. [](common_params & params, int value) {
  1629. params.i_chunk = value;
  1630. }
  1631. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1632. add_opt(common_arg(
  1633. {"-pps"},
  1634. format("is the prompt shared across parallel sequences (default: %s)", params.is_pp_shared ? "true" : "false"),
  1635. [](common_params & params) {
  1636. params.is_pp_shared = true;
  1637. }
  1638. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1639. add_opt(common_arg(
  1640. {"-npp"}, "n0,n1,...",
  1641. "number of prompt tokens",
  1642. [](common_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(common_arg(
  1648. {"-ntg"}, "n0,n1,...",
  1649. "number of text generation tokens",
  1650. [](common_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(common_arg(
  1656. {"-npl"}, "n0,n1,...",
  1657. "number of parallel prompts",
  1658. [](common_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(common_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. [](common_params & params, int value) {
  1667. params.embd_normalize = value;
  1668. }
  1669. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1670. add_opt(common_arg(
  1671. {"--embd-output-format"}, "FORMAT",
  1672. "empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix",
  1673. [](common_params & params, const std::string & value) {
  1674. params.embd_out = value;
  1675. }
  1676. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1677. add_opt(common_arg(
  1678. {"--embd-separator"}, "STRING",
  1679. "separator of embendings (default \\n) for example \"<#sep#>\"",
  1680. [](common_params & params, const std::string & value) {
  1681. params.embd_sep = value;
  1682. }
  1683. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1684. add_opt(common_arg(
  1685. {"--host"}, "HOST",
  1686. format("ip address to listen (default: %s)", params.hostname.c_str()),
  1687. [](common_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(common_arg(
  1692. {"--port"}, "PORT",
  1693. format("port to listen (default: %d)", params.port),
  1694. [](common_params & params, int value) {
  1695. params.port = value;
  1696. }
  1697. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_PORT"));
  1698. add_opt(common_arg(
  1699. {"--path"}, "PATH",
  1700. format("path to serve static files from (default: %s)", params.public_path.c_str()),
  1701. [](common_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(common_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. [](common_params & params) {
  1709. params.embedding = true;
  1710. }
  1711. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_EMBEDDINGS"));
  1712. add_opt(common_arg(
  1713. {"--reranking", "--rerank"},
  1714. format("enable reranking endpoint on server (default: %s)", params.reranking ? "enabled" : "disabled"),
  1715. [](common_params & params) {
  1716. params.reranking = true;
  1717. }
  1718. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_RERANKING"));
  1719. add_opt(common_arg(
  1720. {"--api-key"}, "KEY",
  1721. "API key to use for authentication (default: none)",
  1722. [](common_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(common_arg(
  1727. {"--api-key-file"}, "FNAME",
  1728. "path to file containing API keys (default: none)",
  1729. [](common_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(common_arg(
  1744. {"--ssl-key-file"}, "FNAME",
  1745. "path to file a PEM-encoded SSL private key",
  1746. [](common_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(common_arg(
  1751. {"--ssl-cert-file"}, "FNAME",
  1752. "path to file a PEM-encoded SSL certificate",
  1753. [](common_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(common_arg(
  1758. {"-to", "--timeout"}, "N",
  1759. format("server read/write timeout in seconds (default: %d)", params.timeout_read),
  1760. [](common_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(common_arg(
  1766. {"--threads-http"}, "N",
  1767. format("number of threads used to process HTTP requests (default: %d)", params.n_threads_http),
  1768. [](common_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(common_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. [](common_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(common_arg(
  1790. {"--metrics"},
  1791. format("enable prometheus compatible metrics endpoint (default: %s)", params.endpoint_metrics ? "enabled" : "disabled"),
  1792. [](common_params & params) {
  1793. params.endpoint_metrics = true;
  1794. }
  1795. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_METRICS"));
  1796. add_opt(common_arg(
  1797. {"--slots"},
  1798. format("enable slots monitoring endpoint (default: %s)", params.endpoint_slots ? "enabled" : "disabled"),
  1799. [](common_params & params) {
  1800. params.endpoint_slots = true;
  1801. }
  1802. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_SLOTS"));
  1803. add_opt(common_arg(
  1804. {"--props"},
  1805. format("enable changing global properties via POST /props (default: %s)", params.endpoint_props ? "enabled" : "disabled"),
  1806. [](common_params & params) {
  1807. params.endpoint_props = true;
  1808. }
  1809. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_PROPS"));
  1810. add_opt(common_arg(
  1811. {"--no-slots"},
  1812. "disables slots monitoring endpoint",
  1813. [](common_params & params) {
  1814. params.endpoint_slots = false;
  1815. }
  1816. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_NO_ENDPOINT_SLOTS"));
  1817. add_opt(common_arg(
  1818. {"--slot-save-path"}, "PATH",
  1819. "path to save slot kv cache (default: disabled)",
  1820. [](common_params & params, const std::string & value) {
  1821. params.slot_save_path = value;
  1822. // if doesn't end with DIRECTORY_SEPARATOR, add it
  1823. if (!params.slot_save_path.empty() && params.slot_save_path[params.slot_save_path.size() - 1] != DIRECTORY_SEPARATOR) {
  1824. params.slot_save_path += DIRECTORY_SEPARATOR;
  1825. }
  1826. }
  1827. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1828. add_opt(common_arg(
  1829. {"--chat-template"}, "JINJA_TEMPLATE",
  1830. "set custom jinja chat template (default: template taken from model's metadata)\n"
  1831. "if suffix/prefix are specified, template will be disabled\n"
  1832. "only commonly used templates are accepted:\nhttps://github.com/ggerganov/llama.cpp/wiki/Templates-supported-by-llama_chat_apply_template",
  1833. [](common_params & params, const std::string & value) {
  1834. if (!common_chat_verify_template(value)) {
  1835. throw std::runtime_error(format(
  1836. "error: the supplied chat template is not supported: %s\n"
  1837. "note: llama.cpp does not use jinja parser, we only support commonly used templates\n",
  1838. value.c_str()
  1839. ));
  1840. }
  1841. params.chat_template = value;
  1842. }
  1843. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
  1844. add_opt(common_arg(
  1845. {"-sps", "--slot-prompt-similarity"}, "SIMILARITY",
  1846. 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),
  1847. [](common_params & params, const std::string & value) {
  1848. params.slot_prompt_similarity = std::stof(value);
  1849. }
  1850. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1851. add_opt(common_arg(
  1852. {"--lora-init-without-apply"},
  1853. format("load LoRA adapters without applying them (apply later via POST /lora-adapters) (default: %s)", params.lora_init_without_apply ? "enabled" : "disabled"),
  1854. [](common_params & params) {
  1855. params.lora_init_without_apply = true;
  1856. }
  1857. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1858. add_opt(common_arg(
  1859. {"--simple-io"},
  1860. "use basic IO for better compatibility in subprocesses and limited consoles",
  1861. [](common_params & params) {
  1862. params.simple_io = true;
  1863. }
  1864. ).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_INFILL}));
  1865. add_opt(common_arg(
  1866. {"-ld", "--logdir"}, "LOGDIR",
  1867. "path under which to save YAML logs (no logging if unset)",
  1868. [](common_params & params, const std::string & value) {
  1869. params.logdir = value;
  1870. if (params.logdir.back() != DIRECTORY_SEPARATOR) {
  1871. params.logdir += DIRECTORY_SEPARATOR;
  1872. }
  1873. }
  1874. ));
  1875. add_opt(common_arg(
  1876. {"--positive-file"}, "FNAME",
  1877. format("positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str()),
  1878. [](common_params & params, const std::string & value) {
  1879. params.cvector_positive_file = value;
  1880. }
  1881. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1882. add_opt(common_arg(
  1883. {"--negative-file"}, "FNAME",
  1884. format("negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str()),
  1885. [](common_params & params, const std::string & value) {
  1886. params.cvector_negative_file = value;
  1887. }
  1888. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1889. add_opt(common_arg(
  1890. {"--pca-batch"}, "N",
  1891. format("batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch),
  1892. [](common_params & params, int value) {
  1893. params.n_pca_batch = value;
  1894. }
  1895. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1896. add_opt(common_arg(
  1897. {"--pca-iter"}, "N",
  1898. format("number of iterations used for PCA (default: %d)", params.n_pca_iterations),
  1899. [](common_params & params, int value) {
  1900. params.n_pca_iterations = value;
  1901. }
  1902. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1903. add_opt(common_arg(
  1904. {"--method"}, "{pca, mean}",
  1905. "dimensionality reduction method to be used (default: pca)",
  1906. [](common_params & params, const std::string & value) {
  1907. /**/ if (value == "pca") { params.cvector_dimre_method = DIMRE_METHOD_PCA; }
  1908. else if (value == "mean") { params.cvector_dimre_method = DIMRE_METHOD_MEAN; }
  1909. else { throw std::invalid_argument("invalid value"); }
  1910. }
  1911. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  1912. add_opt(common_arg(
  1913. {"--output-format"}, "{md,jsonl}",
  1914. "output format for batched-bench results (default: md)",
  1915. [](common_params & params, const std::string & value) {
  1916. /**/ if (value == "jsonl") { params.batched_bench_output_jsonl = true; }
  1917. else if (value == "md") { params.batched_bench_output_jsonl = false; }
  1918. else { std::invalid_argument("invalid value"); }
  1919. }
  1920. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  1921. add_opt(common_arg(
  1922. {"--log-disable"},
  1923. "Log disable",
  1924. [](common_params &) {
  1925. common_log_pause(common_log_main());
  1926. }
  1927. ));
  1928. add_opt(common_arg(
  1929. {"--log-file"}, "FNAME",
  1930. "Log to file",
  1931. [](common_params &, const std::string & value) {
  1932. common_log_set_file(common_log_main(), value.c_str());
  1933. }
  1934. ));
  1935. add_opt(common_arg(
  1936. {"--log-colors"},
  1937. "Enable colored logging",
  1938. [](common_params &) {
  1939. common_log_set_colors(common_log_main(), true);
  1940. }
  1941. ).set_env("LLAMA_LOG_COLORS"));
  1942. add_opt(common_arg(
  1943. {"-v", "--verbose", "--log-verbose"},
  1944. "Set verbosity level to infinity (i.e. log all messages, useful for debugging)",
  1945. [](common_params & params) {
  1946. params.verbosity = INT_MAX;
  1947. common_log_set_verbosity_thold(INT_MAX);
  1948. }
  1949. ));
  1950. add_opt(common_arg(
  1951. {"-lv", "--verbosity", "--log-verbosity"}, "N",
  1952. "Set the verbosity threshold. Messages with a higher verbosity will be ignored.",
  1953. [](common_params & params, int value) {
  1954. params.verbosity = value;
  1955. common_log_set_verbosity_thold(value);
  1956. }
  1957. ).set_env("LLAMA_LOG_VERBOSITY"));
  1958. add_opt(common_arg(
  1959. {"--log-prefix"},
  1960. "Enable prefx in log messages",
  1961. [](common_params &) {
  1962. common_log_set_prefix(common_log_main(), true);
  1963. }
  1964. ).set_env("LLAMA_LOG_PREFIX"));
  1965. add_opt(common_arg(
  1966. {"--log-timestamps"},
  1967. "Enable timestamps in log messages",
  1968. [](common_params &) {
  1969. common_log_set_timestamps(common_log_main(), true);
  1970. }
  1971. ).set_env("LLAMA_LOG_TIMESTAMPS"));
  1972. return ctx_arg;
  1973. }