arg.cpp 148 KB

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