Skip to content

Commit

Permalink
Feat/config log location for engines (#1356)
Browse files Browse the repository at this point in the history
* fix/mistral-nemo-chat-template

* feat/config-engines-log-path

* Fix: use file system path instead of string concat

* Fix: CI build window

* Fix: CI build window

* Fix: CI build windows
  • Loading branch information
nguyenhoangthuan99 authored Sep 30, 2024
1 parent 44d831f commit 4bc1aa7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
4 changes: 2 additions & 2 deletions engine/controllers/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ void server::LoadModel(const HttpRequestPtr& req,
if (engine_type == kLlamaEngine) { //fix for llamacpp engine first
auto config = file_manager_utils::GetCortexConfig();
if (en->IsSupported("SetFileLogger")) {
en->SetFileLogger(config.maxLogLines, config.logFolderPath + "/" +
cortex_utils::logs_base_name);
en->SetFileLogger(config.maxLogLines, (std::filesystem::path(config.logFolderPath) /
std::filesystem::path(config.logLlamaCppPath)).string());
} else {
LOG_WARN << "Method SetFileLogger is not supported yet";
}
Expand Down
38 changes: 30 additions & 8 deletions engine/test/components/test_cortex_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ class CortexConfigTest : public ::testing::Test {

void SetUp() override {
// Set up default configuration
default_config = {
"default_log_path", "default_data_path", 1000,
kDefaultHost, kDefaultPort, kDefaultCheckedForUpdateAt,
kDefaultLatestRelease};
default_config = {"default_log_path",
"default_llamacpp_log_path",
"default_tensorrtllm_log_path",
"default_onnx_log_path",
"default_data_path",
1000,
kDefaultHost,
kDefaultPort,
kDefaultCheckedForUpdateAt,
kDefaultLatestRelease};
}

void TearDown() override {
Expand All @@ -24,8 +30,16 @@ class CortexConfigTest : public ::testing::Test {
};

TEST_F(CortexConfigTest, DumpYamlConfig_WritesCorrectly) {
CortexConfig config = {"log_path", "data_path", 5000, "localhost",
"8080", 123456789, "v1.0.0"};
CortexConfig config = {"log_path",
"default_llamacpp_log_path",
"default_tensorrtllm_log_path",
"default_onnx_log_path",
"data_path",
5000,
"localhost",
"8080",
123456789,
"v1.0.0"};

DumpYamlConfig(config, test_file_path);

Expand All @@ -43,8 +57,16 @@ TEST_F(CortexConfigTest, DumpYamlConfig_WritesCorrectly) {

TEST_F(CortexConfigTest, FromYaml_ReadsCorrectly) {
// First, create a valid YAML configuration file
CortexConfig config = {"log_path", "data_path", 5000, "localhost",
"8080", 123456789, "v1.0.0"};
CortexConfig config = {"log_path",
"default_llamacpp_log_path",
"default_tensorrtllm_log_path",
"default_onnx_log_path",
"data_path",
5000,
"localhost",
"8080",
123456789,
"v1.0.0"};

DumpYamlConfig(config, test_file_path);

Expand Down
18 changes: 17 additions & 1 deletion engine/utils/config_yaml_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
namespace config_yaml_utils {
struct CortexConfig {
std::string logFolderPath;
std::string logLlamaCppPath;
std::string logTensorrtLLMPath;
std::string logOnnxPath;
std::string dataFolderPath;
int maxLogLines;
std::string apiServerHost;
Expand All @@ -35,6 +38,9 @@ inline void DumpYamlConfig(const CortexConfig& config,
}
YAML::Node node;
node["logFolderPath"] = config.logFolderPath;
node["logLlamaCppPath"] = config.logLlamaCppPath;
node["logTensorrtLLMPath"] = config.logTensorrtLLMPath;
node["logOnnxPath"] = config.logOnnxPath;
node["dataFolderPath"] = config.dataFolderPath;
node["maxLogLines"] = config.maxLogLines;
node["apiServerHost"] = config.apiServerHost;
Expand Down Expand Up @@ -63,12 +69,22 @@ inline CortexConfig FromYaml(const std::string& path,
(!node["logFolderPath"] || !node["dataFolderPath"] ||
!node["maxLogLines"] || !node["apiServerHost"] ||
!node["apiServerPort"] || !node["checkedForUpdateAt"] ||
!node["latestRelease"]);
!node["latestRelease"] || !node["logLlamaCppPath"] ||
!node["logOnnxPath"] || !node["logTensorrtLLMPath"]);

CortexConfig config = {
.logFolderPath = node["logFolderPath"]
? node["logFolderPath"].as<std::string>()
: default_cfg.logFolderPath,
.logLlamaCppPath = node["logLlamaCppPath"]
? node["logLlamaCppPath"].as<std::string>()
: default_cfg.logLlamaCppPath,
.logTensorrtLLMPath = node["logTensorrtLLMPath"]
? node["logTensorrtLLMPath"].as<std::string>()
: default_cfg.logTensorrtLLMPath,
.logOnnxPath = node["logOnnxPath"]
? node["logOnnxPath"].as<std::string>()
: default_cfg.logOnnxPath,
.dataFolderPath = node["dataFolderPath"]
? node["dataFolderPath"].as<std::string>()
: default_cfg.dataFolderPath,
Expand Down
7 changes: 7 additions & 0 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "services/download_service.h"
#include "utils/config_yaml_utils.h"


#if defined(__APPLE__) && defined(__MACH__)
#include <mach-o/dyld.h>
#elif defined(__linux__)
Expand All @@ -20,6 +21,9 @@ constexpr std::string_view kDefaultConfigurationPath = "user_home";
constexpr std::string_view kProdVariant = "prod";
constexpr std::string_view kBetaVariant = "beta";
constexpr std::string_view kNightlyVariant = "nightly";
constexpr char kLogsLlamacppBaseName[] = "./logs/cortex.log";
constexpr char kLogsTensorrtllmBaseName[] = "./logs/cortex.log";
constexpr char kLogsOnnxBaseName[] = "./logs/cortex.log";

inline std::filesystem::path GetExecutableFolderContainerPath() {
#if defined(__APPLE__) && defined(__MACH__)
Expand Down Expand Up @@ -156,6 +160,9 @@ inline config_yaml_utils::CortexConfig GetCortexConfig() {
file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name;
auto default_cfg = config_yaml_utils::CortexConfig{
.logFolderPath = default_data_folder_path.string(),
.logLlamaCppPath = kLogsLlamacppBaseName,
.logTensorrtLLMPath = kLogsTensorrtllmBaseName,
.logOnnxPath = kLogsOnnxBaseName,
.dataFolderPath = default_data_folder_path.string(),
.maxLogLines = config_yaml_utils::kDefaultMaxLines,
.apiServerHost = config_yaml_utils::kDefaultHost,
Expand Down

0 comments on commit 4bc1aa7

Please sign in to comment.