arg.cpp 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354
  1. #include "arg.h"
  2. #include "chat.h"
  3. #include "common.h"
  4. #include "json-schema-to-grammar.h"
  5. #include "log.h"
  6. #include "sampling.h"
  7. #include "download.h"
  8. // fix problem with std::min and std::max
  9. #if defined(_WIN32)
  10. #define WIN32_LEAN_AND_MEAN
  11. #ifndef NOMINMAX
  12. # define NOMINMAX
  13. #endif
  14. #include <windows.h>
  15. #endif
  16. #define JSON_ASSERT GGML_ASSERT
  17. #include <nlohmann/json.hpp>
  18. #include <algorithm>
  19. #include <climits>
  20. #include <cstdarg>
  21. #include <fstream>
  22. #include <list>
  23. #include <regex>
  24. #include <set>
  25. #include <string>
  26. #include <thread> // for hardware_concurrency
  27. #include <vector>
  28. #ifndef __EMSCRIPTEN__
  29. #ifdef __linux__
  30. #include <linux/limits.h>
  31. #elif defined(_WIN32)
  32. # if !defined(PATH_MAX)
  33. # define PATH_MAX MAX_PATH
  34. # endif
  35. #elif defined(_AIX)
  36. #include <sys/limits.h>
  37. #else
  38. #include <sys/syslimits.h>
  39. #endif
  40. #endif
  41. #define LLAMA_MAX_URL_LENGTH 2084 // Maximum URL Length in Chrome: 2083
  42. using json = nlohmann::ordered_json;
  43. using namespace common_arg_utils;
  44. static std::initializer_list<enum llama_example> mmproj_examples = {
  45. LLAMA_EXAMPLE_MTMD,
  46. LLAMA_EXAMPLE_SERVER,
  47. LLAMA_EXAMPLE_CLI,
  48. };
  49. static std::string read_file(const std::string & fname) {
  50. std::ifstream file(fname);
  51. if (!file) {
  52. throw std::runtime_error(string_format("error: failed to open file '%s'\n", fname.c_str()));
  53. }
  54. std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
  55. file.close();
  56. return content;
  57. }
  58. static const std::vector<common_arg> & get_common_arg_defs() {
  59. static const std::vector<common_arg> options = [] {
  60. common_params params;
  61. auto ctx = common_params_parser_init(params, LLAMA_EXAMPLE_SERVER, nullptr);
  62. return ctx.options;
  63. }();
  64. return options;
  65. }
  66. common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
  67. this->examples = examples;
  68. return *this;
  69. }
  70. common_arg & common_arg::set_excludes(std::initializer_list<enum llama_example> excludes) {
  71. this->excludes = excludes;
  72. return *this;
  73. }
  74. common_arg & common_arg::set_env(const char * env) {
  75. help = help + "\n(env: " + env + ")";
  76. this->env = env;
  77. return *this;
  78. }
  79. common_arg & common_arg::set_sparam() {
  80. is_sparam = true;
  81. return *this;
  82. }
  83. bool common_arg::in_example(enum llama_example ex) {
  84. return examples.find(ex) != examples.end();
  85. }
  86. bool common_arg::is_exclude(enum llama_example ex) {
  87. return excludes.find(ex) != excludes.end();
  88. }
  89. bool common_arg::get_value_from_env(std::string & output) const {
  90. if (env == nullptr) return false;
  91. if (!args_neg.empty()) {
  92. // for compatibility, we need to check LLAMA_ARG_NO_ env as well
  93. std::string neg_env = env;
  94. string_replace_all(neg_env, "LLAMA_ARG_", "LLAMA_ARG_NO_");
  95. char * neg_value = std::getenv(neg_env.c_str());
  96. if (neg_value) {
  97. output = "0"; // falsey
  98. return true;
  99. }
  100. }
  101. char * value = std::getenv(env);
  102. if (value) {
  103. output = value;
  104. return true;
  105. }
  106. return false;
  107. }
  108. bool common_arg::has_value_from_env() const {
  109. if (env != nullptr && !args_neg.empty()) {
  110. // for compatibility, we need to check LLAMA_ARG_NO_ env as well
  111. std::string neg_env = env;
  112. string_replace_all(neg_env, "LLAMA_ARG_", "LLAMA_ARG_NO_");
  113. if (std::getenv(neg_env.c_str())) {
  114. return true;
  115. }
  116. }
  117. return env != nullptr && std::getenv(env);
  118. }
  119. static std::vector<std::string> break_str_into_lines(std::string input, size_t max_char_per_line) {
  120. std::vector<std::string> result;
  121. std::istringstream iss(input);
  122. std::string line;
  123. auto add_line = [&](const std::string& l) {
  124. if (l.length() <= max_char_per_line) {
  125. result.push_back(l);
  126. } else {
  127. std::istringstream line_stream(l);
  128. std::string word, current_line;
  129. while (line_stream >> word) {
  130. if (current_line.length() + !current_line.empty() + word.length() > max_char_per_line) {
  131. if (!current_line.empty()) result.push_back(current_line);
  132. current_line = word;
  133. } else {
  134. current_line += (!current_line.empty() ? " " : "") + word;
  135. }
  136. }
  137. if (!current_line.empty()) result.push_back(current_line);
  138. }
  139. };
  140. while (std::getline(iss, line)) {
  141. add_line(line);
  142. }
  143. return result;
  144. }
  145. std::string common_arg::to_string() const {
  146. // params for printing to console
  147. const static int n_leading_spaces = 40;
  148. const static int n_char_per_line_help = 70; // TODO: detect this based on current console
  149. std::string leading_spaces(n_leading_spaces, ' ');
  150. std::ostringstream ss;
  151. auto all_args = get_args(); // also contains args_neg
  152. for (const auto & arg : all_args) {
  153. if (arg == all_args.front()) {
  154. if (all_args.size() == 1) {
  155. ss << arg;
  156. } else {
  157. // first arg is usually abbreviation, we need padding to make it more beautiful
  158. auto tmp = std::string(arg) + ", ";
  159. auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
  160. ss << tmp << spaces;
  161. }
  162. } else {
  163. ss << arg << (arg != all_args.back() ? ", " : "");
  164. }
  165. }
  166. if (value_hint) ss << " " << value_hint;
  167. if (value_hint_2) ss << " " << value_hint_2;
  168. if (ss.tellp() > n_leading_spaces - 3) {
  169. // current line is too long, add new line
  170. ss << "\n" << leading_spaces;
  171. } else {
  172. // padding between arg and help, same line
  173. ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
  174. }
  175. const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
  176. for (const auto & line : help_lines) {
  177. ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
  178. }
  179. return ss.str();
  180. }
  181. std::vector<std::string> common_arg::get_args() const {
  182. std::vector<std::string> result;
  183. for (const auto & arg : args) {
  184. result.push_back(std::string(arg));
  185. }
  186. for (const auto & arg : args_neg) {
  187. result.push_back(std::string(arg));
  188. }
  189. return result;
  190. }
  191. std::vector<std::string> common_arg::get_env() const {
  192. std::vector<std::string> result;
  193. if (env) {
  194. result.push_back(std::string(env));
  195. }
  196. if (!args_neg.empty() && env) {
  197. // for compatibility, we need to add LLAMA_ARG_NO_ variant
  198. std::string neg_env = env;
  199. string_replace_all(neg_env, "LLAMA_ARG_", "LLAMA_ARG_NO_");
  200. result.push_back(neg_env);
  201. }
  202. return result;
  203. }
  204. //
  205. // utils
  206. //
  207. // Helper function to parse tensor buffer override strings
  208. static void parse_tensor_buffer_overrides(const std::string & value, std::vector<llama_model_tensor_buft_override> & overrides) {
  209. std::map<std::string, ggml_backend_buffer_type_t> buft_list;
  210. for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
  211. auto * dev = ggml_backend_dev_get(i);
  212. auto * buft = ggml_backend_dev_buffer_type(dev);
  213. if (buft) {
  214. buft_list[ggml_backend_buft_name(buft)] = buft;
  215. }
  216. }
  217. for (const auto & override : string_split<std::string>(value, ',')) {
  218. std::string::size_type pos = override.find('=');
  219. if (pos == std::string::npos) {
  220. throw std::invalid_argument("invalid value");
  221. }
  222. std::string tensor_name = override.substr(0, pos);
  223. std::string buffer_type = override.substr(pos + 1);
  224. if (buft_list.find(buffer_type) == buft_list.end()) {
  225. printf("Available buffer types:\n");
  226. for (const auto & it : buft_list) {
  227. printf(" %s\n", ggml_backend_buft_name(it.second));
  228. }
  229. throw std::invalid_argument("unknown buffer type");
  230. }
  231. // keep strings alive and avoid leaking memory by storing them in a static vector
  232. static std::list<std::string> buft_overrides;
  233. buft_overrides.push_back(tensor_name);
  234. overrides.push_back({buft_overrides.back().c_str(), buft_list.at(buffer_type)});
  235. }
  236. }
  237. struct handle_model_result {
  238. bool found_mmproj = false;
  239. common_params_model mmproj;
  240. };
  241. static handle_model_result common_params_handle_model(
  242. struct common_params_model & model,
  243. const std::string & bearer_token,
  244. bool offline) {
  245. handle_model_result result;
  246. // handle pre-fill default model path and url based on hf_repo and hf_file
  247. {
  248. if (!model.docker_repo.empty()) { // Handle Docker URLs by resolving them to local paths
  249. model.path = common_docker_resolve_model(model.docker_repo);
  250. model.name = model.docker_repo; // set name for consistency
  251. } else if (!model.hf_repo.empty()) {
  252. // short-hand to avoid specifying --hf-file -> default it to --model
  253. if (model.hf_file.empty()) {
  254. if (model.path.empty()) {
  255. auto auto_detected = common_get_hf_file(model.hf_repo, bearer_token, offline);
  256. if (auto_detected.repo.empty() || auto_detected.ggufFile.empty()) {
  257. exit(1); // built without CURL, error message already printed
  258. }
  259. model.name = model.hf_repo; // repo name with tag
  260. model.hf_repo = auto_detected.repo; // repo name without tag
  261. model.hf_file = auto_detected.ggufFile;
  262. if (!auto_detected.mmprojFile.empty()) {
  263. result.found_mmproj = true;
  264. result.mmproj.hf_repo = model.hf_repo;
  265. result.mmproj.hf_file = auto_detected.mmprojFile;
  266. }
  267. } else {
  268. model.hf_file = model.path;
  269. }
  270. }
  271. std::string model_endpoint = get_model_endpoint();
  272. model.url = model_endpoint + model.hf_repo + "/resolve/main/" + model.hf_file;
  273. // make sure model path is present (for caching purposes)
  274. if (model.path.empty()) {
  275. // this is to avoid different repo having same file name, or same file name in different subdirs
  276. std::string filename = model.hf_repo + "_" + model.hf_file;
  277. // to make sure we don't have any slashes in the filename
  278. string_replace_all(filename, "/", "_");
  279. model.path = fs_get_cache_file(filename);
  280. }
  281. } else if (!model.url.empty()) {
  282. if (model.path.empty()) {
  283. auto f = string_split<std::string>(model.url, '#').front();
  284. f = string_split<std::string>(f, '?').front();
  285. model.path = fs_get_cache_file(string_split<std::string>(f, '/').back());
  286. }
  287. }
  288. }
  289. // then, download it if needed
  290. if (!model.url.empty()) {
  291. bool ok = common_download_model(model, bearer_token, offline);
  292. if (!ok) {
  293. LOG_ERR("error: failed to download model from %s\n", model.url.c_str());
  294. exit(1);
  295. }
  296. }
  297. return result;
  298. }
  299. const std::vector<ggml_type> kv_cache_types = {
  300. GGML_TYPE_F32,
  301. GGML_TYPE_F16,
  302. GGML_TYPE_BF16,
  303. GGML_TYPE_Q8_0,
  304. GGML_TYPE_Q4_0,
  305. GGML_TYPE_Q4_1,
  306. GGML_TYPE_IQ4_NL,
  307. GGML_TYPE_Q5_0,
  308. GGML_TYPE_Q5_1,
  309. };
  310. static ggml_type kv_cache_type_from_str(const std::string & s) {
  311. for (const auto & type : kv_cache_types) {
  312. if (ggml_type_name(type) == s) {
  313. return type;
  314. }
  315. }
  316. throw std::runtime_error("Unsupported cache type: " + s);
  317. }
  318. static std::string get_all_kv_cache_types() {
  319. std::ostringstream msg;
  320. for (const auto & type : kv_cache_types) {
  321. msg << ggml_type_name(type) << (&type == &kv_cache_types.back() ? "" : ", ");
  322. }
  323. return msg.str();
  324. }
  325. static bool parse_bool_value(const std::string & value) {
  326. if (is_truthy(value)) {
  327. return true;
  328. } else if (is_falsey(value)) {
  329. return false;
  330. } else {
  331. throw std::invalid_argument("invalid boolean value");
  332. }
  333. }
  334. //
  335. // CLI argument parsing functions
  336. //
  337. static bool common_params_parse_ex(int argc, char ** argv, common_params_context & ctx_arg) {
  338. common_params & params = ctx_arg.params;
  339. std::unordered_map<std::string, std::pair<common_arg *, bool>> arg_to_options;
  340. for (auto & opt : ctx_arg.options) {
  341. for (const auto & arg : opt.args) {
  342. arg_to_options[arg] = {&opt, /* is_positive */ true};
  343. }
  344. for (const auto & arg : opt.args_neg) {
  345. arg_to_options[arg] = {&opt, /* is_positive */ false};
  346. }
  347. }
  348. // handle environment variables
  349. for (auto & opt : ctx_arg.options) {
  350. std::string value;
  351. if (opt.get_value_from_env(value)) {
  352. try {
  353. if (opt.handler_void && is_truthy(value)) {
  354. opt.handler_void(params);
  355. }
  356. if (opt.handler_int) {
  357. opt.handler_int(params, std::stoi(value));
  358. }
  359. if (opt.handler_bool) {
  360. opt.handler_bool(params, parse_bool_value(value));
  361. }
  362. if (opt.handler_string) {
  363. opt.handler_string(params, value);
  364. continue;
  365. }
  366. } catch (std::exception & e) {
  367. throw std::invalid_argument(string_format(
  368. "error while handling environment variable \"%s\": %s\n\n", opt.env, e.what()));
  369. }
  370. }
  371. }
  372. // handle command line arguments
  373. auto check_arg = [&](int i) {
  374. if (i+1 >= argc) {
  375. throw std::invalid_argument("expected value for argument");
  376. }
  377. };
  378. for (int i = 1; i < argc; i++) {
  379. const std::string arg_prefix = "--";
  380. std::string arg = argv[i];
  381. if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
  382. std::replace(arg.begin(), arg.end(), '_', '-');
  383. }
  384. if (arg_to_options.find(arg) == arg_to_options.end()) {
  385. throw std::invalid_argument(string_format("error: invalid argument: %s", arg.c_str()));
  386. }
  387. auto & tmp = arg_to_options[arg];
  388. auto opt = *tmp.first;
  389. bool is_positive = tmp.second;
  390. if (opt.has_value_from_env()) {
  391. fprintf(stderr, "warn: %s environment variable is set, but will be overwritten by command line argument %s\n", opt.env, arg.c_str());
  392. }
  393. try {
  394. if (opt.handler_void) {
  395. opt.handler_void(params);
  396. continue;
  397. }
  398. if (opt.handler_bool) {
  399. opt.handler_bool(params, is_positive);
  400. continue;
  401. }
  402. // arg with single value
  403. check_arg(i);
  404. std::string val = argv[++i];
  405. if (opt.handler_int) {
  406. opt.handler_int(params, std::stoi(val));
  407. continue;
  408. }
  409. if (opt.handler_string) {
  410. opt.handler_string(params, val);
  411. continue;
  412. }
  413. // arg with 2 values
  414. check_arg(i);
  415. std::string val2 = argv[++i];
  416. if (opt.handler_str_str) {
  417. opt.handler_str_str(params, val, val2);
  418. continue;
  419. }
  420. } catch (std::exception & e) {
  421. throw std::invalid_argument(string_format(
  422. "error while handling argument \"%s\": %s\n\n"
  423. "usage:\n%s\n\nto show complete usage, run with -h",
  424. arg.c_str(), e.what(), opt.to_string().c_str()));
  425. }
  426. }
  427. postprocess_cpu_params(params.cpuparams, nullptr);
  428. postprocess_cpu_params(params.cpuparams_batch, &params.cpuparams);
  429. postprocess_cpu_params(params.speculative.cpuparams, &params.cpuparams);
  430. postprocess_cpu_params(params.speculative.cpuparams_batch, &params.cpuparams_batch);
  431. if (params.prompt_cache_all && (params.interactive || params.interactive_first)) {
  432. throw std::invalid_argument("error: --prompt-cache-all not supported in interactive mode yet\n");
  433. }
  434. // handle model and download
  435. {
  436. auto res = common_params_handle_model(params.model, params.hf_token, params.offline);
  437. if (params.no_mmproj) {
  438. params.mmproj = {};
  439. } else if (res.found_mmproj && params.mmproj.path.empty() && params.mmproj.url.empty()) {
  440. // optionally, handle mmproj model when -hf is specified
  441. params.mmproj = res.mmproj;
  442. }
  443. // only download mmproj if the current example is using it
  444. for (auto & ex : mmproj_examples) {
  445. if (ctx_arg.ex == ex) {
  446. common_params_handle_model(params.mmproj, params.hf_token, params.offline);
  447. break;
  448. }
  449. }
  450. common_params_handle_model(params.speculative.model, params.hf_token, params.offline);
  451. common_params_handle_model(params.vocoder.model, params.hf_token, params.offline);
  452. }
  453. // model is required (except for server)
  454. // TODO @ngxson : maybe show a list of available models in CLI in this case
  455. if (params.model.path.empty() && ctx_arg.ex != LLAMA_EXAMPLE_SERVER && !params.usage) {
  456. throw std::invalid_argument("error: --model is required\n");
  457. }
  458. if (params.escape) {
  459. string_process_escapes(params.prompt);
  460. string_process_escapes(params.input_prefix);
  461. string_process_escapes(params.input_suffix);
  462. for (auto & antiprompt : params.antiprompt) {
  463. string_process_escapes(antiprompt);
  464. }
  465. for (auto & seq_breaker : params.sampling.dry_sequence_breakers) {
  466. string_process_escapes(seq_breaker);
  467. }
  468. for (auto & pair : params.speculative.replacements) {
  469. string_process_escapes(pair.first);
  470. string_process_escapes(pair.second);
  471. }
  472. }
  473. if (!params.kv_overrides.empty()) {
  474. params.kv_overrides.emplace_back();
  475. params.kv_overrides.back().key[0] = 0;
  476. }
  477. if (!params.tensor_buft_overrides.empty()) {
  478. params.tensor_buft_overrides.push_back({nullptr, nullptr});
  479. }
  480. if (!params.speculative.tensor_buft_overrides.empty()) {
  481. params.speculative.tensor_buft_overrides.push_back({nullptr, nullptr});
  482. }
  483. if (!params.chat_template.empty() && !common_chat_verify_template(params.chat_template, params.use_jinja)) {
  484. throw std::runtime_error(string_format(
  485. "error: the supplied chat template is not supported: %s%s\n",
  486. params.chat_template.c_str(),
  487. params.use_jinja ? "" : "\nnote: llama.cpp was started without --jinja, we only support commonly used templates"
  488. ));
  489. }
  490. common_log_set_verbosity_thold(params.verbosity);
  491. return true;
  492. }
  493. static void common_params_print_usage(common_params_context & ctx_arg) {
  494. auto print_options = [](std::vector<common_arg *> & options) {
  495. for (common_arg * opt : options) {
  496. printf("%s", opt->to_string().c_str());
  497. }
  498. };
  499. std::vector<common_arg *> common_options;
  500. std::vector<common_arg *> sparam_options;
  501. std::vector<common_arg *> specific_options;
  502. for (auto & opt : ctx_arg.options) {
  503. // in case multiple LLAMA_EXAMPLE_* are set, we prioritize the LLAMA_EXAMPLE_* matching current example
  504. if (opt.is_sparam) {
  505. sparam_options.push_back(&opt);
  506. } else if (opt.in_example(ctx_arg.ex)) {
  507. specific_options.push_back(&opt);
  508. } else {
  509. common_options.push_back(&opt);
  510. }
  511. }
  512. printf("----- common params -----\n\n");
  513. print_options(common_options);
  514. printf("\n\n----- sampling params -----\n\n");
  515. print_options(sparam_options);
  516. // TODO: maybe convert enum llama_example to string
  517. printf("\n\n----- example-specific params -----\n\n");
  518. print_options(specific_options);
  519. }
  520. static void common_params_print_completion(common_params_context & ctx_arg) {
  521. std::vector<common_arg *> common_options;
  522. std::vector<common_arg *> sparam_options;
  523. std::vector<common_arg *> specific_options;
  524. for (auto & opt : ctx_arg.options) {
  525. if (opt.is_sparam) {
  526. sparam_options.push_back(&opt);
  527. } else if (opt.in_example(ctx_arg.ex)) {
  528. specific_options.push_back(&opt);
  529. } else {
  530. common_options.push_back(&opt);
  531. }
  532. }
  533. printf("_llama_completions() {\n");
  534. printf(" local cur prev opts\n");
  535. printf(" COMPREPLY=()\n");
  536. printf(" cur=\"${COMP_WORDS[COMP_CWORD]}\"\n");
  537. printf(" prev=\"${COMP_WORDS[COMP_CWORD-1]}\"\n\n");
  538. printf(" opts=\"");
  539. auto print_options = [](const std::vector<common_arg *> & options) {
  540. for (const common_arg * opt : options) {
  541. for (const char * arg : opt->args) {
  542. printf("%s ", arg);
  543. }
  544. }
  545. };
  546. print_options(common_options);
  547. print_options(sparam_options);
  548. print_options(specific_options);
  549. printf("\"\n\n");
  550. printf(" case \"$prev\" in\n");
  551. printf(" --model|-m)\n");
  552. printf(" COMPREPLY=( $(compgen -f -X '!*.gguf' -- \"$cur\") $(compgen -d -- \"$cur\") )\n");
  553. printf(" return 0\n");
  554. printf(" ;;\n");
  555. printf(" --grammar-file)\n");
  556. printf(" COMPREPLY=( $(compgen -f -X '!*.gbnf' -- \"$cur\") $(compgen -d -- \"$cur\") )\n");
  557. printf(" return 0\n");
  558. printf(" ;;\n");
  559. printf(" --chat-template-file)\n");
  560. printf(" COMPREPLY=( $(compgen -f -X '!*.jinja' -- \"$cur\") $(compgen -d -- \"$cur\") )\n");
  561. printf(" return 0\n");
  562. printf(" ;;\n");
  563. printf(" *)\n");
  564. printf(" COMPREPLY=( $(compgen -W \"${opts}\" -- \"$cur\") )\n");
  565. printf(" return 0\n");
  566. printf(" ;;\n");
  567. printf(" esac\n");
  568. printf("}\n\n");
  569. std::set<std::string> executables = {
  570. "llama-batched",
  571. "llama-batched-bench",
  572. "llama-bench",
  573. "llama-cli",
  574. "llama-convert-llama2c-to-ggml",
  575. "llama-cvector-generator",
  576. "llama-embedding",
  577. "llama-eval-callback",
  578. "llama-export-lora",
  579. "llama-gen-docs",
  580. "llama-gguf",
  581. "llama-gguf-hash",
  582. "llama-gguf-split",
  583. "llama-gritlm",
  584. "llama-imatrix",
  585. "llama-infill",
  586. "llama-mtmd-cli",
  587. "llama-llava-clip-quantize-cli",
  588. "llama-lookahead",
  589. "llama-lookup",
  590. "llama-lookup-create",
  591. "llama-lookup-merge",
  592. "llama-lookup-stats",
  593. "llama-parallel",
  594. "llama-passkey",
  595. "llama-perplexity",
  596. "llama-q8dot",
  597. "llama-quantize",
  598. "llama-qwen2vl-cli",
  599. "llama-retrieval",
  600. "llama-run",
  601. "llama-save-load-state",
  602. "llama-server",
  603. "llama-simple",
  604. "llama-simple-chat",
  605. "llama-speculative",
  606. "llama-speculative-simple",
  607. "llama-tokenize",
  608. "llama-tts",
  609. "llama-vdot"
  610. };
  611. for (const auto& exe : executables) {
  612. printf("complete -F _llama_completions %s\n", exe.c_str());
  613. }
  614. }
  615. static std::vector<ggml_backend_dev_t> parse_device_list(const std::string & value) {
  616. std::vector<ggml_backend_dev_t> devices;
  617. auto dev_names = string_split<std::string>(value, ',');
  618. if (dev_names.empty()) {
  619. throw std::invalid_argument("no devices specified");
  620. }
  621. if (dev_names.size() == 1 && dev_names[0] == "none") {
  622. devices.push_back(nullptr);
  623. } else {
  624. for (const auto & device : dev_names) {
  625. auto * dev = ggml_backend_dev_by_name(device.c_str());
  626. if (!dev || ggml_backend_dev_type(dev) == GGML_BACKEND_DEVICE_TYPE_CPU) {
  627. throw std::invalid_argument(string_format("invalid device: %s", device.c_str()));
  628. }
  629. devices.push_back(dev);
  630. }
  631. devices.push_back(nullptr);
  632. }
  633. return devices;
  634. }
  635. static void add_rpc_devices(const std::string & servers) {
  636. auto rpc_servers = string_split<std::string>(servers, ',');
  637. if (rpc_servers.empty()) {
  638. throw std::invalid_argument("no RPC servers specified");
  639. }
  640. ggml_backend_reg_t rpc_reg = ggml_backend_reg_by_name("RPC");
  641. if (!rpc_reg) {
  642. throw std::invalid_argument("failed to find RPC backend");
  643. }
  644. typedef ggml_backend_reg_t (*ggml_backend_rpc_add_server_t)(const char * endpoint);
  645. ggml_backend_rpc_add_server_t ggml_backend_rpc_add_server_fn = (ggml_backend_rpc_add_server_t) ggml_backend_reg_get_proc_address(rpc_reg, "ggml_backend_rpc_add_server");
  646. if (!ggml_backend_rpc_add_server_fn) {
  647. throw std::invalid_argument("failed to find RPC add server function");
  648. }
  649. for (const auto & server : rpc_servers) {
  650. auto reg = ggml_backend_rpc_add_server_fn(server.c_str());
  651. ggml_backend_register(reg);
  652. }
  653. }
  654. bool common_params_parse(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map) {
  655. common_params dummy_params;
  656. common_params_context ctx_arg = common_params_parser_init(dummy_params, ex, nullptr);
  657. std::unordered_map<std::string, common_arg *> arg_to_options;
  658. for (auto & opt : ctx_arg.options) {
  659. for (const auto & arg : opt.args) {
  660. arg_to_options[arg] = &opt;
  661. }
  662. }
  663. // TODO @ngxson : find a way to deduplicate this code
  664. // handle command line arguments
  665. auto check_arg = [&](int i) {
  666. if (i+1 >= argc) {
  667. throw std::invalid_argument("expected value for argument");
  668. }
  669. };
  670. for (int i = 1; i < argc; i++) {
  671. const std::string arg_prefix = "--";
  672. std::string arg = argv[i];
  673. if (arg.compare(0, arg_prefix.size(), arg_prefix) == 0) {
  674. std::replace(arg.begin(), arg.end(), '_', '-');
  675. }
  676. if (arg_to_options.find(arg) == arg_to_options.end()) {
  677. throw std::invalid_argument(string_format("error: invalid argument: %s", arg.c_str()));
  678. }
  679. auto opt = *arg_to_options[arg];
  680. std::string val;
  681. if (opt.value_hint != nullptr) {
  682. // arg with single value
  683. check_arg(i);
  684. val = argv[++i];
  685. }
  686. if (opt.value_hint_2 != nullptr) {
  687. // TODO: support arg with 2 values
  688. throw std::invalid_argument("error: argument with 2 values is not yet supported\n");
  689. }
  690. out_map[opt] = val;
  691. }
  692. return true;
  693. }
  694. bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  695. auto ctx_arg = common_params_parser_init(params, ex, print_usage);
  696. const common_params params_org = ctx_arg.params; // the example can modify the default params
  697. try {
  698. if (!common_params_parse_ex(argc, argv, ctx_arg)) {
  699. ctx_arg.params = params_org;
  700. return false;
  701. }
  702. if (ctx_arg.params.usage) {
  703. common_params_print_usage(ctx_arg);
  704. if (ctx_arg.print_usage) {
  705. ctx_arg.print_usage(argc, argv);
  706. }
  707. exit(0);
  708. }
  709. if (ctx_arg.params.completion) {
  710. common_params_print_completion(ctx_arg);
  711. exit(0);
  712. }
  713. params.lr.init();
  714. } catch (const std::invalid_argument & ex) {
  715. fprintf(stderr, "%s\n", ex.what());
  716. ctx_arg.params = params_org;
  717. return false;
  718. } catch (std::exception & ex) {
  719. fprintf(stderr, "%s\n", ex.what());
  720. exit(1); // for other exceptions, we exit with status code 1
  721. }
  722. return true;
  723. }
  724. static std::string list_builtin_chat_templates() {
  725. std::vector<const char *> supported_tmpl;
  726. int32_t res = llama_chat_builtin_templates(nullptr, 0);
  727. supported_tmpl.resize(res);
  728. res = llama_chat_builtin_templates(supported_tmpl.data(), supported_tmpl.size());
  729. std::ostringstream msg;
  730. for (auto & tmpl : supported_tmpl) {
  731. msg << tmpl << (&tmpl == &supported_tmpl.back() ? "" : ", ");
  732. }
  733. return msg.str();
  734. }
  735. bool common_arg_utils::is_truthy(const std::string & value) {
  736. return value == "on" || value == "enabled" || value == "true" || value == "1";
  737. }
  738. bool common_arg_utils::is_falsey(const std::string & value) {
  739. return value == "off" || value == "disabled" || value == "false" || value == "0";
  740. }
  741. bool common_arg_utils::is_autoy(const std::string & value) {
  742. return value == "auto" || value == "-1";
  743. }
  744. common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
  745. params.use_color = tty_can_use_colors();
  746. // load dynamic backends
  747. ggml_backend_load_all();
  748. common_params_context ctx_arg(params);
  749. ctx_arg.print_usage = print_usage;
  750. ctx_arg.ex = ex;
  751. std::string sampler_type_chars;
  752. std::string sampler_type_names;
  753. for (const auto & sampler : params.sampling.samplers) {
  754. sampler_type_chars += common_sampler_type_to_chr(sampler);
  755. sampler_type_names += common_sampler_type_to_str(sampler) + ";";
  756. }
  757. sampler_type_names.pop_back();
  758. /**
  759. * filter options by example
  760. * rules:
  761. * - all examples inherit options from LLAMA_EXAMPLE_COMMON
  762. * - if LLAMA_EXAMPLE_* is set (other than COMMON), we only show the option in the corresponding example
  763. * - if both {LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_*,} are set, we will prioritize the LLAMA_EXAMPLE_* matching current example
  764. */
  765. auto add_opt = [&](common_arg arg) {
  766. if ((arg.in_example(ex) || arg.in_example(LLAMA_EXAMPLE_COMMON)) && !arg.is_exclude(ex)) {
  767. ctx_arg.options.push_back(std::move(arg));
  768. }
  769. };
  770. add_opt(common_arg(
  771. {"-h", "--help", "--usage"},
  772. "print usage and exit",
  773. [](common_params & params) {
  774. params.usage = true;
  775. }
  776. ));
  777. add_opt(common_arg(
  778. {"--version"},
  779. "show version and build info",
  780. [](common_params &) {
  781. fprintf(stderr, "version: %d (%s)\n", LLAMA_BUILD_NUMBER, LLAMA_COMMIT);
  782. fprintf(stderr, "built with %s for %s\n", LLAMA_COMPILER, LLAMA_BUILD_TARGET);
  783. exit(0);
  784. }
  785. ));
  786. add_opt(common_arg(
  787. {"-cl", "--cache-list"},
  788. "show list of models in cache",
  789. [](common_params &) {
  790. printf("model cache directory: %s\n", fs_get_cache_directory().c_str());
  791. auto models = common_list_cached_models();
  792. printf("number of models in cache: %zu\n", models.size());
  793. for (size_t i = 0; i < models.size(); i++) {
  794. auto & model = models[i];
  795. printf("%4d. %s\n", (int) i + 1, model.to_string().c_str());
  796. }
  797. exit(0);
  798. }
  799. ));
  800. add_opt(common_arg(
  801. {"--completion-bash"},
  802. "print source-able bash completion script for llama.cpp",
  803. [](common_params & params) {
  804. params.completion = true;
  805. }
  806. ));
  807. add_opt(common_arg(
  808. {"--verbose-prompt"},
  809. string_format("print a verbose prompt before generation (default: %s)", params.verbose_prompt ? "true" : "false"),
  810. [](common_params & params) {
  811. params.verbose_prompt = true;
  812. }
  813. ));
  814. add_opt(common_arg(
  815. {"--display-prompt"},
  816. {"--no-display-prompt"},
  817. string_format("whether to print prompt at generation (default: %s)", params.display_prompt ? "true" : "false"),
  818. [](common_params & params, bool value) {
  819. params.display_prompt = value;
  820. }
  821. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}));
  822. add_opt(common_arg(
  823. {"-co", "--color"}, "[on|off|auto]",
  824. "Colorize output to distinguish prompt and user input from generations ('on', 'off', or 'auto', default: 'auto')\n"
  825. "'auto' enables colors when output is to a terminal",
  826. [](common_params & params, const std::string & value) {
  827. if (is_truthy(value)) {
  828. params.use_color = true;
  829. } else if (is_falsey(value)) {
  830. params.use_color = false;
  831. } else if (is_autoy(value)) {
  832. params.use_color = tty_can_use_colors();
  833. } else {
  834. throw std::invalid_argument(
  835. string_format("error: unknown value for --color: '%s'\n", value.c_str()));
  836. }
  837. }
  838. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP}));
  839. add_opt(common_arg(
  840. {"-t", "--threads"}, "N",
  841. string_format("number of CPU threads to use during generation (default: %d)", params.cpuparams.n_threads),
  842. [](common_params & params, int value) {
  843. params.cpuparams.n_threads = value;
  844. if (params.cpuparams.n_threads <= 0) {
  845. params.cpuparams.n_threads = std::thread::hardware_concurrency();
  846. }
  847. }
  848. ).set_env("LLAMA_ARG_THREADS"));
  849. add_opt(common_arg(
  850. {"-tb", "--threads-batch"}, "N",
  851. "number of threads to use during batch and prompt processing (default: same as --threads)",
  852. [](common_params & params, int value) {
  853. params.cpuparams_batch.n_threads = value;
  854. if (params.cpuparams_batch.n_threads <= 0) {
  855. params.cpuparams_batch.n_threads = std::thread::hardware_concurrency();
  856. }
  857. }
  858. ));
  859. add_opt(common_arg(
  860. {"-C", "--cpu-mask"}, "M",
  861. "CPU affinity mask: arbitrarily long hex. Complements cpu-range (default: \"\")",
  862. [](common_params & params, const std::string & mask) {
  863. params.cpuparams.mask_valid = true;
  864. if (!parse_cpu_mask(mask, params.cpuparams.cpumask)) {
  865. throw std::invalid_argument("invalid cpumask");
  866. }
  867. }
  868. ));
  869. add_opt(common_arg(
  870. {"-Cr", "--cpu-range"}, "lo-hi",
  871. "range of CPUs for affinity. Complements --cpu-mask",
  872. [](common_params & params, const std::string & range) {
  873. params.cpuparams.mask_valid = true;
  874. if (!parse_cpu_range(range, params.cpuparams.cpumask)) {
  875. throw std::invalid_argument("invalid range");
  876. }
  877. }
  878. ));
  879. add_opt(common_arg(
  880. {"--cpu-strict"}, "<0|1>",
  881. string_format("use strict CPU placement (default: %u)\n", (unsigned) params.cpuparams.strict_cpu),
  882. [](common_params & params, const std::string & value) {
  883. params.cpuparams.strict_cpu = std::stoul(value);
  884. }
  885. ));
  886. add_opt(common_arg(
  887. {"--prio"}, "N",
  888. string_format("set process/thread priority : low(-1), normal(0), medium(1), high(2), realtime(3) (default: %d)\n", params.cpuparams.priority),
  889. [](common_params & params, int prio) {
  890. if (prio < GGML_SCHED_PRIO_LOW || prio > GGML_SCHED_PRIO_REALTIME) {
  891. throw std::invalid_argument("invalid value");
  892. }
  893. params.cpuparams.priority = (enum ggml_sched_priority) prio;
  894. }
  895. ));
  896. add_opt(common_arg(
  897. {"--poll"}, "<0...100>",
  898. string_format("use polling level to wait for work (0 - no polling, default: %u)\n", (unsigned) params.cpuparams.poll),
  899. [](common_params & params, const std::string & value) {
  900. params.cpuparams.poll = std::stoul(value);
  901. }
  902. ));
  903. add_opt(common_arg(
  904. {"-Cb", "--cpu-mask-batch"}, "M",
  905. "CPU affinity mask: arbitrarily long hex. Complements cpu-range-batch (default: same as --cpu-mask)",
  906. [](common_params & params, const std::string & mask) {
  907. params.cpuparams_batch.mask_valid = true;
  908. if (!parse_cpu_mask(mask, params.cpuparams_batch.cpumask)) {
  909. throw std::invalid_argument("invalid cpumask");
  910. }
  911. }
  912. ));
  913. add_opt(common_arg(
  914. {"-Crb", "--cpu-range-batch"}, "lo-hi",
  915. "ranges of CPUs for affinity. Complements --cpu-mask-batch",
  916. [](common_params & params, const std::string & range) {
  917. params.cpuparams_batch.mask_valid = true;
  918. if (!parse_cpu_range(range, params.cpuparams_batch.cpumask)) {
  919. throw std::invalid_argument("invalid range");
  920. }
  921. }
  922. ));
  923. add_opt(common_arg(
  924. {"--cpu-strict-batch"}, "<0|1>",
  925. "use strict CPU placement (default: same as --cpu-strict)",
  926. [](common_params & params, int value) {
  927. params.cpuparams_batch.strict_cpu = value;
  928. }
  929. ));
  930. add_opt(common_arg(
  931. {"--prio-batch"}, "N",
  932. string_format("set process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.cpuparams_batch.priority),
  933. [](common_params & params, int prio) {
  934. if (prio < 0 || prio > 3) {
  935. throw std::invalid_argument("invalid value");
  936. }
  937. params.cpuparams_batch.priority = (enum ggml_sched_priority) prio;
  938. }
  939. ));
  940. add_opt(common_arg(
  941. {"--poll-batch"}, "<0|1>",
  942. "use polling to wait for work (default: same as --poll)",
  943. [](common_params & params, int value) {
  944. params.cpuparams_batch.poll = value;
  945. }
  946. ));
  947. add_opt(common_arg(
  948. {"-lcs", "--lookup-cache-static"}, "FNAME",
  949. "path to static lookup cache to use for lookup decoding (not updated by generation)",
  950. [](common_params & params, const std::string & value) {
  951. params.lookup_cache_static = value;
  952. }
  953. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  954. add_opt(common_arg(
  955. {"-lcd", "--lookup-cache-dynamic"}, "FNAME",
  956. "path to dynamic lookup cache to use for lookup decoding (updated by generation)",
  957. [](common_params & params, const std::string & value) {
  958. params.lookup_cache_dynamic = value;
  959. }
  960. ).set_examples({LLAMA_EXAMPLE_LOOKUP}));
  961. add_opt(common_arg(
  962. {"-c", "--ctx-size"}, "N",
  963. string_format("size of the prompt context (default: %d, 0 = loaded from model)", params.n_ctx),
  964. [](common_params & params, int value) {
  965. params.n_ctx = value;
  966. }
  967. ).set_env("LLAMA_ARG_CTX_SIZE"));
  968. add_opt(common_arg(
  969. {"-n", "--predict", "--n-predict"}, "N",
  970. string_format(
  971. ex == LLAMA_EXAMPLE_COMPLETION
  972. ? "number of tokens to predict (default: %d, -1 = infinity, -2 = until context filled)"
  973. : "number of tokens to predict (default: %d, -1 = infinity)",
  974. params.n_predict),
  975. [](common_params & params, int value) {
  976. params.n_predict = value;
  977. }
  978. ).set_env("LLAMA_ARG_N_PREDICT"));
  979. add_opt(common_arg(
  980. {"-b", "--batch-size"}, "N",
  981. string_format("logical maximum batch size (default: %d)", params.n_batch),
  982. [](common_params & params, int value) {
  983. params.n_batch = value;
  984. }
  985. ).set_env("LLAMA_ARG_BATCH"));
  986. add_opt(common_arg(
  987. {"-ub", "--ubatch-size"}, "N",
  988. string_format("physical maximum batch size (default: %d)", params.n_ubatch),
  989. [](common_params & params, int value) {
  990. params.n_ubatch = value;
  991. }
  992. ).set_env("LLAMA_ARG_UBATCH"));
  993. add_opt(common_arg(
  994. {"--keep"}, "N",
  995. string_format("number of tokens to keep from the initial prompt (default: %d, -1 = all)", params.n_keep),
  996. [](common_params & params, int value) {
  997. params.n_keep = value;
  998. }
  999. ));
  1000. add_opt(common_arg(
  1001. {"--swa-full"},
  1002. string_format("use full-size SWA cache (default: %s)\n"
  1003. "[(more info)](https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)", params.swa_full ? "true" : "false"),
  1004. [](common_params & params) {
  1005. params.swa_full = true;
  1006. }
  1007. ).set_env("LLAMA_ARG_SWA_FULL"));
  1008. add_opt(common_arg(
  1009. {"--ctx-checkpoints", "--swa-checkpoints"}, "N",
  1010. string_format("max number of context checkpoints to create per slot (default: %d)\n"
  1011. "[(more info)](https://github.com/ggml-org/llama.cpp/pull/15293)", params.n_ctx_checkpoints),
  1012. [](common_params & params, int value) {
  1013. params.n_ctx_checkpoints = value;
  1014. }
  1015. ).set_env("LLAMA_ARG_CTX_CHECKPOINTS").set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  1016. add_opt(common_arg(
  1017. {"--cache-ram", "-cram"}, "N",
  1018. string_format("set the maximum cache size in MiB (default: %d, -1 - no limit, 0 - disable)\n"
  1019. "[(more info)](https://github.com/ggml-org/llama.cpp/pull/16391)", params.cache_ram_mib),
  1020. [](common_params & params, int value) {
  1021. params.cache_ram_mib = value;
  1022. }
  1023. ).set_env("LLAMA_ARG_CACHE_RAM").set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  1024. add_opt(common_arg(
  1025. {"--kv-unified", "-kvu"},
  1026. string_format("use single unified KV buffer for the KV cache of all sequences (default: %s)\n"
  1027. "[(more info)](https://github.com/ggml-org/llama.cpp/pull/14363)", params.kv_unified ? "true" : "false"),
  1028. [](common_params & params) {
  1029. params.kv_unified = true;
  1030. }
  1031. ).set_env("LLAMA_ARG_KV_UNIFIED"));
  1032. add_opt(common_arg(
  1033. {"--context-shift"},
  1034. {"--no-context-shift"},
  1035. string_format("whether to use context shift on infinite text generation (default: %s)", params.ctx_shift ? "enabled" : "disabled"),
  1036. [](common_params & params, bool value) {
  1037. params.ctx_shift = value;
  1038. }
  1039. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_PERPLEXITY}).set_env("LLAMA_ARG_CONTEXT_SHIFT"));
  1040. add_opt(common_arg(
  1041. {"--chunks"}, "N",
  1042. string_format("max number of chunks to process (default: %d, -1 = all)", params.n_chunks),
  1043. [](common_params & params, int value) {
  1044. params.n_chunks = value;
  1045. }
  1046. ).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_PERPLEXITY, LLAMA_EXAMPLE_RETRIEVAL}));
  1047. add_opt(common_arg({ "-fa", "--flash-attn" }, "[on|off|auto]",
  1048. string_format("set Flash Attention use ('on', 'off', or 'auto', default: '%s')",
  1049. llama_flash_attn_type_name(params.flash_attn_type)),
  1050. [](common_params & params, const std::string & value) {
  1051. if (is_truthy(value)) {
  1052. params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED;
  1053. } else if (is_falsey(value)) {
  1054. params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_DISABLED;
  1055. } else if (is_autoy(value)) {
  1056. params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_AUTO;
  1057. } else {
  1058. throw std::runtime_error(
  1059. string_format("error: unknown value for --flash-attn: '%s'\n", value.c_str()));
  1060. }
  1061. }).set_env("LLAMA_ARG_FLASH_ATTN"));
  1062. add_opt(common_arg(
  1063. {"-p", "--prompt"}, "PROMPT",
  1064. "prompt to start generation with; for system message, use -sys",
  1065. [](common_params & params, const std::string & value) {
  1066. params.prompt = value;
  1067. }
  1068. ).set_excludes({LLAMA_EXAMPLE_SERVER}));
  1069. add_opt(common_arg(
  1070. {"-sys", "--system-prompt"}, "PROMPT",
  1071. "system prompt to use with model (if applicable, depending on chat template)",
  1072. [](common_params & params, const std::string & value) {
  1073. params.system_prompt = value;
  1074. }
  1075. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_DIFFUSION}));
  1076. add_opt(common_arg(
  1077. {"--perf"},
  1078. {"--no-perf"},
  1079. string_format("whether to enable internal libllama performance timings (default: %s)", params.no_perf ? "true" : "false"),
  1080. [](common_params & params, bool value) {
  1081. params.no_perf = !value;
  1082. params.sampling.no_perf = !value;
  1083. }
  1084. ).set_env("LLAMA_ARG_PERF"));
  1085. add_opt(common_arg(
  1086. {"--show-timings"},
  1087. {"--no-show-timings"},
  1088. string_format("whether to show timing information after each response (default: %s)", params.show_timings ? "true" : "false"),
  1089. [](common_params & params, bool value) {
  1090. params.show_timings = value;
  1091. }
  1092. ).set_examples({LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_SHOW_TIMINGS"));
  1093. add_opt(common_arg(
  1094. {"-f", "--file"}, "FNAME",
  1095. "a file containing the prompt (default: none)",
  1096. [](common_params & params, const std::string & value) {
  1097. params.prompt = read_file(value);
  1098. // store the external file name in params
  1099. params.prompt_file = value;
  1100. if (!params.prompt.empty() && params.prompt.back() == '\n') {
  1101. params.prompt.pop_back();
  1102. }
  1103. }
  1104. ).set_excludes({LLAMA_EXAMPLE_SERVER}));
  1105. add_opt(common_arg(
  1106. {"-sysf", "--system-prompt-file"}, "FNAME",
  1107. "a file containing the system prompt (default: none)",
  1108. [](common_params & params, const std::string & value) {
  1109. params.system_prompt = read_file(value);
  1110. if (!params.system_prompt.empty() && params.system_prompt.back() == '\n') {
  1111. params.system_prompt.pop_back();
  1112. }
  1113. }
  1114. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_DIFFUSION}));
  1115. add_opt(common_arg(
  1116. {"--in-file"}, "FNAME",
  1117. "an input file (repeat to specify multiple files)",
  1118. [](common_params & params, const std::string & value) {
  1119. std::ifstream file(value);
  1120. if (!file) {
  1121. throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
  1122. }
  1123. params.in_files.push_back(value);
  1124. }
  1125. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  1126. add_opt(common_arg(
  1127. {"-bf", "--binary-file"}, "FNAME",
  1128. "binary file containing the prompt (default: none)",
  1129. [](common_params & params, const std::string & value) {
  1130. std::ifstream file(value, std::ios::binary);
  1131. if (!file) {
  1132. throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
  1133. }
  1134. // store the external file name in params
  1135. params.prompt_file = value;
  1136. std::ostringstream ss;
  1137. ss << file.rdbuf();
  1138. params.prompt = ss.str();
  1139. fprintf(stderr, "Read %zu bytes from binary file %s\n", params.prompt.size(), value.c_str());
  1140. }
  1141. ).set_excludes({LLAMA_EXAMPLE_SERVER}));
  1142. add_opt(common_arg(
  1143. {"-e", "--escape"},
  1144. {"--no-escape"},
  1145. string_format("whether to process escapes sequences (\\n, \\r, \\t, \\', \\\", \\\\) (default: %s)", params.escape ? "true" : "false"),
  1146. [](common_params & params, bool value) {
  1147. params.escape = value;
  1148. }
  1149. ));
  1150. add_opt(common_arg(
  1151. {"-ptc", "--print-token-count"}, "N",
  1152. string_format("print token count every N tokens (default: %d)", params.n_print),
  1153. [](common_params & params, int value) {
  1154. params.n_print = value;
  1155. }
  1156. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1157. add_opt(common_arg(
  1158. {"--prompt-cache"}, "FNAME",
  1159. "file to cache prompt state for faster startup (default: none)",
  1160. [](common_params & params, const std::string & value) {
  1161. params.path_prompt_cache = value;
  1162. }
  1163. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1164. add_opt(common_arg(
  1165. {"--prompt-cache-all"},
  1166. "if specified, saves user input and generations to cache as well\n",
  1167. [](common_params & params) {
  1168. params.prompt_cache_all = true;
  1169. }
  1170. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1171. add_opt(common_arg(
  1172. {"--prompt-cache-ro"},
  1173. "if specified, uses the prompt cache but does not update it",
  1174. [](common_params & params) {
  1175. params.prompt_cache_ro = true;
  1176. }
  1177. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1178. add_opt(common_arg(
  1179. {"-r", "--reverse-prompt"}, "PROMPT",
  1180. "halt generation at PROMPT, return control in interactive mode\n",
  1181. [](common_params & params, const std::string & value) {
  1182. params.antiprompt.emplace_back(value);
  1183. }
  1184. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER}));
  1185. add_opt(common_arg(
  1186. {"-sp", "--special"},
  1187. string_format("special tokens output enabled (default: %s)", params.special ? "true" : "false"),
  1188. [](common_params & params) {
  1189. params.special = true;
  1190. }
  1191. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER}));
  1192. add_opt(common_arg(
  1193. {"-cnv", "--conversation"},
  1194. {"-no-cnv", "--no-conversation"},
  1195. "whether to run in conversation mode:\n"
  1196. "- does not print special tokens and suffix/prefix\n"
  1197. "- interactive mode is also enabled\n"
  1198. "(default: auto enabled if chat template is available)",
  1199. [](common_params & params, bool value) {
  1200. params.conversation_mode = value ? COMMON_CONVERSATION_MODE_ENABLED : COMMON_CONVERSATION_MODE_DISABLED;
  1201. }
  1202. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}));
  1203. add_opt(common_arg(
  1204. {"-st", "--single-turn"},
  1205. "run conversation for a single turn only, then exit when done\n"
  1206. "will not be interactive if first turn is predefined with --prompt\n"
  1207. "(default: false)",
  1208. [](common_params & params) {
  1209. params.single_turn = true;
  1210. }
  1211. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}));
  1212. add_opt(common_arg(
  1213. {"-i", "--interactive"},
  1214. string_format("run in interactive mode (default: %s)", params.interactive ? "true" : "false"),
  1215. [](common_params & params) {
  1216. params.interactive = true;
  1217. }
  1218. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1219. add_opt(common_arg(
  1220. {"-if", "--interactive-first"},
  1221. string_format("run in interactive mode and wait for input right away (default: %s)", params.interactive_first ? "true" : "false"),
  1222. [](common_params & params) {
  1223. params.interactive_first = true;
  1224. }
  1225. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1226. add_opt(common_arg(
  1227. {"-mli", "--multiline-input"},
  1228. "allows you to write or paste multiple lines without ending each in '\\'",
  1229. [](common_params & params) {
  1230. params.multiline_input = true;
  1231. }
  1232. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}));
  1233. add_opt(common_arg(
  1234. {"--in-prefix-bos"},
  1235. "prefix BOS to user inputs, preceding the `--in-prefix` string",
  1236. [](common_params & params) {
  1237. params.input_prefix_bos = true;
  1238. params.enable_chat_template = false;
  1239. }
  1240. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1241. add_opt(common_arg(
  1242. {"--in-prefix"}, "STRING",
  1243. "string to prefix user inputs with (default: empty)",
  1244. [](common_params & params, const std::string & value) {
  1245. params.input_prefix = value;
  1246. params.enable_chat_template = false;
  1247. }
  1248. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1249. add_opt(common_arg(
  1250. {"--in-suffix"}, "STRING",
  1251. "string to suffix after user inputs with (default: empty)",
  1252. [](common_params & params, const std::string & value) {
  1253. params.input_suffix = value;
  1254. params.enable_chat_template = false;
  1255. }
  1256. ).set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1257. add_opt(common_arg(
  1258. {"--warmup"},
  1259. {"--no-warmup"},
  1260. string_format("whether to perform warmup with an empty run (default: %s)", params.warmup ? "enabled" : "disabled"),
  1261. [](common_params & params, bool value) {
  1262. params.warmup = value;
  1263. }
  1264. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_MTMD, LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_RETRIEVAL, LLAMA_EXAMPLE_PERPLEXITY}));
  1265. add_opt(common_arg(
  1266. {"--spm-infill"},
  1267. string_format(
  1268. "use Suffix/Prefix/Middle pattern for infill (instead of Prefix/Suffix/Middle) as some models prefer this. (default: %s)",
  1269. params.spm_infill ? "enabled" : "disabled"
  1270. ),
  1271. [](common_params & params) {
  1272. params.spm_infill = true;
  1273. }
  1274. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  1275. add_opt(common_arg(
  1276. {"--samplers"}, "SAMPLERS",
  1277. string_format("samplers that will be used for generation in the order, separated by \';\'\n(default: %s)", sampler_type_names.c_str()),
  1278. [](common_params & params, const std::string & value) {
  1279. const auto sampler_names = string_split<std::string>(value, ';');
  1280. params.sampling.samplers = common_sampler_types_from_names(sampler_names, true);
  1281. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_SAMPLERS;
  1282. }
  1283. ).set_sparam());
  1284. add_opt(common_arg(
  1285. {"-s", "--seed"}, "SEED",
  1286. string_format("RNG seed (default: %d, use random seed for %d)", params.sampling.seed, LLAMA_DEFAULT_SEED),
  1287. [](common_params & params, const std::string & value) {
  1288. params.sampling.seed = std::stoul(value);
  1289. }
  1290. ).set_sparam());
  1291. add_opt(common_arg(
  1292. {"--sampling-seq", "--sampler-seq"}, "SEQUENCE",
  1293. string_format("simplified sequence for samplers that will be used (default: %s)", sampler_type_chars.c_str()),
  1294. [](common_params & params, const std::string & value) {
  1295. params.sampling.samplers = common_sampler_types_from_chars(value);
  1296. }
  1297. ).set_sparam());
  1298. add_opt(common_arg(
  1299. {"--ignore-eos"},
  1300. "ignore end of stream token and continue generating (implies --logit-bias EOS-inf)",
  1301. [](common_params & params) {
  1302. params.sampling.ignore_eos = true;
  1303. }
  1304. ).set_sparam());
  1305. add_opt(common_arg(
  1306. {"--temp"}, "N",
  1307. string_format("temperature (default: %.1f)", (double)params.sampling.temp),
  1308. [](common_params & params, const std::string & value) {
  1309. params.sampling.temp = std::stof(value);
  1310. params.sampling.temp = std::max(params.sampling.temp, 0.0f);
  1311. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_TEMP;
  1312. }
  1313. ).set_sparam());
  1314. add_opt(common_arg(
  1315. {"--top-k"}, "N",
  1316. string_format("top-k sampling (default: %d, 0 = disabled)", params.sampling.top_k),
  1317. [](common_params & params, int value) {
  1318. params.sampling.top_k = value;
  1319. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_TOP_K;
  1320. }
  1321. ).set_sparam());
  1322. add_opt(common_arg(
  1323. {"--top-p"}, "N",
  1324. string_format("top-p sampling (default: %.1f, 1.0 = disabled)", (double)params.sampling.top_p),
  1325. [](common_params & params, const std::string & value) {
  1326. params.sampling.top_p = std::stof(value);
  1327. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_TOP_P;
  1328. }
  1329. ).set_sparam());
  1330. add_opt(common_arg(
  1331. {"--min-p"}, "N",
  1332. string_format("min-p sampling (default: %.1f, 0.0 = disabled)", (double)params.sampling.min_p),
  1333. [](common_params & params, const std::string & value) {
  1334. params.sampling.min_p = std::stof(value);
  1335. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_MIN_P;
  1336. }
  1337. ).set_sparam());
  1338. add_opt(common_arg(
  1339. {"--top-nsigma"}, "N",
  1340. string_format("top-n-sigma sampling (default: %.1f, -1.0 = disabled)", params.sampling.top_n_sigma),
  1341. [](common_params & params, const std::string & value) {
  1342. params.sampling.top_n_sigma = std::stof(value);
  1343. }
  1344. ).set_sparam());
  1345. add_opt(common_arg(
  1346. {"--xtc-probability"}, "N",
  1347. string_format("xtc probability (default: %.1f, 0.0 = disabled)", (double)params.sampling.xtc_probability),
  1348. [](common_params & params, const std::string & value) {
  1349. params.sampling.xtc_probability = std::stof(value);
  1350. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_XTC_PROBABILITY;
  1351. }
  1352. ).set_sparam());
  1353. add_opt(common_arg(
  1354. {"--xtc-threshold"}, "N",
  1355. string_format("xtc threshold (default: %.1f, 1.0 = disabled)", (double)params.sampling.xtc_threshold),
  1356. [](common_params & params, const std::string & value) {
  1357. params.sampling.xtc_threshold = std::stof(value);
  1358. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_XTC_THRESHOLD;
  1359. }
  1360. ).set_sparam());
  1361. add_opt(common_arg(
  1362. {"--typical"}, "N",
  1363. string_format("locally typical sampling, parameter p (default: %.1f, 1.0 = disabled)", (double)params.sampling.typ_p),
  1364. [](common_params & params, const std::string & value) {
  1365. params.sampling.typ_p = std::stof(value);
  1366. }
  1367. ).set_sparam());
  1368. add_opt(common_arg(
  1369. {"--repeat-last-n"}, "N",
  1370. string_format("last n tokens to consider for penalize (default: %d, 0 = disabled, -1 = ctx_size)", params.sampling.penalty_last_n),
  1371. [](common_params & params, int value) {
  1372. if (value < -1) {
  1373. throw std::runtime_error(string_format("error: invalid repeat-last-n = %d\n", value));
  1374. }
  1375. params.sampling.penalty_last_n = value;
  1376. params.sampling.n_prev = std::max(params.sampling.n_prev, params.sampling.penalty_last_n);
  1377. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_PENALTY_LAST_N;
  1378. }
  1379. ).set_sparam());
  1380. add_opt(common_arg(
  1381. {"--repeat-penalty"}, "N",
  1382. string_format("penalize repeat sequence of tokens (default: %.1f, 1.0 = disabled)", (double)params.sampling.penalty_repeat),
  1383. [](common_params & params, const std::string & value) {
  1384. params.sampling.penalty_repeat = std::stof(value);
  1385. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_PENALTY_REPEAT;
  1386. }
  1387. ).set_sparam());
  1388. add_opt(common_arg(
  1389. {"--presence-penalty"}, "N",
  1390. string_format("repeat alpha presence penalty (default: %.1f, 0.0 = disabled)", (double)params.sampling.penalty_present),
  1391. [](common_params & params, const std::string & value) {
  1392. params.sampling.penalty_present = std::stof(value);
  1393. }
  1394. ).set_sparam());
  1395. add_opt(common_arg(
  1396. {"--frequency-penalty"}, "N",
  1397. string_format("repeat alpha frequency penalty (default: %.1f, 0.0 = disabled)", (double)params.sampling.penalty_freq),
  1398. [](common_params & params, const std::string & value) {
  1399. params.sampling.penalty_freq = std::stof(value);
  1400. }
  1401. ).set_sparam());
  1402. add_opt(common_arg(
  1403. {"--dry-multiplier"}, "N",
  1404. string_format("set DRY sampling multiplier (default: %.1f, 0.0 = disabled)", (double)params.sampling.dry_multiplier),
  1405. [](common_params & params, const std::string & value) {
  1406. params.sampling.dry_multiplier = std::stof(value);
  1407. }
  1408. ).set_sparam());
  1409. add_opt(common_arg(
  1410. {"--dry-base"}, "N",
  1411. string_format("set DRY sampling base value (default: %.2f)", (double)params.sampling.dry_base),
  1412. [](common_params & params, const std::string & value) {
  1413. float potential_base = std::stof(value);
  1414. if (potential_base >= 1.0f)
  1415. {
  1416. params.sampling.dry_base = potential_base;
  1417. }
  1418. }
  1419. ).set_sparam());
  1420. add_opt(common_arg(
  1421. {"--dry-allowed-length"}, "N",
  1422. string_format("set allowed length for DRY sampling (default: %d)", params.sampling.dry_allowed_length),
  1423. [](common_params & params, int value) {
  1424. params.sampling.dry_allowed_length = value;
  1425. }
  1426. ).set_sparam());
  1427. add_opt(common_arg(
  1428. {"--dry-penalty-last-n"}, "N",
  1429. string_format("set DRY penalty for the last n tokens (default: %d, 0 = disable, -1 = context size)", params.sampling.dry_penalty_last_n),
  1430. [](common_params & params, int value) {
  1431. if (value < -1) {
  1432. throw std::runtime_error(string_format("error: invalid dry-penalty-last-n = %d\n", value));
  1433. }
  1434. params.sampling.dry_penalty_last_n = value;
  1435. }
  1436. ).set_sparam());
  1437. add_opt(common_arg(
  1438. {"--dry-sequence-breaker"}, "STRING",
  1439. 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",
  1440. params.sampling.dry_sequence_breakers.empty() ? "none" :
  1441. std::accumulate(std::next(params.sampling.dry_sequence_breakers.begin()),
  1442. params.sampling.dry_sequence_breakers.end(),
  1443. std::string("'") + (params.sampling.dry_sequence_breakers[0] == "\n" ? "\\n" : params.sampling.dry_sequence_breakers[0]) + "'",
  1444. [](const std::string& a, const std::string& b) {
  1445. std::string formatted_b = (b == "\n") ? "\\n" : b;
  1446. return a + ", '" + formatted_b + "'";
  1447. }).c_str()),
  1448. [](common_params & params, const std::string & value) {
  1449. static bool defaults_cleared = false;
  1450. if (!defaults_cleared) {
  1451. params.sampling.dry_sequence_breakers.clear();
  1452. defaults_cleared = true;
  1453. }
  1454. if (value == "none") {
  1455. params.sampling.dry_sequence_breakers.clear();
  1456. } else {
  1457. params.sampling.dry_sequence_breakers.emplace_back(value);
  1458. }
  1459. }
  1460. ).set_sparam());
  1461. add_opt(common_arg(
  1462. {"--dynatemp-range"}, "N",
  1463. string_format("dynamic temperature range (default: %.1f, 0.0 = disabled)", (double)params.sampling.dynatemp_range),
  1464. [](common_params & params, const std::string & value) {
  1465. params.sampling.dynatemp_range = std::stof(value);
  1466. }
  1467. ).set_sparam());
  1468. add_opt(common_arg(
  1469. {"--dynatemp-exp"}, "N",
  1470. string_format("dynamic temperature exponent (default: %.1f)", (double)params.sampling.dynatemp_exponent),
  1471. [](common_params & params, const std::string & value) {
  1472. params.sampling.dynatemp_exponent = std::stof(value);
  1473. }
  1474. ).set_sparam());
  1475. add_opt(common_arg(
  1476. {"--mirostat"}, "N",
  1477. string_format("use Mirostat sampling.\nTop K, Nucleus and Locally Typical samplers are ignored if used.\n"
  1478. "(default: %d, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)", params.sampling.mirostat),
  1479. [](common_params & params, int value) {
  1480. params.sampling.mirostat = value;
  1481. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_MIROSTAT;
  1482. }
  1483. ).set_sparam());
  1484. add_opt(common_arg(
  1485. {"--mirostat-lr"}, "N",
  1486. string_format("Mirostat learning rate, parameter eta (default: %.1f)", (double)params.sampling.mirostat_eta),
  1487. [](common_params & params, const std::string & value) {
  1488. params.sampling.mirostat_eta = std::stof(value);
  1489. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_MIROSTAT_ETA;
  1490. }
  1491. ).set_sparam());
  1492. add_opt(common_arg(
  1493. {"--mirostat-ent"}, "N",
  1494. string_format("Mirostat target entropy, parameter tau (default: %.1f)", (double)params.sampling.mirostat_tau),
  1495. [](common_params & params, const std::string & value) {
  1496. params.sampling.mirostat_tau = std::stof(value);
  1497. params.sampling.user_sampling_config |= common_params_sampling_config::COMMON_PARAMS_SAMPLING_CONFIG_MIROSTAT_TAU;
  1498. }
  1499. ).set_sparam());
  1500. add_opt(common_arg(
  1501. {"-l", "--logit-bias"}, "TOKEN_ID(+/-)BIAS",
  1502. "modifies the likelihood of token appearing in the completion,\n"
  1503. "i.e. `--logit-bias 15043+1` to increase likelihood of token ' Hello',\n"
  1504. "or `--logit-bias 15043-1` to decrease likelihood of token ' Hello'",
  1505. [](common_params & params, const std::string & value) {
  1506. std::stringstream ss(value);
  1507. llama_token key;
  1508. char sign;
  1509. std::string value_str;
  1510. try {
  1511. if (ss >> key && ss >> sign && std::getline(ss, value_str) && (sign == '+' || sign == '-')) {
  1512. const float bias = std::stof(value_str) * ((sign == '-') ? -1.0f : 1.0f);
  1513. params.sampling.logit_bias.push_back({key, bias});
  1514. } else {
  1515. throw std::invalid_argument("invalid input format");
  1516. }
  1517. } catch (const std::exception&) {
  1518. throw std::invalid_argument("invalid input format");
  1519. }
  1520. }
  1521. ).set_sparam());
  1522. add_opt(common_arg(
  1523. {"--grammar"}, "GRAMMAR",
  1524. string_format("BNF-like grammar to constrain generations (see samples in grammars/ dir) (default: '%s')", params.sampling.grammar.c_str()),
  1525. [](common_params & params, const std::string & value) {
  1526. params.sampling.grammar = value;
  1527. }
  1528. ).set_sparam());
  1529. add_opt(common_arg(
  1530. {"--grammar-file"}, "FNAME",
  1531. "file to read grammar from",
  1532. [](common_params & params, const std::string & value) {
  1533. params.sampling.grammar = read_file(value);
  1534. }
  1535. ).set_sparam());
  1536. add_opt(common_arg(
  1537. {"-j", "--json-schema"}, "SCHEMA",
  1538. "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",
  1539. [](common_params & params, const std::string & value) {
  1540. params.sampling.grammar = json_schema_to_grammar(json::parse(value));
  1541. }
  1542. ).set_sparam());
  1543. add_opt(common_arg(
  1544. {"-jf", "--json-schema-file"}, "FILE",
  1545. "File containing a 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",
  1546. [](common_params & params, const std::string & value) {
  1547. std::ifstream file(value);
  1548. if (!file) {
  1549. throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
  1550. }
  1551. std::string schema;
  1552. std::copy(
  1553. std::istreambuf_iterator<char>(file),
  1554. std::istreambuf_iterator<char>(),
  1555. std::back_inserter(schema)
  1556. );
  1557. params.sampling.grammar = json_schema_to_grammar(json::parse(schema));
  1558. }
  1559. ).set_sparam());
  1560. add_opt(common_arg(
  1561. {"--pooling"}, "{none,mean,cls,last,rank}",
  1562. "pooling type for embeddings, use model default if unspecified",
  1563. [](common_params & params, const std::string & value) {
  1564. /**/ if (value == "none") { params.pooling_type = LLAMA_POOLING_TYPE_NONE; }
  1565. else if (value == "mean") { params.pooling_type = LLAMA_POOLING_TYPE_MEAN; }
  1566. else if (value == "cls") { params.pooling_type = LLAMA_POOLING_TYPE_CLS; }
  1567. else if (value == "last") { params.pooling_type = LLAMA_POOLING_TYPE_LAST; }
  1568. else if (value == "rank") { params.pooling_type = LLAMA_POOLING_TYPE_RANK; }
  1569. else { throw std::invalid_argument("invalid value"); }
  1570. }
  1571. ).set_examples({LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_RETRIEVAL, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_POOLING"));
  1572. add_opt(common_arg(
  1573. {"--attention"}, "{causal,non-causal}",
  1574. "attention type for embeddings, use model default if unspecified",
  1575. [](common_params & params, const std::string & value) {
  1576. /**/ if (value == "causal") { params.attention_type = LLAMA_ATTENTION_TYPE_CAUSAL; }
  1577. else if (value == "non-causal") { params.attention_type = LLAMA_ATTENTION_TYPE_NON_CAUSAL; }
  1578. else { throw std::invalid_argument("invalid value"); }
  1579. }
  1580. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  1581. add_opt(common_arg(
  1582. {"--rope-scaling"}, "{none,linear,yarn}",
  1583. "RoPE frequency scaling method, defaults to linear unless specified by the model",
  1584. [](common_params & params, const std::string & value) {
  1585. /**/ if (value == "none") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_NONE; }
  1586. else if (value == "linear") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_LINEAR; }
  1587. else if (value == "yarn") { params.rope_scaling_type = LLAMA_ROPE_SCALING_TYPE_YARN; }
  1588. else { throw std::invalid_argument("invalid value"); }
  1589. }
  1590. ).set_env("LLAMA_ARG_ROPE_SCALING_TYPE"));
  1591. add_opt(common_arg(
  1592. {"--rope-scale"}, "N",
  1593. "RoPE context scaling factor, expands context by a factor of N",
  1594. [](common_params & params, const std::string & value) {
  1595. params.rope_freq_scale = 1.0f / std::stof(value);
  1596. }
  1597. ).set_env("LLAMA_ARG_ROPE_SCALE"));
  1598. add_opt(common_arg(
  1599. {"--rope-freq-base"}, "N",
  1600. "RoPE base frequency, used by NTK-aware scaling (default: loaded from model)",
  1601. [](common_params & params, const std::string & value) {
  1602. params.rope_freq_base = std::stof(value);
  1603. }
  1604. ).set_env("LLAMA_ARG_ROPE_FREQ_BASE"));
  1605. add_opt(common_arg(
  1606. {"--rope-freq-scale"}, "N",
  1607. "RoPE frequency scaling factor, expands context by a factor of 1/N",
  1608. [](common_params & params, const std::string & value) {
  1609. params.rope_freq_scale = std::stof(value);
  1610. }
  1611. ).set_env("LLAMA_ARG_ROPE_FREQ_SCALE"));
  1612. add_opt(common_arg(
  1613. {"--yarn-orig-ctx"}, "N",
  1614. string_format("YaRN: original context size of model (default: %d = model training context size)", params.yarn_orig_ctx),
  1615. [](common_params & params, int value) {
  1616. params.yarn_orig_ctx = value;
  1617. }
  1618. ).set_env("LLAMA_ARG_YARN_ORIG_CTX"));
  1619. add_opt(common_arg(
  1620. {"--yarn-ext-factor"}, "N",
  1621. string_format("YaRN: extrapolation mix factor (default: %.1f, 0.0 = full interpolation)", (double)params.yarn_ext_factor),
  1622. [](common_params & params, const std::string & value) {
  1623. params.yarn_ext_factor = std::stof(value);
  1624. }
  1625. ).set_env("LLAMA_ARG_YARN_EXT_FACTOR"));
  1626. add_opt(common_arg(
  1627. {"--yarn-attn-factor"}, "N",
  1628. string_format("YaRN: scale sqrt(t) or attention magnitude (default: %.1f)", (double)params.yarn_attn_factor),
  1629. [](common_params & params, const std::string & value) {
  1630. params.yarn_attn_factor = std::stof(value);
  1631. }
  1632. ).set_env("LLAMA_ARG_YARN_ATTN_FACTOR"));
  1633. add_opt(common_arg(
  1634. {"--yarn-beta-slow"}, "N",
  1635. string_format("YaRN: high correction dim or alpha (default: %.1f)", (double)params.yarn_beta_slow),
  1636. [](common_params & params, const std::string & value) {
  1637. params.yarn_beta_slow = std::stof(value);
  1638. }
  1639. ).set_env("LLAMA_ARG_YARN_BETA_SLOW"));
  1640. add_opt(common_arg(
  1641. {"--yarn-beta-fast"}, "N",
  1642. string_format("YaRN: low correction dim or beta (default: %.1f)", (double)params.yarn_beta_fast),
  1643. [](common_params & params, const std::string & value) {
  1644. params.yarn_beta_fast = std::stof(value);
  1645. }
  1646. ).set_env("LLAMA_ARG_YARN_BETA_FAST"));
  1647. add_opt(common_arg(
  1648. {"-gan", "--grp-attn-n"}, "N",
  1649. string_format("group-attention factor (default: %d)", params.grp_attn_n),
  1650. [](common_params & params, int value) {
  1651. params.grp_attn_n = value;
  1652. }
  1653. ).set_env("LLAMA_ARG_GRP_ATTN_N").set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_PASSKEY}));
  1654. add_opt(common_arg(
  1655. {"-gaw", "--grp-attn-w"}, "N",
  1656. string_format("group-attention width (default: %d)", params.grp_attn_w),
  1657. [](common_params & params, int value) {
  1658. params.grp_attn_w = value;
  1659. }
  1660. ).set_env("LLAMA_ARG_GRP_ATTN_W").set_examples({LLAMA_EXAMPLE_COMPLETION}));
  1661. add_opt(common_arg(
  1662. {"-kvo", "--kv-offload"},
  1663. {"-nkvo", "--no-kv-offload"},
  1664. string_format("whether to enable KV cache offloading (default: %s)", params.no_kv_offload ? "disabled" : "enabled"),
  1665. [](common_params & params, bool value) {
  1666. params.no_kv_offload = !value;
  1667. }
  1668. ).set_env("LLAMA_ARG_KV_OFFLOAD"));
  1669. add_opt(common_arg(
  1670. {"--repack"},
  1671. {"-nr", "--no-repack"},
  1672. string_format("whether to enable weight repacking (default: %s)", params.no_extra_bufts ? "disabled" : "enabled"),
  1673. [](common_params & params, bool value) {
  1674. params.no_extra_bufts = !value;
  1675. }
  1676. ).set_env("LLAMA_ARG_REPACK"));
  1677. add_opt(common_arg(
  1678. {"--no-host"},
  1679. "bypass host buffer allowing extra buffers to be used",
  1680. [](common_params & params) {
  1681. params.no_host = true;
  1682. }
  1683. ).set_env("LLAMA_ARG_NO_HOST"));
  1684. add_opt(common_arg(
  1685. {"-ctk", "--cache-type-k"}, "TYPE",
  1686. string_format(
  1687. "KV cache data type for K\n"
  1688. "allowed values: %s\n"
  1689. "(default: %s)",
  1690. get_all_kv_cache_types().c_str(),
  1691. ggml_type_name(params.cache_type_k)
  1692. ),
  1693. [](common_params & params, const std::string & value) {
  1694. params.cache_type_k = kv_cache_type_from_str(value);
  1695. }
  1696. ).set_env("LLAMA_ARG_CACHE_TYPE_K"));
  1697. add_opt(common_arg(
  1698. {"-ctv", "--cache-type-v"}, "TYPE",
  1699. string_format(
  1700. "KV cache data type for V\n"
  1701. "allowed values: %s\n"
  1702. "(default: %s)",
  1703. get_all_kv_cache_types().c_str(),
  1704. ggml_type_name(params.cache_type_v)
  1705. ),
  1706. [](common_params & params, const std::string & value) {
  1707. params.cache_type_v = kv_cache_type_from_str(value);
  1708. }
  1709. ).set_env("LLAMA_ARG_CACHE_TYPE_V"));
  1710. add_opt(common_arg(
  1711. {"--hellaswag"},
  1712. "compute HellaSwag score over random tasks from datafile supplied with -f",
  1713. [](common_params & params) {
  1714. params.hellaswag = true;
  1715. }
  1716. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1717. add_opt(common_arg(
  1718. {"--hellaswag-tasks"}, "N",
  1719. string_format("number of tasks to use when computing the HellaSwag score (default: %zu)", params.hellaswag_tasks),
  1720. [](common_params & params, int value) {
  1721. params.hellaswag_tasks = value;
  1722. }
  1723. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1724. add_opt(common_arg(
  1725. {"--winogrande"},
  1726. "compute Winogrande score over random tasks from datafile supplied with -f",
  1727. [](common_params & params) {
  1728. params.winogrande = true;
  1729. }
  1730. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1731. add_opt(common_arg(
  1732. {"--winogrande-tasks"}, "N",
  1733. string_format("number of tasks to use when computing the Winogrande score (default: %zu)", params.winogrande_tasks),
  1734. [](common_params & params, int value) {
  1735. params.winogrande_tasks = value;
  1736. }
  1737. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1738. add_opt(common_arg(
  1739. {"--multiple-choice"},
  1740. "compute multiple choice score over random tasks from datafile supplied with -f",
  1741. [](common_params & params) {
  1742. params.multiple_choice = true;
  1743. }
  1744. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1745. add_opt(common_arg(
  1746. {"--multiple-choice-tasks"}, "N",
  1747. string_format("number of tasks to use when computing the multiple choice score (default: %zu)", params.multiple_choice_tasks),
  1748. [](common_params & params, int value) {
  1749. params.multiple_choice_tasks = value;
  1750. }
  1751. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1752. add_opt(common_arg(
  1753. {"--kl-divergence"},
  1754. "computes KL-divergence to logits provided via --kl-divergence-base",
  1755. [](common_params & params) {
  1756. params.kl_divergence = true;
  1757. }
  1758. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1759. add_opt(common_arg(
  1760. {"--save-all-logits", "--kl-divergence-base"}, "FNAME",
  1761. "set logits file",
  1762. [](common_params & params, const std::string & value) {
  1763. params.logits_file = value;
  1764. }
  1765. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1766. add_opt(common_arg(
  1767. {"--ppl-stride"}, "N",
  1768. string_format("stride for perplexity calculation (default: %d)", params.ppl_stride),
  1769. [](common_params & params, int value) {
  1770. params.ppl_stride = value;
  1771. }
  1772. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1773. add_opt(common_arg(
  1774. {"--ppl-output-type"}, "<0|1>",
  1775. string_format("output type for perplexity calculation (default: %d)", params.ppl_output_type),
  1776. [](common_params & params, int value) {
  1777. params.ppl_output_type = value;
  1778. }
  1779. ).set_examples({LLAMA_EXAMPLE_PERPLEXITY}));
  1780. add_opt(common_arg(
  1781. {"-dt", "--defrag-thold"}, "N",
  1782. string_format("KV cache defragmentation threshold (DEPRECATED)"),
  1783. [](common_params & params, const std::string & value) {
  1784. GGML_UNUSED(params);
  1785. GGML_UNUSED(value);
  1786. LOG_WRN("DEPRECATED: --defrag-thold is deprecated and no longer necessary to specify\n");
  1787. }
  1788. ).set_env("LLAMA_ARG_DEFRAG_THOLD"));
  1789. add_opt(common_arg(
  1790. {"-np", "--parallel"}, "N",
  1791. string_format("number of parallel sequences to decode (default: %d)", params.n_parallel),
  1792. [](common_params & params, int value) {
  1793. params.n_parallel = value;
  1794. }
  1795. ).set_env("LLAMA_ARG_N_PARALLEL"));
  1796. add_opt(common_arg(
  1797. {"-ns", "--sequences"}, "N",
  1798. string_format("number of sequences to decode (default: %d)", params.n_sequences),
  1799. [](common_params & params, int value) {
  1800. params.n_sequences = value;
  1801. }
  1802. ).set_examples({LLAMA_EXAMPLE_PARALLEL}));
  1803. add_opt(common_arg(
  1804. {"-cb", "--cont-batching"},
  1805. {"-nocb", "--no-cont-batching"},
  1806. string_format("whether to enable continuous batching (a.k.a dynamic batching) (default: %s)", params.cont_batching ? "enabled" : "disabled"),
  1807. [](common_params & params, bool value) {
  1808. params.cont_batching = value;
  1809. }
  1810. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CONT_BATCHING"));
  1811. add_opt(common_arg(
  1812. {"-mm", "--mmproj"}, "FILE",
  1813. "path to a multimodal projector file. see tools/mtmd/README.md\n"
  1814. "note: if -hf is used, this argument can be omitted",
  1815. [](common_params & params, const std::string & value) {
  1816. params.mmproj.path = value;
  1817. }
  1818. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_MMPROJ"));
  1819. add_opt(common_arg(
  1820. {"-mmu", "--mmproj-url"}, "URL",
  1821. "URL to a multimodal projector file. see tools/mtmd/README.md",
  1822. [](common_params & params, const std::string & value) {
  1823. params.mmproj.url = value;
  1824. }
  1825. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_MMPROJ_URL"));
  1826. add_opt(common_arg(
  1827. {"--mmproj-auto"},
  1828. {"--no-mmproj", "--no-mmproj-auto"},
  1829. string_format("whether to use multimodal projector file (if available), useful when using -hf (default: %s)", params.no_mmproj ? "disabled" : "enabled"),
  1830. [](common_params & params, bool value) {
  1831. params.no_mmproj = !value;
  1832. }
  1833. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_MMPROJ_AUTO"));
  1834. add_opt(common_arg(
  1835. {"--mmproj-offload"},
  1836. {"--no-mmproj-offload"},
  1837. string_format("whether to enable GPU offloading for multimodal projector (default: %s)", params.mmproj_use_gpu ? "enabled" : "disabled"),
  1838. [](common_params & params, bool value) {
  1839. params.mmproj_use_gpu = value;
  1840. }
  1841. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_MMPROJ_OFFLOAD"));
  1842. add_opt(common_arg(
  1843. {"--image", "--audio"}, "FILE",
  1844. "path to an image or audio file. use with multimodal models, can be repeated if you have multiple files\n",
  1845. [](common_params & params, const std::string & value) {
  1846. params.image.emplace_back(value);
  1847. }
  1848. ).set_examples({LLAMA_EXAMPLE_MTMD, LLAMA_EXAMPLE_CLI}));
  1849. add_opt(common_arg(
  1850. {"--image-min-tokens"}, "N",
  1851. "minimum number of tokens each image can take, only used by vision models with dynamic resolution (default: read from model)",
  1852. [](common_params & params, int value) {
  1853. params.image_min_tokens = value;
  1854. }
  1855. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_IMAGE_MIN_TOKENS"));
  1856. add_opt(common_arg(
  1857. {"--image-max-tokens"}, "N",
  1858. "maximum number of tokens each image can take, only used by vision models with dynamic resolution (default: read from model)",
  1859. [](common_params & params, int value) {
  1860. params.image_max_tokens = value;
  1861. }
  1862. ).set_examples(mmproj_examples).set_env("LLAMA_ARG_IMAGE_MAX_TOKENS"));
  1863. if (llama_supports_rpc()) {
  1864. add_opt(common_arg(
  1865. {"--rpc"}, "SERVERS",
  1866. "comma separated list of RPC servers",
  1867. [](common_params & params, const std::string & value) {
  1868. add_rpc_devices(value);
  1869. GGML_UNUSED(params);
  1870. }
  1871. ).set_env("LLAMA_ARG_RPC"));
  1872. }
  1873. add_opt(common_arg(
  1874. {"--mlock"},
  1875. "force system to keep model in RAM rather than swapping or compressing",
  1876. [](common_params & params) {
  1877. params.use_mlock = true;
  1878. }
  1879. ).set_env("LLAMA_ARG_MLOCK"));
  1880. add_opt(common_arg(
  1881. {"--mmap"},
  1882. {"--no-mmap"},
  1883. string_format("whether to memory-map model (if disabled, slower load but may reduce pageouts if not using mlock) (default: %s)", params.use_mmap ? "enabled" : "disabled"),
  1884. [](common_params & params, bool value) {
  1885. params.use_mmap = value;
  1886. }
  1887. ).set_env("LLAMA_ARG_MMAP"));
  1888. add_opt(common_arg(
  1889. {"--numa"}, "TYPE",
  1890. "attempt optimizations that help on some NUMA systems\n"
  1891. "- distribute: spread execution evenly over all nodes\n"
  1892. "- isolate: only spawn threads on CPUs on the node that execution started on\n"
  1893. "- numactl: use the CPU map provided by numactl\n"
  1894. "if run without this previously, it is recommended to drop the system page cache before using this\n"
  1895. "see https://github.com/ggml-org/llama.cpp/issues/1437",
  1896. [](common_params & params, const std::string & value) {
  1897. /**/ if (value == "distribute" || value == "") { params.numa = GGML_NUMA_STRATEGY_DISTRIBUTE; }
  1898. else if (value == "isolate") { params.numa = GGML_NUMA_STRATEGY_ISOLATE; }
  1899. else if (value == "numactl") { params.numa = GGML_NUMA_STRATEGY_NUMACTL; }
  1900. else { throw std::invalid_argument("invalid value"); }
  1901. }
  1902. ).set_env("LLAMA_ARG_NUMA"));
  1903. add_opt(common_arg(
  1904. {"-dev", "--device"}, "<dev1,dev2,..>",
  1905. "comma-separated list of devices to use for offloading (none = don't offload)\n"
  1906. "use --list-devices to see a list of available devices",
  1907. [](common_params & params, const std::string & value) {
  1908. params.devices = parse_device_list(value);
  1909. }
  1910. ).set_env("LLAMA_ARG_DEVICE"));
  1911. add_opt(common_arg(
  1912. {"--list-devices"},
  1913. "print list of available devices and exit",
  1914. [](common_params &) {
  1915. std::vector<ggml_backend_dev_t> devices;
  1916. for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
  1917. auto * dev = ggml_backend_dev_get(i);
  1918. if (ggml_backend_dev_type(dev) != GGML_BACKEND_DEVICE_TYPE_CPU) {
  1919. devices.push_back(dev);
  1920. }
  1921. }
  1922. printf("Available devices:\n");
  1923. for (auto * dev : devices) {
  1924. size_t free, total;
  1925. ggml_backend_dev_memory(dev, &free, &total);
  1926. 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);
  1927. }
  1928. exit(0);
  1929. }
  1930. ));
  1931. add_opt(common_arg(
  1932. {"--override-tensor", "-ot"}, "<tensor name pattern>=<buffer type>,...",
  1933. "override tensor buffer type", [](common_params & params, const std::string & value) {
  1934. parse_tensor_buffer_overrides(value, params.tensor_buft_overrides);
  1935. }
  1936. ));
  1937. add_opt(common_arg(
  1938. {"--override-tensor-draft", "-otd"}, "<tensor name pattern>=<buffer type>,...",
  1939. "override tensor buffer type for draft model", [](common_params & params, const std::string & value) {
  1940. parse_tensor_buffer_overrides(value, params.speculative.tensor_buft_overrides);
  1941. }
  1942. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  1943. add_opt(common_arg(
  1944. {"--cpu-moe", "-cmoe"},
  1945. "keep all Mixture of Experts (MoE) weights in the CPU",
  1946. [](common_params & params) {
  1947. params.tensor_buft_overrides.push_back(llm_ffn_exps_cpu_override());
  1948. }
  1949. ).set_env("LLAMA_ARG_CPU_MOE"));
  1950. add_opt(common_arg(
  1951. {"--n-cpu-moe", "-ncmoe"}, "N",
  1952. "keep the Mixture of Experts (MoE) weights of the first N layers in the CPU",
  1953. [](common_params & params, int value) {
  1954. if (value < 0) {
  1955. throw std::invalid_argument("invalid value");
  1956. }
  1957. for (int i = 0; i < value; ++i) {
  1958. // keep strings alive and avoid leaking memory by storing them in a static vector
  1959. static std::list<std::string> buft_overrides;
  1960. buft_overrides.push_back(llm_ffn_exps_block_regex(i));
  1961. params.tensor_buft_overrides.push_back({buft_overrides.back().c_str(), ggml_backend_cpu_buffer_type()});
  1962. }
  1963. }
  1964. ).set_env("LLAMA_ARG_N_CPU_MOE"));
  1965. add_opt(common_arg(
  1966. {"--cpu-moe-draft", "-cmoed"},
  1967. "keep all Mixture of Experts (MoE) weights in the CPU for the draft model",
  1968. [](common_params & params) {
  1969. params.speculative.tensor_buft_overrides.push_back(llm_ffn_exps_cpu_override());
  1970. }
  1971. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_CPU_MOE_DRAFT"));
  1972. add_opt(common_arg(
  1973. {"--n-cpu-moe-draft", "-ncmoed"}, "N",
  1974. "keep the Mixture of Experts (MoE) weights of the first N layers in the CPU for the draft model",
  1975. [](common_params & params, int value) {
  1976. if (value < 0) {
  1977. throw std::invalid_argument("invalid value");
  1978. }
  1979. for (int i = 0; i < value; ++i) {
  1980. static std::list<std::string> buft_overrides_draft;
  1981. buft_overrides_draft.push_back(llm_ffn_exps_block_regex(i));
  1982. params.speculative.tensor_buft_overrides.push_back({buft_overrides_draft.back().c_str(), ggml_backend_cpu_buffer_type()});
  1983. }
  1984. }
  1985. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_N_CPU_MOE_DRAFT"));
  1986. add_opt(common_arg(
  1987. {"-ngl", "--gpu-layers", "--n-gpu-layers"}, "N",
  1988. string_format("max. number of layers to store in VRAM (default: %d)", params.n_gpu_layers),
  1989. [](common_params & params, int value) {
  1990. params.n_gpu_layers = value;
  1991. if (!llama_supports_gpu_offload()) {
  1992. fprintf(stderr, "warning: no usable GPU found, --gpu-layers option will be ignored\n");
  1993. fprintf(stderr, "warning: one possible reason is that llama.cpp was compiled without GPU support\n");
  1994. fprintf(stderr, "warning: consult docs/build.md for compilation instructions\n");
  1995. }
  1996. }
  1997. ).set_env("LLAMA_ARG_N_GPU_LAYERS"));
  1998. add_opt(common_arg(
  1999. {"-sm", "--split-mode"}, "{none,layer,row}",
  2000. "how to split the model across multiple GPUs, one of:\n"
  2001. "- none: use one GPU only\n"
  2002. "- layer (default): split layers and KV across GPUs\n"
  2003. "- row: split rows across GPUs",
  2004. [](common_params & params, const std::string & value) {
  2005. std::string arg_next = value;
  2006. if (arg_next == "none") {
  2007. params.split_mode = LLAMA_SPLIT_MODE_NONE;
  2008. } else if (arg_next == "layer") {
  2009. params.split_mode = LLAMA_SPLIT_MODE_LAYER;
  2010. } else if (arg_next == "row") {
  2011. params.split_mode = LLAMA_SPLIT_MODE_ROW;
  2012. } else {
  2013. throw std::invalid_argument("invalid value");
  2014. }
  2015. if (!llama_supports_gpu_offload()) {
  2016. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the split mode has no effect.\n");
  2017. }
  2018. }
  2019. ).set_env("LLAMA_ARG_SPLIT_MODE"));
  2020. add_opt(common_arg(
  2021. {"-ts", "--tensor-split"}, "N0,N1,N2,...",
  2022. "fraction of the model to offload to each GPU, comma-separated list of proportions, e.g. 3,1",
  2023. [](common_params & params, const std::string & value) {
  2024. std::string arg_next = value;
  2025. // split string by , and /
  2026. const std::regex regex{ R"([,/]+)" };
  2027. std::sregex_token_iterator it{ arg_next.begin(), arg_next.end(), regex, -1 };
  2028. std::vector<std::string> split_arg{ it, {} };
  2029. if (split_arg.size() >= llama_max_devices()) {
  2030. throw std::invalid_argument(
  2031. string_format("got %d input configs, but system only has %d devices", (int)split_arg.size(), (int)llama_max_devices())
  2032. );
  2033. }
  2034. for (size_t i = 0; i < llama_max_devices(); ++i) {
  2035. if (i < split_arg.size()) {
  2036. params.tensor_split[i] = std::stof(split_arg[i]);
  2037. } else {
  2038. params.tensor_split[i] = 0.0f;
  2039. }
  2040. }
  2041. if (!llama_supports_gpu_offload()) {
  2042. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting a tensor split has no effect.\n");
  2043. }
  2044. }
  2045. ).set_env("LLAMA_ARG_TENSOR_SPLIT"));
  2046. add_opt(common_arg(
  2047. {"-mg", "--main-gpu"}, "INDEX",
  2048. 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),
  2049. [](common_params & params, int value) {
  2050. params.main_gpu = value;
  2051. if (!llama_supports_gpu_offload()) {
  2052. fprintf(stderr, "warning: llama.cpp was compiled without support for GPU offload. Setting the main GPU has no effect.\n");
  2053. }
  2054. }
  2055. ).set_env("LLAMA_ARG_MAIN_GPU"));
  2056. add_opt(common_arg(
  2057. {"--check-tensors"},
  2058. string_format("check model tensor data for invalid values (default: %s)", params.check_tensors ? "true" : "false"),
  2059. [](common_params & params) {
  2060. params.check_tensors = true;
  2061. }
  2062. ));
  2063. add_opt(common_arg(
  2064. {"--override-kv"}, "KEY=TYPE:VALUE",
  2065. "advanced option to override model metadata by key. may be specified multiple times.\n"
  2066. "types: int, float, bool, str. example: --override-kv tokenizer.ggml.add_bos_token=bool:false",
  2067. [](common_params & params, const std::string & value) {
  2068. if (!string_parse_kv_override(value.c_str(), params.kv_overrides)) {
  2069. throw std::runtime_error(string_format("error: Invalid type for KV override: %s\n", value.c_str()));
  2070. }
  2071. }
  2072. ));
  2073. add_opt(common_arg(
  2074. {"--op-offload"},
  2075. {"--no-op-offload"},
  2076. string_format("whether to offload host tensor operations to device (default: %s)", params.no_op_offload ? "false" : "true"),
  2077. [](common_params & params, bool value) {
  2078. params.no_op_offload = !value;
  2079. }
  2080. ));
  2081. add_opt(common_arg(
  2082. {"--lora"}, "FNAME",
  2083. "path to LoRA adapter (can be repeated to use multiple adapters)",
  2084. [](common_params & params, const std::string & value) {
  2085. params.lora_adapters.push_back({ std::string(value), 1.0, "", "", nullptr });
  2086. }
  2087. // 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
  2088. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
  2089. add_opt(common_arg(
  2090. {"--lora-scaled"}, "FNAME", "SCALE",
  2091. "path to LoRA adapter with user defined scaling (can be repeated to use multiple adapters)",
  2092. [](common_params & params, const std::string & fname, const std::string & scale) {
  2093. params.lora_adapters.push_back({ fname, std::stof(scale), "", "", nullptr });
  2094. }
  2095. // 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
  2096. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}));
  2097. add_opt(common_arg(
  2098. {"--control-vector"}, "FNAME",
  2099. "add a control vector\nnote: this argument can be repeated to add multiple control vectors",
  2100. [](common_params & params, const std::string & value) {
  2101. params.control_vectors.push_back({ 1.0f, value, });
  2102. }
  2103. ));
  2104. add_opt(common_arg(
  2105. {"--control-vector-scaled"}, "FNAME", "SCALE",
  2106. "add a control vector with user defined scaling SCALE\n"
  2107. "note: this argument can be repeated to add multiple scaled control vectors",
  2108. [](common_params & params, const std::string & fname, const std::string & scale) {
  2109. params.control_vectors.push_back({ std::stof(scale), fname });
  2110. }
  2111. ));
  2112. add_opt(common_arg(
  2113. {"--control-vector-layer-range"}, "START", "END",
  2114. "layer range to apply the control vector(s) to, start and end inclusive",
  2115. [](common_params & params, const std::string & start, const std::string & end) {
  2116. params.control_vector_layer_start = std::stoi(start);
  2117. params.control_vector_layer_end = std::stoi(end);
  2118. }
  2119. ));
  2120. add_opt(common_arg(
  2121. {"-a", "--alias"}, "STRING",
  2122. "set alias for model name (to be used by REST API)",
  2123. [](common_params & params, const std::string & value) {
  2124. params.model_alias = value;
  2125. }
  2126. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ALIAS"));
  2127. add_opt(common_arg(
  2128. {"-m", "--model"}, "FNAME",
  2129. ex == LLAMA_EXAMPLE_EXPORT_LORA
  2130. ? "model path from which to load base model"
  2131. : "model path to load",
  2132. [](common_params & params, const std::string & value) {
  2133. params.model.path = value;
  2134. }
  2135. ).set_examples({LLAMA_EXAMPLE_COMMON, LLAMA_EXAMPLE_EXPORT_LORA}).set_env("LLAMA_ARG_MODEL"));
  2136. add_opt(common_arg(
  2137. {"-mu", "--model-url"}, "MODEL_URL",
  2138. "model download url (default: unused)",
  2139. [](common_params & params, const std::string & value) {
  2140. params.model.url = value;
  2141. }
  2142. ).set_env("LLAMA_ARG_MODEL_URL"));
  2143. add_opt(common_arg(
  2144. { "-dr", "--docker-repo" }, "[<repo>/]<model>[:quant]",
  2145. "Docker Hub model repository. repo is optional, default to ai/. quant is optional, default to :latest.\n"
  2146. "example: gemma3\n"
  2147. "(default: unused)",
  2148. [](common_params & params, const std::string & value) {
  2149. params.model.docker_repo = value;
  2150. }
  2151. ).set_env("LLAMA_ARG_DOCKER_REPO"));
  2152. add_opt(common_arg(
  2153. {"-hf", "-hfr", "--hf-repo"}, "<user>/<model>[:quant]",
  2154. "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"
  2155. "mmproj is also downloaded automatically if available. to disable, add --no-mmproj\n"
  2156. "example: unsloth/phi-4-GGUF:q4_k_m\n"
  2157. "(default: unused)",
  2158. [](common_params & params, const std::string & value) {
  2159. params.model.hf_repo = value;
  2160. }
  2161. ).set_env("LLAMA_ARG_HF_REPO"));
  2162. add_opt(common_arg(
  2163. {"-hfd", "-hfrd", "--hf-repo-draft"}, "<user>/<model>[:quant]",
  2164. "Same as --hf-repo, but for the draft model (default: unused)",
  2165. [](common_params & params, const std::string & value) {
  2166. params.speculative.model.hf_repo = value;
  2167. }
  2168. ).set_env("LLAMA_ARG_HFD_REPO"));
  2169. add_opt(common_arg(
  2170. {"-hff", "--hf-file"}, "FILE",
  2171. "Hugging Face model file. If specified, it will override the quant in --hf-repo (default: unused)",
  2172. [](common_params & params, const std::string & value) {
  2173. params.model.hf_file = value;
  2174. }
  2175. ).set_env("LLAMA_ARG_HF_FILE"));
  2176. add_opt(common_arg(
  2177. {"-hfv", "-hfrv", "--hf-repo-v"}, "<user>/<model>[:quant]",
  2178. "Hugging Face model repository for the vocoder model (default: unused)",
  2179. [](common_params & params, const std::string & value) {
  2180. params.vocoder.model.hf_repo = value;
  2181. }
  2182. ).set_env("LLAMA_ARG_HF_REPO_V"));
  2183. add_opt(common_arg(
  2184. {"-hffv", "--hf-file-v"}, "FILE",
  2185. "Hugging Face model file for the vocoder model (default: unused)",
  2186. [](common_params & params, const std::string & value) {
  2187. params.vocoder.model.hf_file = value;
  2188. }
  2189. ).set_env("LLAMA_ARG_HF_FILE_V"));
  2190. add_opt(common_arg(
  2191. {"-hft", "--hf-token"}, "TOKEN",
  2192. "Hugging Face access token (default: value from HF_TOKEN environment variable)",
  2193. [](common_params & params, const std::string & value) {
  2194. params.hf_token = value;
  2195. }
  2196. ).set_env("HF_TOKEN"));
  2197. add_opt(common_arg(
  2198. {"--context-file"}, "FNAME",
  2199. "file to load context from (repeat to specify multiple files)",
  2200. [](common_params & params, const std::string & value) {
  2201. std::ifstream file(value, std::ios::binary);
  2202. if (!file) {
  2203. throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
  2204. }
  2205. params.context_files.push_back(value);
  2206. }
  2207. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  2208. add_opt(common_arg(
  2209. {"--chunk-size"}, "N",
  2210. string_format("minimum length of embedded text chunks (default: %d)", params.chunk_size),
  2211. [](common_params & params, int value) {
  2212. params.chunk_size = value;
  2213. }
  2214. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  2215. add_opt(common_arg(
  2216. {"--chunk-separator"}, "STRING",
  2217. string_format("separator between chunks (default: '%s')", params.chunk_separator.c_str()),
  2218. [](common_params & params, const std::string & value) {
  2219. params.chunk_separator = value;
  2220. }
  2221. ).set_examples({LLAMA_EXAMPLE_RETRIEVAL}));
  2222. add_opt(common_arg(
  2223. {"--junk"}, "N",
  2224. string_format("number of times to repeat the junk text (default: %d)", params.n_junk),
  2225. [](common_params & params, int value) {
  2226. params.n_junk = value;
  2227. }
  2228. ).set_examples({LLAMA_EXAMPLE_PASSKEY, LLAMA_EXAMPLE_PARALLEL}));
  2229. add_opt(common_arg(
  2230. {"--pos"}, "N",
  2231. string_format("position of the passkey in the junk text (default: %d)", params.i_pos),
  2232. [](common_params & params, int value) {
  2233. params.i_pos = value;
  2234. }
  2235. ).set_examples({LLAMA_EXAMPLE_PASSKEY}));
  2236. add_opt(common_arg(
  2237. {"-o", "--output", "--output-file"}, "FNAME",
  2238. string_format("output file (default: '%s')", params.out_file.c_str()),
  2239. [](common_params & params, const std::string & value) {
  2240. params.out_file = value;
  2241. }
  2242. ).set_examples({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_CVECTOR_GENERATOR, LLAMA_EXAMPLE_EXPORT_LORA, LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_FINETUNE}));
  2243. add_opt(common_arg(
  2244. {"-ofreq", "--output-frequency"}, "N",
  2245. string_format("output the imatrix every N iterations (default: %d)", params.n_out_freq),
  2246. [](common_params & params, int value) {
  2247. params.n_out_freq = value;
  2248. }
  2249. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2250. add_opt(common_arg(
  2251. {"--output-format"}, "{gguf,dat}",
  2252. string_format("output format for imatrix file (default: %s)", params.imat_dat > 0 ? "dat" : "gguf"),
  2253. [](common_params & params, const std::string & value) {
  2254. /**/ if (value == "gguf") { params.imat_dat = -1; }
  2255. else if (value == "dat") { params.imat_dat = 1; }
  2256. else { throw std::invalid_argument("invalid output format"); }
  2257. }
  2258. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2259. add_opt(common_arg(
  2260. {"--save-frequency"}, "N",
  2261. string_format("save an imatrix copy every N iterations (default: %d)", params.n_save_freq),
  2262. [](common_params & params, int value) {
  2263. params.n_save_freq = value;
  2264. }
  2265. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2266. add_opt(common_arg(
  2267. {"--process-output"},
  2268. string_format("collect data for the output tensor (default: %s)", params.process_output ? "true" : "false"),
  2269. [](common_params & params) {
  2270. params.process_output = true;
  2271. }
  2272. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2273. add_opt(common_arg(
  2274. {"--ppl"},
  2275. {"--no-ppl"},
  2276. string_format("whether to compute perplexity (default: %s)", params.compute_ppl ? "true" : "false"),
  2277. [](common_params & params, bool value) {
  2278. params.compute_ppl = value;
  2279. }
  2280. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2281. add_opt(common_arg(
  2282. {"--chunk", "--from-chunk"}, "N",
  2283. string_format("start processing the input from chunk N (default: %d)", params.i_chunk),
  2284. [](common_params & params, int value) {
  2285. params.i_chunk = value;
  2286. }
  2287. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2288. add_opt(common_arg(
  2289. {"--show-statistics"},
  2290. string_format("show imatrix statistics and then exit (default: %s)", params.show_statistics ? "true" : "false"),
  2291. [](common_params & params) {
  2292. params.show_statistics = true;
  2293. }
  2294. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2295. add_opt(common_arg(
  2296. {"--parse-special"},
  2297. string_format("parse special tokens (chat, tool, etc) (default: %s)", params.parse_special ? "true" : "false"),
  2298. [](common_params & params) {
  2299. params.parse_special = true;
  2300. }
  2301. ).set_examples({LLAMA_EXAMPLE_IMATRIX}));
  2302. add_opt(common_arg(
  2303. {"-pps"},
  2304. string_format("is the prompt shared across parallel sequences (default: %s)", params.is_pp_shared ? "true" : "false"),
  2305. [](common_params & params) {
  2306. params.is_pp_shared = true;
  2307. }
  2308. ).set_examples({LLAMA_EXAMPLE_BENCH, LLAMA_EXAMPLE_PARALLEL}));
  2309. add_opt(common_arg(
  2310. {"-tgs"},
  2311. string_format("is the text generation separated across the different sequences (default: %s)", params.is_tg_separate ? "true" : "false"),
  2312. [](common_params & params) {
  2313. params.is_tg_separate = true;
  2314. }
  2315. ).set_examples({LLAMA_EXAMPLE_BENCH, LLAMA_EXAMPLE_PARALLEL}));
  2316. add_opt(common_arg(
  2317. {"-npp"}, "n0,n1,...",
  2318. "number of prompt tokens",
  2319. [](common_params & params, const std::string & value) {
  2320. auto p = string_split<int>(value, ',');
  2321. params.n_pp.insert(params.n_pp.end(), p.begin(), p.end());
  2322. }
  2323. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  2324. add_opt(common_arg(
  2325. {"-ntg"}, "n0,n1,...",
  2326. "number of text generation tokens",
  2327. [](common_params & params, const std::string & value) {
  2328. auto p = string_split<int>(value, ',');
  2329. params.n_tg.insert(params.n_tg.end(), p.begin(), p.end());
  2330. }
  2331. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  2332. add_opt(common_arg(
  2333. {"-npl"}, "n0,n1,...",
  2334. "number of parallel prompts",
  2335. [](common_params & params, const std::string & value) {
  2336. auto p = string_split<int>(value, ',');
  2337. params.n_pl.insert(params.n_pl.end(), p.begin(), p.end());
  2338. }
  2339. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  2340. add_opt(common_arg(
  2341. {"--embd-normalize"}, "N",
  2342. string_format("normalisation for embeddings (default: %d) (-1=none, 0=max absolute int16, 1=taxicab, 2=euclidean, >2=p-norm)", params.embd_normalize),
  2343. [](common_params & params, int value) {
  2344. params.embd_normalize = value;
  2345. }
  2346. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  2347. add_opt(common_arg(
  2348. {"--embd-output-format"}, "FORMAT",
  2349. "empty = default, \"array\" = [[],[]...], \"json\" = openai style, \"json+\" = same \"json\" + cosine similarity matrix, \"raw\" = plain whitespace-delimited output (one embedding per line)",
  2350. [](common_params & params, const std::string & value) {
  2351. params.embd_out = value;
  2352. }
  2353. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  2354. add_opt(common_arg(
  2355. {"--embd-separator"}, "STRING",
  2356. "separator of embeddings (default \\n) for example \"<#sep#>\"",
  2357. [](common_params & params, const std::string & value) {
  2358. params.embd_sep = value;
  2359. }
  2360. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  2361. add_opt(common_arg(
  2362. {"--cls-separator"}, "STRING",
  2363. "separator of classification sequences (default \\t) for example \"<#seq#>\"",
  2364. [](common_params & params, const std::string & value) {
  2365. params.cls_sep = value;
  2366. }
  2367. ).set_examples({LLAMA_EXAMPLE_EMBEDDING}));
  2368. add_opt(common_arg(
  2369. {"--host"}, "HOST",
  2370. string_format("ip address to listen, or bind to an UNIX socket if the address ends with .sock (default: %s)", params.hostname.c_str()),
  2371. [](common_params & params, const std::string & value) {
  2372. params.hostname = value;
  2373. }
  2374. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_HOST"));
  2375. add_opt(common_arg(
  2376. {"--port"}, "PORT",
  2377. string_format("port to listen (default: %d)", params.port),
  2378. [](common_params & params, int value) {
  2379. params.port = value;
  2380. }
  2381. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_PORT"));
  2382. add_opt(common_arg(
  2383. {"--path"}, "PATH",
  2384. string_format("path to serve static files from (default: %s)", params.public_path.c_str()),
  2385. [](common_params & params, const std::string & value) {
  2386. params.public_path = value;
  2387. }
  2388. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_STATIC_PATH"));
  2389. add_opt(common_arg(
  2390. {"--api-prefix"}, "PREFIX",
  2391. string_format("prefix path the server serves from, without the trailing slash (default: %s)", params.api_prefix.c_str()),
  2392. [](common_params & params, const std::string & value) {
  2393. params.api_prefix = value;
  2394. }
  2395. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_API_PREFIX"));
  2396. add_opt(common_arg(
  2397. {"--webui"},
  2398. {"--no-webui"},
  2399. string_format("whether to enable the Web UI (default: %s)", params.webui ? "enabled" : "disabled"),
  2400. [](common_params & params, bool value) {
  2401. params.webui = value;
  2402. }
  2403. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_WEBUI"));
  2404. add_opt(common_arg(
  2405. {"--embedding", "--embeddings"},
  2406. string_format("restrict to only support embedding use case; use only with dedicated embedding models (default: %s)", params.embedding ? "enabled" : "disabled"),
  2407. [](common_params & params) {
  2408. params.embedding = true;
  2409. }
  2410. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_EMBEDDINGS"));
  2411. add_opt(common_arg(
  2412. {"--reranking", "--rerank"},
  2413. string_format("enable reranking endpoint on server (default: %s)", "disabled"),
  2414. [](common_params & params) {
  2415. params.embedding = true;
  2416. params.pooling_type = LLAMA_POOLING_TYPE_RANK;
  2417. }
  2418. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_RERANKING"));
  2419. add_opt(common_arg(
  2420. {"--api-key"}, "KEY",
  2421. "API key to use for authentication (default: none)",
  2422. [](common_params & params, const std::string & value) {
  2423. params.api_keys.push_back(value);
  2424. }
  2425. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_API_KEY"));
  2426. add_opt(common_arg(
  2427. {"--api-key-file"}, "FNAME",
  2428. "path to file containing API keys (default: none)",
  2429. [](common_params & params, const std::string & value) {
  2430. std::ifstream key_file(value);
  2431. if (!key_file) {
  2432. throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
  2433. }
  2434. std::string key;
  2435. while (std::getline(key_file, key)) {
  2436. if (!key.empty()) {
  2437. params.api_keys.push_back(key);
  2438. }
  2439. }
  2440. key_file.close();
  2441. }
  2442. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  2443. add_opt(common_arg(
  2444. {"--ssl-key-file"}, "FNAME",
  2445. "path to file a PEM-encoded SSL private key",
  2446. [](common_params & params, const std::string & value) {
  2447. params.ssl_file_key = value;
  2448. }
  2449. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_SSL_KEY_FILE"));
  2450. add_opt(common_arg(
  2451. {"--ssl-cert-file"}, "FNAME",
  2452. "path to file a PEM-encoded SSL certificate",
  2453. [](common_params & params, const std::string & value) {
  2454. params.ssl_file_cert = value;
  2455. }
  2456. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_SSL_CERT_FILE"));
  2457. add_opt(common_arg(
  2458. {"--chat-template-kwargs"}, "STRING",
  2459. string_format("sets additional params for the json template parser"),
  2460. [](common_params & params, const std::string & value) {
  2461. auto parsed = json::parse(value);
  2462. for (const auto & item : parsed.items()) {
  2463. params.default_template_kwargs[item.key()] = item.value().dump();
  2464. }
  2465. }
  2466. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_CHAT_TEMPLATE_KWARGS"));
  2467. add_opt(common_arg(
  2468. {"-to", "--timeout"}, "N",
  2469. string_format("server read/write timeout in seconds (default: %d)", params.timeout_read),
  2470. [](common_params & params, int value) {
  2471. params.timeout_read = value;
  2472. params.timeout_write = value;
  2473. }
  2474. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_TIMEOUT"));
  2475. add_opt(common_arg(
  2476. {"--threads-http"}, "N",
  2477. string_format("number of threads used to process HTTP requests (default: %d)", params.n_threads_http),
  2478. [](common_params & params, int value) {
  2479. params.n_threads_http = value;
  2480. }
  2481. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_THREADS_HTTP"));
  2482. add_opt(common_arg(
  2483. {"--cache-reuse"}, "N",
  2484. string_format(
  2485. "min chunk size to attempt reusing from the cache via KV shifting (default: %d)\n"
  2486. "[(card)](https://ggml.ai/f0.png)", params.n_cache_reuse
  2487. ),
  2488. [](common_params & params, int value) {
  2489. params.n_cache_reuse = value;
  2490. }
  2491. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CACHE_REUSE"));
  2492. add_opt(common_arg(
  2493. {"--metrics"},
  2494. string_format("enable prometheus compatible metrics endpoint (default: %s)", params.endpoint_metrics ? "enabled" : "disabled"),
  2495. [](common_params & params) {
  2496. params.endpoint_metrics = true;
  2497. }
  2498. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_METRICS"));
  2499. add_opt(common_arg(
  2500. {"--props"},
  2501. string_format("enable changing global properties via POST /props (default: %s)", params.endpoint_props ? "enabled" : "disabled"),
  2502. [](common_params & params) {
  2503. params.endpoint_props = true;
  2504. }
  2505. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_PROPS"));
  2506. add_opt(common_arg(
  2507. {"--slots"},
  2508. {"--no-slots"},
  2509. string_format("expose slots monitoring endpoint (default: %s)", params.endpoint_slots ? "enabled" : "disabled"),
  2510. [](common_params & params, bool value) {
  2511. params.endpoint_slots = value;
  2512. }
  2513. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_ENDPOINT_SLOTS"));
  2514. add_opt(common_arg(
  2515. {"--slot-save-path"}, "PATH",
  2516. "path to save slot kv cache (default: disabled)",
  2517. [](common_params & params, const std::string & value) {
  2518. params.slot_save_path = value;
  2519. if (!fs_is_directory(params.slot_save_path)) {
  2520. throw std::invalid_argument("not a directory: " + value);
  2521. }
  2522. // if doesn't end with DIRECTORY_SEPARATOR, add it
  2523. if (!params.slot_save_path.empty() && params.slot_save_path[params.slot_save_path.size() - 1] != DIRECTORY_SEPARATOR) {
  2524. params.slot_save_path += DIRECTORY_SEPARATOR;
  2525. }
  2526. }
  2527. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  2528. add_opt(common_arg(
  2529. {"--media-path"}, "PATH",
  2530. "directory for loading local media files; files can be accessed via file:// URLs using relative paths (default: disabled)",
  2531. [](common_params & params, const std::string & value) {
  2532. params.media_path = value;
  2533. if (!fs_is_directory(params.media_path)) {
  2534. throw std::invalid_argument("not a directory: " + value);
  2535. }
  2536. // if doesn't end with DIRECTORY_SEPARATOR, add it
  2537. if (!params.media_path.empty() && params.media_path[params.media_path.size() - 1] != DIRECTORY_SEPARATOR) {
  2538. params.media_path += DIRECTORY_SEPARATOR;
  2539. }
  2540. }
  2541. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  2542. add_opt(common_arg(
  2543. {"--models-dir"}, "PATH",
  2544. "directory containing models for the router server (default: disabled)",
  2545. [](common_params & params, const std::string & value) {
  2546. params.models_dir = value;
  2547. }
  2548. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_MODELS_DIR"));
  2549. add_opt(common_arg(
  2550. {"--models-preset"}, "PATH",
  2551. "path to INI file containing model presets for the router server (default: disabled)",
  2552. [](common_params & params, const std::string & value) {
  2553. params.models_preset = value;
  2554. }
  2555. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_MODELS_PRESET"));
  2556. add_opt(common_arg(
  2557. {"--models-max"}, "N",
  2558. string_format("for router server, maximum number of models to load simultaneously (default: %d, 0 = unlimited)", params.models_max),
  2559. [](common_params & params, int value) {
  2560. params.models_max = value;
  2561. }
  2562. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_MODELS_MAX"));
  2563. add_opt(common_arg(
  2564. {"--models-autoload"},
  2565. {"--no-models-autoload"},
  2566. string_format("for router server, whether to automatically load models (default: %s)", params.models_autoload ? "enabled" : "disabled"),
  2567. [](common_params & params, bool value) {
  2568. params.models_autoload = value;
  2569. }
  2570. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_MODELS_AUTOLOAD"));
  2571. add_opt(common_arg(
  2572. {"--jinja"},
  2573. {"--no-jinja"},
  2574. string_format("whether to use jinja template engine for chat (default: %s)", params.use_jinja ? "enabled" : "disabled"),
  2575. [](common_params & params, bool value) {
  2576. params.use_jinja = value;
  2577. }
  2578. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_MTMD}).set_env("LLAMA_ARG_JINJA"));
  2579. add_opt(common_arg(
  2580. {"--reasoning-format"}, "FORMAT",
  2581. "controls whether thought tags are allowed and/or extracted from the response, and in which format they're returned; one of:\n"
  2582. "- none: leaves thoughts unparsed in `message.content`\n"
  2583. "- deepseek: puts thoughts in `message.reasoning_content`\n"
  2584. "- deepseek-legacy: keeps `<think>` tags in `message.content` while also populating `message.reasoning_content`\n"
  2585. "(default: auto)",
  2586. [](common_params & params, const std::string & value) {
  2587. params.reasoning_format = common_reasoning_format_from_name(value);
  2588. }
  2589. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_THINK"));
  2590. add_opt(common_arg(
  2591. {"--reasoning-budget"}, "N",
  2592. "controls the amount of thinking allowed; currently only one of: -1 for unrestricted thinking budget, or 0 to disable thinking (default: -1)",
  2593. [](common_params & params, int value) {
  2594. if (value != 0 && value != -1) { throw std::invalid_argument("invalid value"); }
  2595. params.reasoning_budget = value;
  2596. }
  2597. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_THINK_BUDGET"));
  2598. add_opt(common_arg(
  2599. {"--chat-template"}, "JINJA_TEMPLATE",
  2600. string_format(
  2601. "set custom jinja chat template (default: template taken from model's metadata)\n"
  2602. "if suffix/prefix are specified, template will be disabled\n"
  2603. "only commonly used templates are accepted (unless --jinja is set before this flag):\n"
  2604. "list of built-in templates:\n%s", list_builtin_chat_templates().c_str()
  2605. ),
  2606. [](common_params & params, const std::string & value) {
  2607. params.chat_template = value;
  2608. }
  2609. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_MTMD}).set_env("LLAMA_ARG_CHAT_TEMPLATE"));
  2610. add_opt(common_arg(
  2611. {"--chat-template-file"}, "JINJA_TEMPLATE_FILE",
  2612. string_format(
  2613. "set custom jinja chat template file (default: template taken from model's metadata)\n"
  2614. "if suffix/prefix are specified, template will be disabled\n"
  2615. "only commonly used templates are accepted (unless --jinja is set before this flag):\n"
  2616. "list of built-in templates:\n%s", list_builtin_chat_templates().c_str()
  2617. ),
  2618. [](common_params & params, const std::string & value) {
  2619. params.chat_template = read_file(value);
  2620. }
  2621. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI, LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_CHAT_TEMPLATE_FILE"));
  2622. add_opt(common_arg(
  2623. {"--prefill-assistant"},
  2624. {"--no-prefill-assistant"},
  2625. string_format(
  2626. "whether to prefill the assistant's response if the last message is an assistant message (default: prefill enabled)\n"
  2627. "when this flag is set, if the last message is an assistant message then it will be treated as a full message and not prefilled\n"
  2628. ),
  2629. [](common_params & params, bool value) {
  2630. params.prefill_assistant = value;
  2631. }
  2632. ).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_PREFILL_ASSISTANT"));
  2633. add_opt(common_arg(
  2634. {"-sps", "--slot-prompt-similarity"}, "SIMILARITY",
  2635. 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),
  2636. [](common_params & params, const std::string & value) {
  2637. params.slot_prompt_similarity = std::stof(value);
  2638. }
  2639. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  2640. add_opt(common_arg(
  2641. {"--lora-init-without-apply"},
  2642. string_format("load LoRA adapters without applying them (apply later via POST /lora-adapters) (default: %s)", params.lora_init_without_apply ? "enabled" : "disabled"),
  2643. [](common_params & params) {
  2644. params.lora_init_without_apply = true;
  2645. }
  2646. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  2647. add_opt(common_arg(
  2648. {"--simple-io"},
  2649. "use basic IO for better compatibility in subprocesses and limited consoles",
  2650. [](common_params & params) {
  2651. params.simple_io = true;
  2652. }
  2653. ).set_examples({LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}));
  2654. add_opt(common_arg(
  2655. {"--positive-file"}, "FNAME",
  2656. string_format("positive prompts file, one prompt per line (default: '%s')", params.cvector_positive_file.c_str()),
  2657. [](common_params & params, const std::string & value) {
  2658. params.cvector_positive_file = value;
  2659. }
  2660. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  2661. add_opt(common_arg(
  2662. {"--negative-file"}, "FNAME",
  2663. string_format("negative prompts file, one prompt per line (default: '%s')", params.cvector_negative_file.c_str()),
  2664. [](common_params & params, const std::string & value) {
  2665. params.cvector_negative_file = value;
  2666. }
  2667. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  2668. add_opt(common_arg(
  2669. {"--pca-batch"}, "N",
  2670. string_format("batch size used for PCA. Larger batch runs faster, but uses more memory (default: %d)", params.n_pca_batch),
  2671. [](common_params & params, int value) {
  2672. params.n_pca_batch = value;
  2673. }
  2674. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  2675. add_opt(common_arg(
  2676. {"--pca-iter"}, "N",
  2677. string_format("number of iterations used for PCA (default: %d)", params.n_pca_iterations),
  2678. [](common_params & params, int value) {
  2679. params.n_pca_iterations = value;
  2680. }
  2681. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  2682. add_opt(common_arg(
  2683. {"--method"}, "{pca, mean}",
  2684. "dimensionality reduction method to be used (default: pca)",
  2685. [](common_params & params, const std::string & value) {
  2686. /**/ if (value == "pca") { params.cvector_dimre_method = DIMRE_METHOD_PCA; }
  2687. else if (value == "mean") { params.cvector_dimre_method = DIMRE_METHOD_MEAN; }
  2688. else { throw std::invalid_argument("invalid value"); }
  2689. }
  2690. ).set_examples({LLAMA_EXAMPLE_CVECTOR_GENERATOR}));
  2691. add_opt(common_arg(
  2692. {"--output-format"}, "{md,jsonl}",
  2693. "output format for batched-bench results (default: md)",
  2694. [](common_params & params, const std::string & value) {
  2695. /**/ if (value == "jsonl") { params.batched_bench_output_jsonl = true; }
  2696. else if (value == "md") { params.batched_bench_output_jsonl = false; }
  2697. else { throw std::invalid_argument("invalid value"); }
  2698. }
  2699. ).set_examples({LLAMA_EXAMPLE_BENCH}));
  2700. add_opt(common_arg(
  2701. {"--log-disable"},
  2702. "Log disable",
  2703. [](common_params &) {
  2704. common_log_pause(common_log_main());
  2705. }
  2706. ));
  2707. add_opt(common_arg(
  2708. {"--log-file"}, "FNAME",
  2709. "Log to file",
  2710. [](common_params &, const std::string & value) {
  2711. common_log_set_file(common_log_main(), value.c_str());
  2712. }
  2713. ).set_env("LLAMA_LOG_FILE"));
  2714. add_opt(common_arg(
  2715. {"--log-colors"}, "[on|off|auto]",
  2716. "Set colored logging ('on', 'off', or 'auto', default: 'auto')\n"
  2717. "'auto' enables colors when output is to a terminal",
  2718. [](common_params &, const std::string & value) {
  2719. if (is_truthy(value)) {
  2720. common_log_set_colors(common_log_main(), LOG_COLORS_ENABLED);
  2721. } else if (is_falsey(value)) {
  2722. common_log_set_colors(common_log_main(), LOG_COLORS_DISABLED);
  2723. } else if (is_autoy(value)) {
  2724. common_log_set_colors(common_log_main(), LOG_COLORS_AUTO);
  2725. } else {
  2726. throw std::invalid_argument(
  2727. string_format("error: unknown value for --log-colors: '%s'\n", value.c_str()));
  2728. }
  2729. }
  2730. ).set_env("LLAMA_LOG_COLORS"));
  2731. add_opt(common_arg(
  2732. {"-v", "--verbose", "--log-verbose"},
  2733. "Set verbosity level to infinity (i.e. log all messages, useful for debugging)",
  2734. [](common_params & params) {
  2735. params.verbosity = INT_MAX;
  2736. }
  2737. ));
  2738. add_opt(common_arg(
  2739. {"--offline"},
  2740. "Offline mode: forces use of cache, prevents network access",
  2741. [](common_params & params) {
  2742. params.offline = true;
  2743. }
  2744. ).set_env("LLAMA_OFFLINE"));
  2745. add_opt(common_arg(
  2746. {"-lv", "--verbosity", "--log-verbosity"}, "N",
  2747. string_format("Set the verbosity threshold. Messages with a higher verbosity will be ignored. Values:\n"
  2748. " - 0: generic output\n"
  2749. " - 1: error\n"
  2750. " - 2: warning\n"
  2751. " - 3: info\n"
  2752. " - 4: debug\n"
  2753. "(default: %d)\n", params.verbosity),
  2754. [](common_params & params, int value) {
  2755. params.verbosity = value;
  2756. }
  2757. ).set_env("LLAMA_LOG_VERBOSITY"));
  2758. add_opt(common_arg(
  2759. {"--log-prefix"},
  2760. "Enable prefix in log messages",
  2761. [](common_params &) {
  2762. common_log_set_prefix(common_log_main(), true);
  2763. }
  2764. ).set_env("LLAMA_LOG_PREFIX"));
  2765. add_opt(common_arg(
  2766. {"--log-timestamps"},
  2767. "Enable timestamps in log messages",
  2768. [](common_params &) {
  2769. common_log_set_timestamps(common_log_main(), true);
  2770. }
  2771. ).set_env("LLAMA_LOG_TIMESTAMPS"));
  2772. // speculative parameters
  2773. add_opt(common_arg(
  2774. {"-td", "--threads-draft"}, "N",
  2775. "number of threads to use during generation (default: same as --threads)",
  2776. [](common_params & params, int value) {
  2777. params.speculative.cpuparams.n_threads = value;
  2778. if (params.speculative.cpuparams.n_threads <= 0) {
  2779. params.speculative.cpuparams.n_threads = std::thread::hardware_concurrency();
  2780. }
  2781. }
  2782. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER}));
  2783. add_opt(common_arg(
  2784. {"-tbd", "--threads-batch-draft"}, "N",
  2785. "number of threads to use during batch and prompt processing (default: same as --threads-draft)",
  2786. [](common_params & params, int value) {
  2787. params.speculative.cpuparams_batch.n_threads = value;
  2788. if (params.speculative.cpuparams_batch.n_threads <= 0) {
  2789. params.speculative.cpuparams_batch.n_threads = std::thread::hardware_concurrency();
  2790. }
  2791. }
  2792. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER}));
  2793. add_opt(common_arg(
  2794. {"-Cd", "--cpu-mask-draft"}, "M",
  2795. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  2796. [](common_params & params, const std::string & mask) {
  2797. params.speculative.cpuparams.mask_valid = true;
  2798. if (!parse_cpu_mask(mask, params.speculative.cpuparams.cpumask)) {
  2799. throw std::invalid_argument("invalid cpumask");
  2800. }
  2801. }
  2802. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2803. add_opt(common_arg(
  2804. {"-Crd", "--cpu-range-draft"}, "lo-hi",
  2805. "Ranges of CPUs for affinity. Complements --cpu-mask-draft",
  2806. [](common_params & params, const std::string & range) {
  2807. params.speculative.cpuparams.mask_valid = true;
  2808. if (!parse_cpu_range(range, params.speculative.cpuparams.cpumask)) {
  2809. throw std::invalid_argument("invalid range");
  2810. }
  2811. }
  2812. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2813. add_opt(common_arg(
  2814. {"--cpu-strict-draft"}, "<0|1>",
  2815. "Use strict CPU placement for draft model (default: same as --cpu-strict)",
  2816. [](common_params & params, int value) {
  2817. params.speculative.cpuparams.strict_cpu = value;
  2818. }
  2819. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2820. add_opt(common_arg(
  2821. {"--prio-draft"}, "N",
  2822. string_format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.speculative.cpuparams.priority),
  2823. [](common_params & params, int prio) {
  2824. if (prio < 0 || prio > 3) {
  2825. throw std::invalid_argument("invalid value");
  2826. }
  2827. params.speculative.cpuparams.priority = (enum ggml_sched_priority) prio;
  2828. }
  2829. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2830. add_opt(common_arg(
  2831. {"--poll-draft"}, "<0|1>",
  2832. "Use polling to wait for draft model work (default: same as --poll])",
  2833. [](common_params & params, int value) {
  2834. params.speculative.cpuparams.poll = value;
  2835. }
  2836. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2837. add_opt(common_arg(
  2838. {"-Cbd", "--cpu-mask-batch-draft"}, "M",
  2839. "Draft model CPU affinity mask. Complements cpu-range-draft (default: same as --cpu-mask)",
  2840. [](common_params & params, const std::string & mask) {
  2841. params.speculative.cpuparams_batch.mask_valid = true;
  2842. if (!parse_cpu_mask(mask, params.speculative.cpuparams_batch.cpumask)) {
  2843. throw std::invalid_argument("invalid cpumask");
  2844. }
  2845. }
  2846. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2847. add_opt(common_arg(
  2848. {"-Crbd", "--cpu-range-batch-draft"}, "lo-hi",
  2849. "Ranges of CPUs for affinity. Complements --cpu-mask-draft-batch)",
  2850. [](common_params & params, const std::string & range) {
  2851. params.speculative.cpuparams_batch.mask_valid = true;
  2852. if (!parse_cpu_range(range, params.speculative.cpuparams_batch.cpumask)) {
  2853. throw std::invalid_argument("invalid cpumask");
  2854. }
  2855. }
  2856. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2857. add_opt(common_arg(
  2858. {"--cpu-strict-batch-draft"}, "<0|1>",
  2859. "Use strict CPU placement for draft model (default: --cpu-strict-draft)",
  2860. [](common_params & params, int value) {
  2861. params.speculative.cpuparams_batch.strict_cpu = value;
  2862. }
  2863. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2864. add_opt(common_arg(
  2865. {"--prio-batch-draft"}, "N",
  2866. string_format("set draft process/thread priority : 0-normal, 1-medium, 2-high, 3-realtime (default: %d)\n", params.speculative.cpuparams_batch.priority),
  2867. [](common_params & params, int prio) {
  2868. if (prio < 0 || prio > 3) {
  2869. throw std::invalid_argument("invalid value");
  2870. }
  2871. params.speculative.cpuparams_batch.priority = (enum ggml_sched_priority) prio;
  2872. }
  2873. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2874. add_opt(common_arg(
  2875. {"--poll-batch-draft"}, "<0|1>",
  2876. "Use polling to wait for draft model work (default: --poll-draft)",
  2877. [](common_params & params, int value) {
  2878. params.speculative.cpuparams_batch.poll = value;
  2879. }
  2880. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}));
  2881. add_opt(common_arg(
  2882. {"--draft-max", "--draft", "--draft-n"}, "N",
  2883. string_format("number of tokens to draft for speculative decoding (default: %d)", params.speculative.n_max),
  2884. [](common_params & params, int value) {
  2885. params.speculative.n_max = value;
  2886. }
  2887. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_DRAFT_MAX"));
  2888. add_opt(common_arg(
  2889. {"--draft-min", "--draft-n-min"}, "N",
  2890. string_format("minimum number of draft tokens to use for speculative decoding (default: %d)", params.speculative.n_min),
  2891. [](common_params & params, int value) {
  2892. params.speculative.n_min = value;
  2893. }
  2894. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_LOOKUP, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_DRAFT_MIN"));
  2895. add_opt(common_arg(
  2896. {"--draft-p-split"}, "P",
  2897. string_format("speculative decoding split probability (default: %.1f)", (double)params.speculative.p_split),
  2898. [](common_params & params, const std::string & value) {
  2899. params.speculative.p_split = std::stof(value);
  2900. }
  2901. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE}).set_env("LLAMA_ARG_DRAFT_P_SPLIT"));
  2902. add_opt(common_arg(
  2903. {"--draft-p-min"}, "P",
  2904. string_format("minimum speculative decoding probability (greedy) (default: %.1f)", (double)params.speculative.p_min),
  2905. [](common_params & params, const std::string & value) {
  2906. params.speculative.p_min = std::stof(value);
  2907. }
  2908. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_DRAFT_P_MIN"));
  2909. add_opt(common_arg(
  2910. {"-cd", "--ctx-size-draft"}, "N",
  2911. string_format("size of the prompt context for the draft model (default: %d, 0 = loaded from model)", params.speculative.n_ctx),
  2912. [](common_params & params, int value) {
  2913. params.speculative.n_ctx = value;
  2914. }
  2915. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_CTX_SIZE_DRAFT"));
  2916. add_opt(common_arg(
  2917. {"-devd", "--device-draft"}, "<dev1,dev2,..>",
  2918. "comma-separated list of devices to use for offloading the draft model (none = don't offload)\n"
  2919. "use --list-devices to see a list of available devices",
  2920. [](common_params & params, const std::string & value) {
  2921. params.speculative.devices = parse_device_list(value);
  2922. }
  2923. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  2924. add_opt(common_arg(
  2925. {"-ngld", "--gpu-layers-draft", "--n-gpu-layers-draft"}, "N",
  2926. "number of layers to store in VRAM for the draft model",
  2927. [](common_params & params, int value) {
  2928. params.speculative.n_gpu_layers = value;
  2929. if (!llama_supports_gpu_offload()) {
  2930. fprintf(stderr, "warning: no usable GPU found, --gpu-layers-draft option will be ignored\n");
  2931. fprintf(stderr, "warning: one possible reason is that llama.cpp was compiled without GPU support\n");
  2932. fprintf(stderr, "warning: consult docs/build.md for compilation instructions\n");
  2933. }
  2934. }
  2935. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_N_GPU_LAYERS_DRAFT"));
  2936. add_opt(common_arg(
  2937. {"-md", "--model-draft"}, "FNAME",
  2938. "draft model for speculative decoding (default: unused)",
  2939. [](common_params & params, const std::string & value) {
  2940. params.speculative.model.path = value;
  2941. }
  2942. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_MODEL_DRAFT"));
  2943. add_opt(common_arg(
  2944. {"--spec-replace"}, "TARGET", "DRAFT",
  2945. "translate the string in TARGET into DRAFT if the draft model and main model are not compatible",
  2946. [](common_params & params, const std::string & tgt, const std::string & dft) {
  2947. params.speculative.replacements.push_back({ tgt, dft });
  2948. }
  2949. ).set_examples({LLAMA_EXAMPLE_SPECULATIVE, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  2950. add_opt(common_arg(
  2951. {"-ctkd", "--cache-type-k-draft"}, "TYPE",
  2952. string_format(
  2953. "KV cache data type for K for the draft model\n"
  2954. "allowed values: %s\n"
  2955. "(default: %s)",
  2956. get_all_kv_cache_types().c_str(),
  2957. ggml_type_name(params.speculative.cache_type_k)
  2958. ),
  2959. [](common_params & params, const std::string & value) {
  2960. params.speculative.cache_type_k = kv_cache_type_from_str(value);
  2961. }
  2962. ).set_env("LLAMA_ARG_CACHE_TYPE_K_DRAFT"));
  2963. add_opt(common_arg(
  2964. {"-ctvd", "--cache-type-v-draft"}, "TYPE",
  2965. string_format(
  2966. "KV cache data type for V for the draft model\n"
  2967. "allowed values: %s\n"
  2968. "(default: %s)",
  2969. get_all_kv_cache_types().c_str(),
  2970. ggml_type_name(params.speculative.cache_type_v)
  2971. ),
  2972. [](common_params & params, const std::string & value) {
  2973. params.speculative.cache_type_v = kv_cache_type_from_str(value);
  2974. }
  2975. ).set_env("LLAMA_ARG_CACHE_TYPE_V_DRAFT"));
  2976. add_opt(common_arg(
  2977. {"-mv", "--model-vocoder"}, "FNAME",
  2978. "vocoder model for audio generation (default: unused)",
  2979. [](common_params & params, const std::string & value) {
  2980. params.vocoder.model.path = value;
  2981. }
  2982. ).set_examples({LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_SERVER}));
  2983. add_opt(common_arg(
  2984. {"--tts-use-guide-tokens"},
  2985. "Use guide tokens to improve TTS word recall",
  2986. [](common_params & params) {
  2987. params.vocoder.use_guide_tokens = true;
  2988. }
  2989. ).set_examples({LLAMA_EXAMPLE_TTS, LLAMA_EXAMPLE_SERVER}));
  2990. add_opt(common_arg(
  2991. {"--tts-speaker-file"}, "FNAME",
  2992. "speaker file path for audio generation",
  2993. [](common_params & params, const std::string & value) {
  2994. params.vocoder.speaker_file = value;
  2995. }
  2996. ).set_examples({LLAMA_EXAMPLE_TTS}));
  2997. add_opt(common_arg(
  2998. {"--diffusion-steps"}, "N",
  2999. string_format("number of diffusion steps (default: %d)", params.diffusion.steps),
  3000. [](common_params & params, int value) { params.diffusion.steps = value; }
  3001. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3002. add_opt(common_arg(
  3003. {"--diffusion-visual"},
  3004. string_format("enable visual diffusion mode (show progressive generation) (default: %s)", params.diffusion.visual_mode ? "true" : "false"),
  3005. [](common_params & params) { params.diffusion.visual_mode = true; }
  3006. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3007. add_opt(common_arg(
  3008. {"--diffusion-eps"}, "F",
  3009. string_format("epsilon for timesteps (default: %.6f)", (double) params.diffusion.eps),
  3010. [](common_params & params, const std::string & value) { params.diffusion.eps = std::stof(value); }
  3011. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3012. add_opt(common_arg(
  3013. {"--diffusion-algorithm"}, "N",
  3014. string_format("diffusion algorithm: 0=ORIGIN, 1=ENTROPY_BASED, 2=MARGIN_BASED, 3=RANDOM, 4=LOW_CONFIDENCE (default: %d)", params.diffusion.algorithm),
  3015. [](common_params & params, int value) { params.diffusion.algorithm = value; }
  3016. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3017. add_opt(common_arg(
  3018. {"--diffusion-alg-temp"}, "F",
  3019. string_format("dream algorithm temperature (default: %.3f)", (double) params.diffusion.alg_temp),
  3020. [](common_params & params, const std::string & value) { params.diffusion.alg_temp = std::stof(value); }
  3021. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3022. add_opt(common_arg(
  3023. {"--diffusion-block-length"}, "N",
  3024. string_format("llada block length for generation (default: %d)", params.diffusion.block_length),
  3025. [](common_params & params, int value) { params.diffusion.block_length = value; }
  3026. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3027. add_opt(common_arg(
  3028. {"--diffusion-cfg-scale"}, "F",
  3029. string_format("llada classifier-free guidance scale (default: %.3f)", (double) params.diffusion.cfg_scale),
  3030. [](common_params & params, const std::string & value) { params.diffusion.cfg_scale = std::stof(value); }
  3031. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3032. add_opt(common_arg(
  3033. {"--diffusion-add-gumbel-noise"}, "F",
  3034. string_format("add gumbel noise to the logits if temp > 0.0 (default: %s)", params.diffusion.add_gumbel_noise ? "true" : "false"),
  3035. [](common_params & params, const std::string & value) { params.diffusion.add_gumbel_noise = std::stof(value); }
  3036. ).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
  3037. add_opt(common_arg(
  3038. { "-lr", "--learning-rate" }, "ALPHA",
  3039. string_format("adamw or sgd optimizer alpha (default: %.2g); note: sgd alpha recommended ~10x (no momentum)", (double) params.lr.lr0),
  3040. [](common_params & params, const std::string & value) { params.lr.lr0 = std::stof(value); }
  3041. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3042. add_opt(common_arg({ "-lr-min", "--learning-rate-min" }, "ALPHA",
  3043. string_format("(if >0) final learning rate after decay (if -decay-epochs is set, default=%.2g)",
  3044. (double) params.lr.lr_min),
  3045. [](common_params & params, const std::string & value) { params.lr.lr_min = std::stof(value); }
  3046. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3047. add_opt(common_arg(
  3048. {"-decay-epochs", "--learning-rate-decay-epochs"}, "ALPHA",
  3049. string_format("(if >0) decay learning rate to -lr-min after this many epochs (exponential decay, default=%.2g)", (double) params.lr.decay_epochs),
  3050. [](common_params & params, const std::string & value) { params.lr.decay_epochs = std::stof(value); }
  3051. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3052. add_opt(common_arg(
  3053. {"-wd", "--weight-decay"}, "WD",
  3054. string_format("adamw or sgd optimizer weight decay (0 is off; recommend very small e.g. 1e-9) (default: %.2g).", (double) params.lr.wd),
  3055. [](common_params & params, const std::string & value) { params.lr.wd = std::stof(value); }
  3056. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3057. add_opt(common_arg(
  3058. {"-val-split", "--val-split"}, "FRACTION",
  3059. string_format("fraction of data to use as validation set for training (default: %.2g).", (double) params.val_split),
  3060. [](common_params & params, const std::string & value) { params.val_split = std::stof(value); }
  3061. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3062. add_opt(common_arg(
  3063. {"-epochs", "--epochs"}, "N",
  3064. string_format("optimizer max # of epochs (default: %d)", params.lr.epochs),
  3065. [](common_params & params, int epochs) { params.lr.epochs = epochs; }
  3066. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3067. add_opt(common_arg(
  3068. {"-opt", "--optimizer"}, "sgd|adamw", "adamw or sgd",
  3069. [](common_params & params, const std::string & name) {
  3070. params.optimizer = common_opt_get_optimizer(name.c_str());
  3071. if (params.optimizer == GGML_OPT_OPTIMIZER_TYPE_COUNT) {
  3072. throw std::invalid_argument("invalid --optimizer, valid options: adamw, sgd");
  3073. }
  3074. }
  3075. ).set_examples({ LLAMA_EXAMPLE_FINETUNE }));
  3076. // presets
  3077. add_opt(common_arg(
  3078. {"--tts-oute-default"},
  3079. string_format("use default OuteTTS models (note: can download weights from the internet)"),
  3080. [](common_params & params) {
  3081. params.model.hf_repo = "OuteAI/OuteTTS-0.2-500M-GGUF";
  3082. params.model.hf_file = "OuteTTS-0.2-500M-Q8_0.gguf";
  3083. params.vocoder.model.hf_repo = "ggml-org/WavTokenizer";
  3084. params.vocoder.model.hf_file = "WavTokenizer-Large-75-F16.gguf";
  3085. }
  3086. ).set_examples({LLAMA_EXAMPLE_TTS}));
  3087. add_opt(common_arg(
  3088. {"--embd-gemma-default"},
  3089. string_format("use default EmbeddingGemma model (note: can download weights from the internet)"),
  3090. [](common_params & params) {
  3091. params.model.hf_repo = "ggml-org/embeddinggemma-300M-qat-q4_0-GGUF";
  3092. params.model.hf_file = "embeddinggemma-300M-qat-Q4_0.gguf";
  3093. params.port = 8011;
  3094. params.n_ubatch = 2048;
  3095. params.n_batch = 2048;
  3096. params.n_parallel = 32;
  3097. params.n_ctx = 2048*params.n_parallel;
  3098. params.verbose_prompt = true;
  3099. params.embedding = true;
  3100. }
  3101. ).set_examples({LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_SERVER}));
  3102. add_opt(common_arg(
  3103. {"--fim-qwen-1.5b-default"},
  3104. string_format("use default Qwen 2.5 Coder 1.5B (note: can download weights from the internet)"),
  3105. [](common_params & params) {
  3106. params.model.hf_repo = "ggml-org/Qwen2.5-Coder-1.5B-Q8_0-GGUF";
  3107. params.model.hf_file = "qwen2.5-coder-1.5b-q8_0.gguf";
  3108. params.port = 8012;
  3109. params.n_ubatch = 1024;
  3110. params.n_batch = 1024;
  3111. params.n_ctx = 0;
  3112. params.n_cache_reuse = 256;
  3113. }
  3114. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3115. add_opt(common_arg(
  3116. {"--fim-qwen-3b-default"},
  3117. string_format("use default Qwen 2.5 Coder 3B (note: can download weights from the internet)"),
  3118. [](common_params & params) {
  3119. params.model.hf_repo = "ggml-org/Qwen2.5-Coder-3B-Q8_0-GGUF";
  3120. params.model.hf_file = "qwen2.5-coder-3b-q8_0.gguf";
  3121. params.port = 8012;
  3122. params.n_ubatch = 1024;
  3123. params.n_batch = 1024;
  3124. params.n_ctx = 0;
  3125. params.n_cache_reuse = 256;
  3126. }
  3127. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3128. add_opt(common_arg(
  3129. {"--fim-qwen-7b-default"},
  3130. string_format("use default Qwen 2.5 Coder 7B (note: can download weights from the internet)"),
  3131. [](common_params & params) {
  3132. params.model.hf_repo = "ggml-org/Qwen2.5-Coder-7B-Q8_0-GGUF";
  3133. params.model.hf_file = "qwen2.5-coder-7b-q8_0.gguf";
  3134. params.port = 8012;
  3135. params.n_ubatch = 1024;
  3136. params.n_batch = 1024;
  3137. params.n_ctx = 0;
  3138. params.n_cache_reuse = 256;
  3139. }
  3140. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3141. add_opt(common_arg(
  3142. {"--fim-qwen-7b-spec"},
  3143. string_format("use Qwen 2.5 Coder 7B + 0.5B draft for speculative decoding (note: can download weights from the internet)"),
  3144. [](common_params & params) {
  3145. params.model.hf_repo = "ggml-org/Qwen2.5-Coder-7B-Q8_0-GGUF";
  3146. params.model.hf_file = "qwen2.5-coder-7b-q8_0.gguf";
  3147. params.speculative.model.hf_repo = "ggml-org/Qwen2.5-Coder-0.5B-Q8_0-GGUF";
  3148. params.speculative.model.hf_file = "qwen2.5-coder-0.5b-q8_0.gguf";
  3149. params.port = 8012;
  3150. params.n_ubatch = 1024;
  3151. params.n_batch = 1024;
  3152. params.n_ctx = 0;
  3153. params.n_cache_reuse = 256;
  3154. }
  3155. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3156. add_opt(common_arg(
  3157. {"--fim-qwen-14b-spec"},
  3158. string_format("use Qwen 2.5 Coder 14B + 0.5B draft for speculative decoding (note: can download weights from the internet)"),
  3159. [](common_params & params) {
  3160. params.model.hf_repo = "ggml-org/Qwen2.5-Coder-14B-Q8_0-GGUF";
  3161. params.model.hf_file = "qwen2.5-coder-14b-q8_0.gguf";
  3162. params.speculative.model.hf_repo = "ggml-org/Qwen2.5-Coder-0.5B-Q8_0-GGUF";
  3163. params.speculative.model.hf_file = "qwen2.5-coder-0.5b-q8_0.gguf";
  3164. params.port = 8012;
  3165. params.n_ubatch = 1024;
  3166. params.n_batch = 1024;
  3167. params.n_ctx = 0;
  3168. params.n_cache_reuse = 256;
  3169. }
  3170. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3171. add_opt(common_arg(
  3172. {"--fim-qwen-30b-default"},
  3173. string_format("use default Qwen 3 Coder 30B A3B Instruct (note: can download weights from the internet)"),
  3174. [](common_params & params) {
  3175. params.model.hf_repo = "ggml-org/Qwen3-Coder-30B-A3B-Instruct-Q8_0-GGUF";
  3176. params.model.hf_file = "qwen3-coder-30b-a3b-instruct-q8_0.gguf";
  3177. params.port = 8012;
  3178. params.n_ubatch = 1024;
  3179. params.n_batch = 1024;
  3180. params.n_ctx = 0;
  3181. params.n_cache_reuse = 256;
  3182. }
  3183. ).set_examples({LLAMA_EXAMPLE_SERVER}));
  3184. add_opt(common_arg(
  3185. {"--gpt-oss-20b-default"},
  3186. string_format("use gpt-oss-20b (note: can download weights from the internet)"),
  3187. [](common_params & params) {
  3188. params.model.hf_repo = "ggml-org/gpt-oss-20b-GGUF";
  3189. params.model.hf_file = "gpt-oss-20b-mxfp4.gguf";
  3190. params.port = 8013;
  3191. params.n_ubatch = 2048;
  3192. params.n_batch = 32768;
  3193. params.n_parallel = 2;
  3194. params.n_ctx = 131072*params.n_parallel;
  3195. params.sampling.temp = 1.0f;
  3196. params.sampling.top_p = 1.0f;
  3197. params.sampling.top_k = 0;
  3198. params.sampling.min_p = 0.01f;
  3199. params.use_jinja = true;
  3200. //params.default_template_kwargs["reasoning_effort"] = "\"high\"";
  3201. }
  3202. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  3203. add_opt(common_arg(
  3204. {"--gpt-oss-120b-default"},
  3205. string_format("use gpt-oss-120b (note: can download weights from the internet)"),
  3206. [](common_params & params) {
  3207. params.model.hf_repo = "ggml-org/gpt-oss-120b-GGUF";
  3208. params.port = 8013;
  3209. params.n_ubatch = 2048;
  3210. params.n_batch = 32768;
  3211. params.n_parallel = 2;
  3212. params.n_ctx = 131072*params.n_parallel;
  3213. params.sampling.temp = 1.0f;
  3214. params.sampling.top_p = 1.0f;
  3215. params.sampling.top_k = 0;
  3216. params.sampling.min_p = 0.01f;
  3217. params.use_jinja = true;
  3218. //params.default_template_kwargs["reasoning_effort"] = "\"high\"";
  3219. }
  3220. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  3221. add_opt(common_arg(
  3222. {"--vision-gemma-4b-default"},
  3223. string_format("use Gemma 3 4B QAT (note: can download weights from the internet)"),
  3224. [](common_params & params) {
  3225. params.model.hf_repo = "ggml-org/gemma-3-4b-it-qat-GGUF";
  3226. params.port = 8014;
  3227. params.n_ctx = 0;
  3228. params.use_jinja = true;
  3229. }
  3230. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  3231. add_opt(common_arg(
  3232. {"--vision-gemma-12b-default"},
  3233. string_format("use Gemma 3 12B QAT (note: can download weights from the internet)"),
  3234. [](common_params & params) {
  3235. params.model.hf_repo = "ggml-org/gemma-3-12b-it-qat-GGUF";
  3236. params.port = 8014;
  3237. params.n_ctx = 0;
  3238. params.use_jinja = true;
  3239. }
  3240. ).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}));
  3241. return ctx_arg;
  3242. }