arg.cpp 146 KB

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