Add RPC longhaul paging
This commit is contained in:
+11
-1
@@ -36,6 +36,17 @@ flowchart TD
|
||||
By default, `ggml-rpc-server` exposes all available accelerator devices on the host.
|
||||
If there are no accelerators, it exposes a single `CPU` device.
|
||||
|
||||
For server-resident longhaul MoE paging, place the same GGUF shards on the RPC
|
||||
host and point the server at their directory:
|
||||
|
||||
```sh
|
||||
$ bin/ggml-rpc-server --device MTL0 --longhaul-root /path/to/model-directory
|
||||
```
|
||||
|
||||
The client can then use `--rpc`, `--longhaul`, and `--longhaul-cache` together.
|
||||
RPC longhaul v1 requires one remote Metal device. Expert cache misses are read
|
||||
from the RPC host's local files rather than uploaded by the client.
|
||||
|
||||
## Usage
|
||||
|
||||
### Remote hosts
|
||||
@@ -107,4 +118,3 @@ Use the `GGML_RPC_DEBUG` environment variable to enable debug messages from `ggm
|
||||
```bash
|
||||
$ GGML_RPC_DEBUG=1 bin/ggml-rpc-server
|
||||
```
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <algorithm>
|
||||
#include <clocale>
|
||||
#include <codecvt>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <regex>
|
||||
#include <stdio.h>
|
||||
@@ -173,6 +174,7 @@ struct rpc_server_params {
|
||||
std::string host = "127.0.0.1";
|
||||
int port = 50052;
|
||||
bool use_cache = false;
|
||||
std::string longhaul_root;
|
||||
int n_threads = std::max(1U, std::thread::hardware_concurrency()/2);
|
||||
std::vector<std::string> devices;
|
||||
};
|
||||
@@ -186,6 +188,7 @@ static void print_usage(int /*argc*/, char ** argv, rpc_server_params params) {
|
||||
fprintf(stderr, " -H, --host HOST host to bind to (default: %s)\n", params.host.c_str());
|
||||
fprintf(stderr, " -p, --port PORT port to bind to (default: %d)\n", params.port);
|
||||
fprintf(stderr, " -c, --cache enable local file cache\n");
|
||||
fprintf(stderr, " --longhaul-root PATH serve longhaul expert data from this model directory\n");
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
@@ -233,6 +236,11 @@ static bool rpc_server_params_parse(int argc, char ** argv, rpc_server_params &
|
||||
}
|
||||
} else if (arg == "-c" || arg == "--cache") {
|
||||
params.use_cache = true;
|
||||
} else if (arg == "--longhaul-root") {
|
||||
if (++i >= argc) {
|
||||
return false;
|
||||
}
|
||||
params.longhaul_root = argv[i];
|
||||
} else if (arg == "-h" || arg == "--help") {
|
||||
print_usage(argc, argv, params);
|
||||
exit(0);
|
||||
@@ -313,6 +321,23 @@ int main(int argc, char * argv[]) {
|
||||
fprintf(stderr, "No devices found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!params.longhaul_root.empty()) {
|
||||
std::error_code ec;
|
||||
const auto root = std::filesystem::canonical(params.longhaul_root, ec);
|
||||
if (ec || !std::filesystem::is_directory(root, ec)) {
|
||||
fprintf(stderr, "Invalid longhaul root: %s\n", params.longhaul_root.c_str());
|
||||
return 1;
|
||||
}
|
||||
params.longhaul_root = root.string();
|
||||
for (auto * dev : devices) {
|
||||
auto * dev_reg = ggml_backend_dev_backend_reg(dev);
|
||||
if (!dev_reg || strcmp(ggml_backend_reg_name(dev_reg), "MTL") != 0) {
|
||||
fprintf(stderr, "--longhaul-root currently requires Metal devices\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string endpoint = params.host + ":" + std::to_string(params.port);
|
||||
const char * cache_dir = nullptr;
|
||||
std::string cache_dir_str;
|
||||
@@ -331,12 +356,19 @@ int main(int argc, char * argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto start_server_fn = (decltype(ggml_backend_rpc_start_server)*) ggml_backend_reg_get_proc_address(reg, "ggml_backend_rpc_start_server");
|
||||
auto start_server_fn = (decltype(ggml_backend_rpc_start_server_with_options)*)
|
||||
ggml_backend_reg_get_proc_address(reg, "ggml_backend_rpc_start_server_with_options");
|
||||
if (!start_server_fn) {
|
||||
fprintf(stderr, "Failed to obtain RPC backend start server function\n");
|
||||
fprintf(stderr, "Failed to obtain RPC backend start server function with options\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
start_server_fn(endpoint.c_str(), cache_dir, params.n_threads, devices.size(), devices.data());
|
||||
start_server_fn(
|
||||
endpoint.c_str(),
|
||||
cache_dir,
|
||||
params.longhaul_root.empty() ? nullptr : params.longhaul_root.c_str(),
|
||||
params.n_threads,
|
||||
devices.size(),
|
||||
devices.data());
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user