Skip to content

Commit 88d3c02

Browse files
committed
common_parse_skip_backend_init
1 parent ba77a54 commit 88d3c02

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

common/arg.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,8 @@ static void add_rpc_devices(const std::string & servers) {
13381338
}
13391339
}
13401340

1341-
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
1342-
auto ctx_arg = common_params_parser_init(params, ex, print_usage);
1341+
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **), bool skip_backend_init) {
1342+
auto ctx_arg = common_params_parser_init(params, ex, print_usage, skip_backend_init);
13431343
const common_params params_org = ctx_arg.params; // the example can modify the default params
13441344

13451345
try {
@@ -1395,9 +1395,14 @@ static bool is_autoy(const std::string & value) {
13951395
return value == "auto" || value == "-1";
13961396
}
13971397

1398-
common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **)) {
1399-
// load dynamic backends
1400-
ggml_backend_load_all();
1398+
common_params_context common_params_parser_init(common_params & params,
1399+
llama_example ex,
1400+
void (*print_usage)(int, char **),
1401+
bool skip_backend_init) {
1402+
// load dynamic backends (unless explicitly skipped)
1403+
if (!skip_backend_init) {
1404+
ggml_backend_load_all();
1405+
}
14011406

14021407
common_params_context ctx_arg(params);
14031408
ctx_arg.print_usage = print_usage;

common/arg.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ struct common_params_context {
7474

7575
// parse input arguments from CLI
7676
// if one argument has invalid value, it will automatically display usage of the specific argument (and not the full usage message)
77-
bool common_params_parse(int argc, char ** argv, common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
77+
// skip_backend_init: if true, skip calling ggml_backend_load_all() in common_params_parser_init
78+
bool common_params_parse(int argc,
79+
char ** argv,
80+
common_params & params,
81+
llama_example ex,
82+
void (*print_usage)(int, char **) = nullptr,
83+
bool skip_backend_init = false);
7884

7985
// function to be used by test-arg-parser
80-
common_params_context common_params_parser_init(common_params & params, llama_example ex, void(*print_usage)(int, char **) = nullptr);
81-
bool common_has_curl();
86+
// skip_backend_init: if true, skip calling ggml_backend_load_all()
87+
common_params_context common_params_parser_init(common_params & params,
88+
llama_example ex,
89+
void (*print_usage)(int, char **) = nullptr,
90+
bool skip_backend_init = false);
91+
bool common_has_curl();
8292

8393
struct common_remote_params {
8494
std::vector<std::string> headers;

0 commit comments

Comments
 (0)