arg.cpp 142 KB

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