diff --git a/common/arg.cpp b/common/arg.cpp index 24ebd9a012..9961f1eda4 100644 --- a/common/arg.cpp +++ b/common/arg.cpp @@ -430,6 +430,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; @@ -476,7 +496,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 = "--"; @@ -488,17 +508,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) { - if (arg == "-m" || arg == "--model") { - LOG_WRN("DEPRECATED: multiple %s options are not supported (only last value will be used). " - "Use router mode for llama-server (see --help)\n", arg.c_str()); - } else { - 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()); } @@ -840,7 +855,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 = "--"; @@ -852,15 +867,11 @@ bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map