Skip to content

Commit 4d5ae24

Browse files
authored
arg: fix common_params_parse not accepting negated arg (#17991)
1 parent 66ba512 commit 4d5ae24

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

common/arg.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static void add_rpc_devices(const std::string & servers) {
724724
}
725725
}
726726

727-
bool common_params_parse(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map) {
727+
bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map) {
728728
common_params dummy_params;
729729
common_params_context ctx_arg = common_params_parser_init(dummy_params, ex, nullptr);
730730

@@ -733,6 +733,9 @@ bool common_params_parse(int argc, char ** argv, llama_example ex, std::map<comm
733733
for (const auto & arg : opt.args) {
734734
arg_to_options[arg] = &opt;
735735
}
736+
for (const auto & arg : opt.args_neg) {
737+
arg_to_options[arg] = &opt;
738+
}
736739
}
737740

738741
// TODO @ngxson : find a way to deduplicate this code

common/arg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool common_params_parse(int argc, char ** argv, common_params & params, llama_e
115115

116116
// parse input arguments from CLI into a map
117117
// TODO: support repeated args in the future
118-
bool common_params_parse(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map);
118+
bool common_params_to_map(int argc, char ** argv, llama_example ex, std::map<common_arg, std::string> & out_map);
119119

120120
// initialize argument parser context - used by test-arg-parser and preset
121121
common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);

tests/test-arg-parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ int main(void) {
7272
argv = {"binary_name", "--draft", "123"};
7373
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_EMBEDDING));
7474

75+
// negated arg
76+
argv = {"binary_name", "--no-mmap"};
77+
assert(false == common_params_parse(argv.size(), list_str_to_char(argv).data(), params, LLAMA_EXAMPLE_COMMON));
78+
7579

7680
printf("test-arg-parser: test valid usage\n\n");
7781

tools/server/server-models.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ server_presets::server_presets(int argc, char ** argv, common_params & base_para
171171
}
172172

173173
// read base args from router's argv
174-
common_params_parse(argc, argv, LLAMA_EXAMPLE_SERVER, base_args);
174+
common_params_to_map(argc, argv, LLAMA_EXAMPLE_SERVER, base_args);
175175

176176
// remove any router-controlled args from base_args
177177
for (const auto & cargs : control_args) {

0 commit comments

Comments
 (0)