@@ -1265,6 +1265,18 @@ static std::string list_builtin_chat_templates() {
12651265 return msg.str ();
12661266}
12671267
1268+ static bool is_truthy (const std::string & value) {
1269+ return value == " on" || value == " enabled" || value == " 1" ;
1270+ }
1271+
1272+ static bool is_falsey (const std::string & value) {
1273+ return value == " off" || value == " disabled" || value == " 0" ;
1274+ }
1275+
1276+ static bool is_autoy (const std::string & value) {
1277+ return value == " auto" || value == " -1" ;
1278+ }
1279+
12681280common_params_context common_params_parser_init (common_params & params, llama_example ex, void (*print_usage)(int , char **)) {
12691281 // load dynamic backends
12701282 ggml_backend_load_all ();
@@ -1546,21 +1558,21 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
15461558 params.n_chunks = value;
15471559 }
15481560 ).set_examples ({LLAMA_EXAMPLE_IMATRIX, LLAMA_EXAMPLE_PERPLEXITY, LLAMA_EXAMPLE_RETRIEVAL}));
1549- add_opt (common_arg (
1550- { " -fa " , " --flash-attn " }, " FA " ,
1551- string_format ( " set Flash Attention use ('on', 'off', or 'auto', default: '%s') " , llama_flash_attn_type_name (params.flash_attn_type )),
1552- [](common_params & params, const std::string & value) {
1553- if (value == " on " || value == " enabled " || value == " 1 " ) {
1554- params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED;
1555- } else if (value == " off " || value == " disabled " || value == " 0 " ) {
1556- params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_DISABLED;
1557- } else if (value == " auto " || value == " -1 " ) {
1558- params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_AUTO;
1559- } else {
1560- throw std::runtime_error ( string_format ( " error: unkown value for --flash-attn: '%s' \n " , value. c_str ()));
1561- }
1562- }
1563- ).set_env (" LLAMA_ARG_FLASH_ATTN" ));
1561+ add_opt (common_arg ({ " -fa " , " --flash-attn " }, " [on|off|auto] " ,
1562+ string_format ( " set Flash Attention use ('on', 'off', or 'auto', default: '%s') " ,
1563+ llama_flash_attn_type_name (params.flash_attn_type )),
1564+ [](common_params & params, const std::string & value) {
1565+ if ( is_truthy (value) ) {
1566+ params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED;
1567+ } else if ( is_falsey (value) ) {
1568+ params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_DISABLED;
1569+ } else if ( is_autoy (value) ) {
1570+ params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_AUTO;
1571+ } else {
1572+ throw std::runtime_error (
1573+ string_format ( " error: unkown value for --flash-attn: '%s' \n " , value. c_str ()));
1574+ }
1575+ } ).set_env (" LLAMA_ARG_FLASH_ATTN" ));
15641576 add_opt (common_arg (
15651577 {" -p" , " --prompt" }, " PROMPT" ,
15661578 " prompt to start generation with; for system message, use -sys" ,
@@ -3136,13 +3148,21 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
31363148 common_log_set_file (common_log_main (), value.c_str ());
31373149 }
31383150 ));
3139- add_opt (common_arg (
3140- {" --log-colors" },
3141- " Enable colored logging" ,
3142- [](common_params &) {
3143- common_log_set_colors (common_log_main (), true );
3144- }
3145- ).set_env (" LLAMA_LOG_COLORS" ));
3151+ add_opt (common_arg ({ " --log-colors" }, " [on|off|auto]" ,
3152+ " Set colored logging ('on', 'off', or 'auto', default: 'auto')\n "
3153+ " 'auto' enables colors when output is to a terminal" ,
3154+ [](common_params &, const std::string & value) {
3155+ if (is_truthy (value)) {
3156+ common_log_set_colors (common_log_main (), LOG_COLORS_ENABLED);
3157+ } else if (is_falsey (value)) {
3158+ common_log_set_colors (common_log_main (), LOG_COLORS_DISABLED);
3159+ } else if (is_autoy (value)) {
3160+ common_log_set_colors (common_log_main (), LOG_COLORS_AUTO);
3161+ } else {
3162+ throw std::invalid_argument (
3163+ string_format (" error: unkown value for --log-colors: '%s'\n " , value.c_str ()));
3164+ }
3165+ }).set_env (" LLAMA_LOG_COLORS" ));
31463166 add_opt (common_arg (
31473167 {" -v" , " --verbose" , " --log-verbose" },
31483168 " Set verbosity level to infinity (i.e. log all messages, useful for debugging)" ,
0 commit comments