Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 20b60cf

Browse files
committed
fix: failed on tensor overriding
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent 2a7df34 commit 20b60cf

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ general:
369369
--version Print version and exit
370370
--system-info Print system info and exit
371371
--list-devices Print list of available devices and exit
372+
--list-buffer-types Print list of available buffer types and exit
372373
-v, --verbose, --log-verbose
373374
Set verbosity level to infinity (i.e. log all messages, useful for debugging)
374375
-lv, --verbosity, --log-verbosity V

llama-box/engine_param.hpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ static void llama_box_params_print_usage(int, char ** argv, const llama_box_para
202202
opts.push_back({ "general", " --version", "Print version and exit" });
203203
opts.push_back({ "general", " --system-info", "Print system info and exit" });
204204
opts.push_back({ "general", " --list-devices", "Print list of available devices and exit" });
205+
opts.push_back({ "general", " --list-buffer-types", "Print list of available buffer types and exit" });
205206
opts.push_back({ "general", "-v, --verbose, --log-verbose", "Set verbosity level to infinity (i.e. log all messages, useful for debugging)" });
206207
opts.push_back({ "general", "-lv, --verbosity, --log-verbosity V", "Set the verbosity threshold, messages with a higher verbosity will be ignored" });
207208
opts.push_back({ "general", " --log-colors", "Enable colored logging" });
@@ -515,6 +516,23 @@ static bool llama_box_params_parse(int argc, char ** argv, llama_box_params & pa
515516
exit(0);
516517
}
517518

519+
if (!strcmp(flag, "--list-buffer-types")) {
520+
std::set<std::string> buffer_type_names;
521+
// enumerate all the devices and add their buffer types to the list
522+
for (size_t j = 0; j < ggml_backend_dev_count(); ++j) {
523+
ggml_backend_device * dev = ggml_backend_dev_get(j);
524+
ggml_backend_buffer_type * buffer_type = ggml_backend_dev_buffer_type(dev);
525+
if (buffer_type) {
526+
buffer_type_names.insert(ggml_backend_buft_name(buffer_type));
527+
}
528+
}
529+
fprintf(stderr, "available buffer types:\n");
530+
for (const auto & name : buffer_type_names) {
531+
fprintf(stderr, " %s\n", name.c_str());
532+
}
533+
exit(0);
534+
}
535+
518536
if (!strcmp(flag, "-v") || !strcmp(flag, "--verbose") || !strcmp(flag, "--log-verbose")) {
519537
params_.hs_params.llm_params.verbosity = INT_MAX;
520538
common_log_set_verbosity_thold(INT_MAX);
@@ -741,21 +759,15 @@ static bool llama_box_params_parse(int argc, char ** argv, llama_box_params & pa
741759
missing("--override-tensor");
742760
}
743761
char * arg = argv[i++];
744-
745-
/* static */ std::unordered_map<std::string /* buffer type name */,
746-
ggml_backend_buffer_type_t /* buffer type */>
747-
buffer_types;
748-
if (buffer_types.empty()) {
749-
// enumerate all the devices and add their buffer types to the list
750-
for (size_t j = 0; j < ggml_backend_dev_count(); ++j) {
751-
auto * dev = ggml_backend_dev_get(j);
752-
auto * dev_buffer_type = ggml_backend_dev_buffer_type(dev);
753-
if (dev_buffer_type) {
754-
buffer_types[ggml_backend_buft_name(dev_buffer_type)] = dev_buffer_type;
755-
}
762+
// enumerate all the devices and add their buffer types to the list
763+
std::unordered_map<std::string, ggml_backend_buffer_type_t> buffer_types;
764+
for (size_t j = 0; j < ggml_backend_dev_count(); ++j) {
765+
ggml_backend_device * dev = ggml_backend_dev_get(j);
766+
ggml_backend_buffer_type * buffer_type = ggml_backend_dev_buffer_type(dev);
767+
if (buffer_type) {
768+
buffer_types[ggml_backend_buft_name(buffer_type)] = buffer_type;
756769
}
757770
}
758-
759771
for (const auto & override : string_split<std::string>(std::string(arg), ',')) {
760772
std::string::size_type pos = override.find('=');
761773
if (pos == std::string::npos) {
@@ -765,16 +777,13 @@ static bool llama_box_params_parse(int argc, char ** argv, llama_box_params & pa
765777
std::string buffer_type = override.substr(pos + 1);
766778

767779
if (buffer_types.find(buffer_type) == buffer_types.end()) {
768-
printf("Available buffer types:\n");
769-
for (const auto & it : buffer_types) {
770-
printf(" %s\n", ggml_backend_buft_name(it.second));
771-
}
772-
invalid("--override-tensor");
780+
invalid(("--override-tensor cannot find buffer type " + buffer_type).c_str());
773781
}
774782

775783
params_.hs_params.llm_params.tensor_buft_overrides.push_back(
776784
{ strdup(tensor_name.c_str()), buffer_types.at(buffer_type) });
777785
}
786+
continue;
778787
}
779788

780789
if (!strcmp(flag, "--no-warmup")) {
@@ -2178,6 +2187,10 @@ static bool llama_box_params_parse(int argc, char ** argv, llama_box_params & pa
21782187
params_.hs_params.llm_params.kv_overrides.back().key[0] = 0;
21792188
}
21802189

2190+
if (!params_.hs_params.llm_params.tensor_buft_overrides.empty()) {
2191+
params_.hs_params.llm_params.tensor_buft_overrides.push_back({nullptr, nullptr});
2192+
}
2193+
21812194
if (params_.hs_params.llm_params.lora_init_without_apply) {
21822195
for (auto & lora_adapter : params_.hs_params.llm_params.lora_adapters) {
21832196
lora_adapter.scale = 0.0f;

0 commit comments

Comments
 (0)