diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp index f5a88747cb..47f5e1886d 100644 --- a/tools/server/server-common.cpp +++ b/tools/server/server-common.cpp @@ -1948,7 +1948,7 @@ static void server_proc_restart(char ** argv, const char * env_name, const std:: return; } - setenv(env_name, env_value.c_str(), 1); + common_set_env(env_name, env_value); const std::string exe = server_proc_exe_path(argv); SRV_INF("restarting the process, exe = '%s'\n", exe.c_str()); @@ -1974,8 +1974,8 @@ void server_sleep_rst::init(int argc, char ** argv) { this->argv = argv; - const char * state = std::getenv(SLEEP_STATE_ENV); - if (state == nullptr) { + const std::string state = common_get_env(SLEEP_STATE_ENV); + if (state.empty()) { return; } @@ -1985,12 +1985,8 @@ void server_sleep_rst::init(int argc, char ** argv) { SRV_ERR("failed to read the state left by the previous process: %s\n", e.what()); } -#if defined(_WIN32) - _putenv_s(SLEEP_STATE_ENV, ""); -#else // clear it now, so that child processes do not inherit it - unsetenv(SLEEP_STATE_ENV); -#endif + common_set_env(SLEEP_STATE_ENV, ""); } void server_sleep_rst::enable(common_params & params) { @@ -2014,6 +2010,10 @@ void server_sleep_rst::enable(common_params & params) { enabled = true; } +bool server_sleep_rst::is_boot_to_sleep() { + return !common_get_env(SLEEP_STATE_ENV).empty(); +} + void server_sleep_rst::restart() const { if (!enabled) { return; diff --git a/tools/server/server-common.h b/tools/server/server-common.h index e9c823daca..9e6811ed7f 100644 --- a/tools/server/server-common.h +++ b/tools/server/server-common.h @@ -619,6 +619,10 @@ struct server_pipe { // struct server_sleep_rst { + // true if the process was restarted by a previous instance + // in this case, the model is only loaded upon the first request + static bool is_boot_to_sleep(); + // remember argv and read the state left by the previous process // must be called once at startup, before spawning any thread or child process void init(int argc, char ** argv); @@ -626,10 +630,6 @@ struct server_sleep_rst { // enable the restart upon sleeping, warns and falls back to --sleep-mode free if not possible void enable(common_params & params); - // true if the process was restarted by a previous instance - // in this case, the model is only loaded upon the first request - bool is_boot_to_sleep() const { return !boot_state.is_null(); } - // state left by the previous process, only valid if is_boot_to_sleep() const json & get_boot_state() const { return boot_state; } diff --git a/tools/server/server.cpp b/tools/server/server.cpp index e8030a5c20..6275cdbbca 100644 --- a/tools/server/server.cpp +++ b/tools/server/server.cpp @@ -132,8 +132,10 @@ int llama_server(common_params & params, int argc, char ** argv) { const bool is_router_server = params.model.path.empty() && params.model.hf_repo.empty(); - // skip device enumeration so the CUDA primary context stays uncreated - common_params_print_info(params, !is_router_server); + // may skip device enumeration so the CUDA primary context stays uncreated + if (!server_sleep_rst::is_boot_to_sleep()) { + common_params_print_info(params, !is_router_server); + } if (!is_router_server) { // validate batch size for embeddings