|
52 | 52 | #include "common.h" |
53 | 53 | #include "arg.h" |
54 | 54 | #include "chat-auto-parser.h" |
| 55 | +#include "llama_compat.h" // fork-skew switches, generated by prepare.sh |
55 | 56 | #include "message_content.h" |
56 | 57 | #include <getopt.h> |
57 | 58 | #include <grpcpp/ext/proto_server_reflection_plugin.h> |
@@ -613,6 +614,13 @@ static void params_parse(server_context& /*ctx_server*/, const backend::ModelOpt |
613 | 614 | // starts with '-'. Applied once after the loop via common_params_parse. |
614 | 615 | std::vector<std::string> extra_argv; |
615 | 616 |
|
| 617 | + // O_DIRECT intent from the `direct_io` option. Upstream folded |
| 618 | + // use_mmap/use_mlock/use_direct_io into a single common_params::load_mode |
| 619 | + // enum (ggml-org/llama.cpp#20834), so the three independent LocalAI settings |
| 620 | + // can only be reduced to one value once all of them have been read, held |
| 621 | + // here until the mmap/mlock fields arrive further down. |
| 622 | + bool want_direct_io = false; |
| 623 | + |
616 | 624 | auto add_device_options = [&](const std::string & devices) { |
617 | 625 | const std::regex regex{ R"([,]+)" }; |
618 | 626 | std::sregex_token_iterator it{ devices.begin(), devices.end(), regex, -1 }; |
@@ -868,9 +876,9 @@ static void params_parse(server_context& /*ctx_server*/, const backend::ModelOpt |
868 | 876 | // --- O_DIRECT model loading (upstream --direct-io) --- |
869 | 877 | } else if (!strcmp(optname, "direct_io") || !strcmp(optname, "use_direct_io")) { |
870 | 878 | if (optval_str == "true" || optval_str == "1" || optval_str == "yes" || optval_str == "on" || optval_str == "enabled") { |
871 | | - params.use_direct_io = true; |
| 879 | + want_direct_io = true; |
872 | 880 | } else if (optval_str == "false" || optval_str == "0" || optval_str == "no" || optval_str == "off" || optval_str == "disabled") { |
873 | | - params.use_direct_io = false; |
| 881 | + want_direct_io = false; |
874 | 882 | } |
875 | 883 |
|
876 | 884 | // --- embedding normalization (upstream --embd-normalize) --- |
@@ -1278,8 +1286,28 @@ static void params_parse(server_context& /*ctx_server*/, const backend::ModelOpt |
1278 | 1286 | lora_info.ptr = nullptr; |
1279 | 1287 | params.lora_adapters.push_back(std::move(lora_info)); |
1280 | 1288 | } |
1281 | | - params.use_mlock = request->mlock(); |
1282 | | - params.use_mmap = request->mmap(); |
| 1289 | + // LocalAI keeps mmap, mlock and direct-I/O as three independent settings, |
| 1290 | + // while upstream now carries a single load mode. Fold them with the |
| 1291 | + // precedence the separate booleans used to give: direct I/O bypasses the |
| 1292 | + // page cache entirely, mlock implies mmap, and everything off is a plain |
| 1293 | + // buffered read. Forks that branched before ggml-org/llama.cpp#20834 still |
| 1294 | + // expose the booleans; prepare.sh probes the checkout and sets |
| 1295 | + // LOCALAI_LEGACY_LOAD_MODE in the generated llama_compat.h accordingly. |
| 1296 | +#if LOCALAI_LEGACY_LOAD_MODE |
| 1297 | + params.use_mlock = request->mlock(); |
| 1298 | + params.use_mmap = request->mmap(); |
| 1299 | + params.use_direct_io = want_direct_io; |
| 1300 | +#else |
| 1301 | + if (want_direct_io) { |
| 1302 | + params.load_mode = LLAMA_LOAD_MODE_DIRECT_IO; |
| 1303 | + } else if (request->mlock()) { |
| 1304 | + params.load_mode = LLAMA_LOAD_MODE_MLOCK; |
| 1305 | + } else if (request->mmap()) { |
| 1306 | + params.load_mode = LLAMA_LOAD_MODE_MMAP; |
| 1307 | + } else { |
| 1308 | + params.load_mode = LLAMA_LOAD_MODE_NONE; |
| 1309 | + } |
| 1310 | +#endif |
1283 | 1311 |
|
1284 | 1312 | if (request->flashattention() == "on" || request->flashattention() == "enabled") { |
1285 | 1313 | params.flash_attn_type = LLAMA_FLASH_ATTN_TYPE_ENABLED; |
|
0 commit comments