diff --git a/engine/controllers/server.cc b/engine/controllers/server.cc index cfc6be6e3..29319d963 100644 --- a/engine/controllers/server.cc +++ b/engine/controllers/server.cc @@ -13,7 +13,10 @@ namespace inferences { server::server(std::shared_ptr inference_service) : inference_svc_(inference_service) { #if defined(_WIN32) - SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + if (bool should_use_dll_search_path = !(getenv("ENGINE_PATH")); + should_use_dll_search_path) { + SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); + } #endif }; diff --git a/engine/services/inference_service.cc b/engine/services/inference_service.cc index 35cdab098..c29f75e4a 100644 --- a/engine/services/inference_service.cc +++ b/engine/services/inference_service.cc @@ -137,19 +137,23 @@ InferResult InferenceService::LoadModel( } }; - if (IsEngineLoaded(kLlamaRepo) && ne == kTrtLlmRepo) { - // Remove llamacpp dll directory - if (!RemoveDllDirectory(engines_[kLlamaRepo].cookie)) { - LOG_WARN << "Could not remove dll directory: " << kLlamaRepo; + if (bool should_use_dll_search_path = !(getenv("ENGINE_PATH")); + should_use_dll_search_path) { + if (IsEngineLoaded(kLlamaRepo) && ne == kTrtLlmRepo && + should_use_dll_search_path) { + // Remove llamacpp dll directory + if (!RemoveDllDirectory(engines_[kLlamaRepo].cookie)) { + LOG_WARN << "Could not remove dll directory: " << kLlamaRepo; + } else { + LOG_INFO << "Removed dll directory: " << kLlamaRepo; + } + + add_dll(ne, abs_path); + } else if (IsEngineLoaded(kTrtLlmRepo) && ne == kLlamaRepo) { + // Do nothing } else { - LOG_INFO << "Removed dll directory: " << kLlamaRepo; + add_dll(ne, abs_path); } - - add_dll(ne, abs_path); - } else if (IsEngineLoaded(kTrtLlmRepo) && ne == kLlamaRepo) { - // Do nothing - } else { - add_dll(ne, abs_path); } #endif engines_[ne].dl = std::make_unique(abs_path, "engine"); @@ -366,10 +370,13 @@ InferResult InferenceService::UnloadEngine( EngineI* e = std::get(engines_[ne].engine); delete e; #if defined(_WIN32) - if (!RemoveDllDirectory(engines_[ne].cookie)) { - LOG_WARN << "Could not remove dll directory: " << ne; - } else { - LOG_INFO << "Removed dll directory: " << ne; + if (bool should_use_dll_search_path = !(getenv("ENGINE_PATH")); + should_use_dll_search_path) { + if (!RemoveDllDirectory(engines_[ne].cookie)) { + LOG_WARN << "Could not remove dll directory: " << ne; + } else { + LOG_INFO << "Removed dll directory: " << ne; + } } #endif engines_.erase(ne);