arg.cpp 104 KB

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