server: skip device enumeration in router mode to avoid creating CUDA primary context (#23137)
This commit is contained in:
+11
-7
@@ -373,7 +373,7 @@ void common_init() {
|
|||||||
llama_log_set(common_log_default_callback, NULL);
|
llama_log_set(common_log_default_callback, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_params_print_info(const common_params & params) {
|
void common_params_print_info(const common_params & params, bool print_devices) {
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
const char * build_type = "";
|
const char * build_type = "";
|
||||||
#else
|
#else
|
||||||
@@ -382,12 +382,16 @@ void common_params_print_info(const common_params & params) {
|
|||||||
LOG_TRC("%s: build %d (%s) with %s for %s%s\n", __func__, llama_build_number(), llama_commit(), llama_compiler(), llama_build_target(), build_type);
|
LOG_TRC("%s: build %d (%s) with %s for %s%s\n", __func__, llama_build_number(), llama_commit(), llama_compiler(), llama_build_target(), build_type);
|
||||||
|
|
||||||
LOG_INF("log_info: verbosity = %d (adjust with the `-lv N` CLI arg)\n", common_log_get_verbosity_thold());
|
LOG_INF("log_info: verbosity = %d (adjust with the `-lv N` CLI arg)\n", common_log_get_verbosity_thold());
|
||||||
LOG_INF("device_info:\n");
|
|
||||||
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
// device enumeration creates a primary context on CUDA backends, skip it when the caller does not own any device
|
||||||
auto * dev = ggml_backend_dev_get(i);
|
if (print_devices) {
|
||||||
size_t free, total;
|
LOG_INF("device_info:\n");
|
||||||
ggml_backend_dev_memory(dev, &free, &total);
|
for (size_t i = 0; i < ggml_backend_dev_count(); ++i) {
|
||||||
LOG_INF(" - %-8s: %s (%zu MiB, %zu MiB free)\n", ggml_backend_dev_name(dev), ggml_backend_dev_description(dev), total / 1024 / 1024, free / 1024 / 1024);
|
auto * dev = ggml_backend_dev_get(i);
|
||||||
|
size_t free, total;
|
||||||
|
ggml_backend_dev_memory(dev, &free, &total);
|
||||||
|
LOG_INF(" - %-8s: %s (%zu MiB, %zu MiB free)\n", ggml_backend_dev_name(dev), ggml_backend_dev_description(dev), total / 1024 / 1024, free / 1024 / 1024);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOG_INF("%s\n", common_params_get_system_info(params).c_str());
|
LOG_INF("%s\n", common_params_get_system_info(params).c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -708,7 +708,7 @@ struct common_params {
|
|||||||
// initializes the logging system and prints info about the build
|
// initializes the logging system and prints info about the build
|
||||||
void common_init();
|
void common_init();
|
||||||
|
|
||||||
void common_params_print_info(const common_params & params);
|
void common_params_print_info(const common_params & params, bool print_devices = true);
|
||||||
std::string common_params_get_system_info(const common_params & params);
|
std::string common_params_get_system_info(const common_params & params);
|
||||||
|
|
||||||
bool parse_cpu_range(const std::string & range, bool(&boolmask)[GGML_MAX_N_THREADS]);
|
bool parse_cpu_range(const std::string & range, bool(&boolmask)[GGML_MAX_N_THREADS]);
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ int main(int argc, char ** argv) {
|
|||||||
llama_backend_init();
|
llama_backend_init();
|
||||||
llama_numa_init(params.numa);
|
llama_numa_init(params.numa);
|
||||||
|
|
||||||
common_params_print_info(params);
|
// router server never loads a model and must not touch the GPU
|
||||||
|
// skip device enumeration so the CUDA primary context stays uncreated
|
||||||
|
const bool is_router_server = params.model.path.empty();
|
||||||
|
common_params_print_info(params, !is_router_server);
|
||||||
|
|
||||||
// validate batch size for embeddings
|
// validate batch size for embeddings
|
||||||
// embeddings require all tokens to be processed in a single ubatch
|
// embeddings require all tokens to be processed in a single ubatch
|
||||||
@@ -126,7 +129,6 @@ int main(int argc, char ** argv) {
|
|||||||
server_routes routes(params, ctx_server);
|
server_routes routes(params, ctx_server);
|
||||||
server_tools tools;
|
server_tools tools;
|
||||||
|
|
||||||
bool is_router_server = params.model.path.empty();
|
|
||||||
std::optional<server_models_routes> models_routes{};
|
std::optional<server_models_routes> models_routes{};
|
||||||
if (is_router_server) {
|
if (is_router_server) {
|
||||||
// setup server instances manager
|
// setup server instances manager
|
||||||
|
|||||||
Reference in New Issue
Block a user