1
0

arg.cpp 88 KB

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