diff --git a/common/arg.cpp b/common/arg.cpp index 5fbc9022c0..7f5b52cec9 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -431,6 +431,26 @@ static bool parse_bool_value(const std::string & value) { // CLI argument parsing functions // +static void check_duplicate_arg(const std::string & arg) { + static const std::set multi_value_options = { + "--lora", + "--lora-scaled", + "--control-vector", + "--control-vector-scaled", + "-f", "--file", + "--context-file", + "--api-key", + "--logit-bias", + "--tensor-filter" + }; + + if (multi_value_options.find(arg) != multi_value_options.end()) { + LOG_INF("DEPRECATED: argument '%s' specified multiple times, use comma-separated values instead (only last value will be used)\n", arg.c_str()); + } else { + throw std::invalid_argument(string_format("error: argument '%s' cannot be specified multiple times", arg.c_str())); + } +} + static bool common_params_parse_ex(int argc, char ** argv, common_params_context & ctx_arg) { common_params & params = ctx_arg.params; @@ -477,7 +497,7 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context }; auto parse_cli_args = [&]() { - std::set seen_args; + std::set seen_options; for (int i = 1; i < argc; i++) { const std::string arg_prefix = "--"; @@ -489,12 +509,12 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context if (arg_to_options.find(arg) == arg_to_options.end()) { throw std::invalid_argument(string_format("error: invalid argument: %s", arg.c_str())); } - if (!seen_args.insert(arg).second) { - LOG_WRN("DEPRECATED: argument '%s' specified multiple times, use comma-separated values instead (only last value will be used)\n", arg.c_str()); - } auto & tmp = arg_to_options[arg]; auto opt = *tmp.first; bool is_positive = tmp.second; + if (!seen_options.insert(tmp.first).second) { + check_duplicate_arg(arg); + } if (opt.has_value_from_env()) { fprintf(stderr, "warn: %s environment variable is set, but will be overwritten by command line argument %s\n", opt.env, arg.c_str()); } @@ -836,7 +856,7 @@ bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map seen_args; + std::set seen_options; for (int i = 1; i < argc; i++) { const std::string arg_prefix = "--"; @@ -848,10 +868,11 @@ bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map