1
0

arg.cpp 144 KB

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