Skip to content

Commit 1d85e73

Browse files
committed
skip download mmproj on examples not using it
1 parent 397348c commit 1d85e73

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

common/arg.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
using json = nlohmann::ordered_json;
4040

41+
std::initializer_list<enum llama_example> mmproj_examples = {
42+
LLAMA_EXAMPLE_LLAVA,
43+
// TODO: add LLAMA_EXAMPLE_SERVER when it's ready
44+
};
45+
4146
common_arg & common_arg::set_examples(std::initializer_list<enum llama_example> examples) {
4247
this->examples = std::move(examples);
4348
return *this;
@@ -841,14 +846,20 @@ static bool common_params_parse_ex(int argc, char ** argv, common_params_context
841846

842847
// handle model and download
843848
{
844-
auto res = common_params_handle_model(params.model, params.hf_token, DEFAULT_MODEL_PATH);
849+
auto res = common_params_handle_model(params.model, params.hf_token, DEFAULT_MODEL_PATH);
845850
if (params.no_mmproj) {
846851
params.mmproj = {};
847852
} else if (res.found_mmproj && params.mmproj.path.empty() && params.mmproj.url.empty()) {
848853
// optionally, handle mmproj model when -hf is specified
849854
params.mmproj = res.mmproj;
850855
}
851-
common_params_handle_model(params.mmproj, params.hf_token, "");
856+
// only download mmproj if the current example is using it
857+
for (auto & ex : mmproj_examples) {
858+
if (ctx_arg.ex == ex) {
859+
common_params_handle_model(params.mmproj, params.hf_token, "");
860+
break;
861+
}
862+
}
852863
common_params_handle_model(params.speculative.model, params.hf_token, "");
853864
common_params_handle_model(params.vocoder.model, params.hf_token, "");
854865
}
@@ -2114,21 +2125,21 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
21142125
[](common_params & params, const std::string & value) {
21152126
params.mmproj.path = value;
21162127
}
2117-
).set_examples({LLAMA_EXAMPLE_LLAVA}));
2128+
).set_examples(mmproj_examples));
21182129
add_opt(common_arg(
21192130
{"--mmproj-url"}, "URL",
21202131
"URL to a multimodal projector file. see examples/llava/README.md",
21212132
[](common_params & params, const std::string & value) {
21222133
params.mmproj.url = value;
21232134
}
2124-
).set_examples({LLAMA_EXAMPLE_LLAVA}));
2135+
).set_examples(mmproj_examples));
21252136
add_opt(common_arg(
21262137
{"--no-mmproj"},
21272138
"explicitly disable multimodal projector, useful when using -hf",
21282139
[](common_params & params) {
21292140
params.no_mmproj = true;
21302141
}
2131-
).set_examples({LLAMA_EXAMPLE_LLAVA}));
2142+
).set_examples(mmproj_examples));
21322143
add_opt(common_arg(
21332144
{"--image"}, "FILE",
21342145
"path to an image file. use with multimodal models. Specify multiple times for batching",

0 commit comments

Comments
 (0)