Skip to content

Commit

Permalink
fix: install local with nvidia-driver unavailable (#1676)
Browse files Browse the repository at this point in the history
* fix: install local without nvidia driver available

* fix: local installer extraction

* fix: set default version

* chore: enable docker e2e test

---------

Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Nov 13, 2024
1 parent a055f69 commit 3d02299
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 46 deletions.
72 changes: 36 additions & 36 deletions .github/workflows/cortex-cpp-quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,40 +188,40 @@ jobs:
AWS_SECRET_ACCESS_KEY: "${{ secrets.MINIO_SECRET_ACCESS_KEY }}"
AWS_DEFAULT_REGION: "${{ secrets.MINIO_REGION }}"

# build-docker-and-test:
# runs-on: ubuntu-latest
# steps:
# - name: Getting the repo
# uses: actions/checkout@v3
# with:
# submodules: 'recursive'

# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
build-docker-and-test:
runs-on: ubuntu-latest
steps:
- name: Getting the repo
uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# - name: Run Docker
# run: |
# docker build -t menloltd/cortex:test -f docker/Dockerfile .
# docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test

# - name: use python
# uses: actions/setup-python@v5
# with:
# python-version: "3.10"

# - name: Run e2e tests
# run: |
# cd engine
# python -m pip install --upgrade pip
# python -m pip install -r e2e-test/requirements.txt
# pytest e2e-test/test_api_docker.py

# - name: Run Docker
# continue-on-error: true
# if: always()
# run: |
# docker stop cortex
# docker rm cortex
- name: Run Docker
run: |
docker build -t menloltd/cortex:test -f docker/Dockerfile .
docker run -it -d -p 3928:39281 --name cortex menloltd/cortex:test
- name: use python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Run e2e tests
run: |
cd engine
python -m pip install --upgrade pip
python -m pip install -r e2e-test/requirements.txt
pytest e2e-test/test_api_docker.py
- name: Run Docker
continue-on-error: true
if: always()
run: |
docker stop cortex
docker rm cortex
37 changes: 27 additions & 10 deletions engine/services/engine_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ cpp::result<bool, std::string> EngineService::UnzipEngine(
CTL_INF("Found cuda variant, extract it");
found_cuda = true;
// extract binary
auto engine_path =
file_manager_utils::GetEnginesContainerPath() / engine;
archive_utils::ExtractArchive(path + "/" + cf, engine_path.string());
auto cuda_path =
file_manager_utils::GetCudaToolkitPath(NormalizeEngine(engine));
archive_utils::ExtractArchive(path + "/" + cf, cuda_path.string(),
true);
}
}
}
Expand All @@ -159,7 +160,8 @@ cpp::result<bool, std::string> EngineService::UnzipEngine(

auto matched_variant = GetMatchedVariant(engine, variants);
CTL_INF("Matched variant: " << matched_variant);
if (!found_cuda || matched_variant.empty()) {
if ((!found_cuda && system_info_utils::IsNvidiaSmiAvailable()) ||
matched_variant.empty()) {
return false;
}

Expand All @@ -169,9 +171,24 @@ cpp::result<bool, std::string> EngineService::UnzipEngine(
<< ", will get engine from remote");
// Go with the remote flow
} else {
auto engine_path = file_manager_utils::GetEnginesContainerPath();
auto [v, ar] = engine_matcher_utils::GetVersionAndArch(matched_variant);
auto engine_path = file_manager_utils::GetEnginesContainerPath() /
NormalizeEngine(engine) / ar / v;
CTL_INF("engine_path: " << engine_path.string());
archive_utils::ExtractArchive(path + "/" + matched_variant,
engine_path.string());
engine_path.string(), true);

auto variant =
engine_matcher_utils::GetVariantFromNameAndVersion(ar, engine, v);
CTL_INF("Extracted variant: " + variant.value());
// set as default
auto res = SetDefaultEngineVariant(engine, v, variant.value());
if (res.has_error()) {
CTL_ERR("Failed to set default engine variant: " << res.error());
return false;
} else {
CTL_INF("Set default engine variant: " << res.value().variant);
}
}

return true;
Expand Down Expand Up @@ -295,12 +312,12 @@ cpp::result<void, std::string> EngineService::DownloadEngineV2(

auto variant_path = variant_folder_path / selected_variant->name;
std::filesystem::create_directories(variant_folder_path);
CLI_LOG("variant_folder_path: " + variant_folder_path.string());
CTL_INF("variant_folder_path: " + variant_folder_path.string());
auto on_finished = [this, engine, selected_variant, variant_folder_path,
normalize_version](const DownloadTask& finishedTask) {
// try to unzip the downloaded file
CLI_LOG("Engine zip path: " << finishedTask.items[0].localPath.string());
CLI_LOG("Version: " + normalize_version);
CTL_INF("Engine zip path: " << finishedTask.items[0].localPath.string());
CTL_INF("Version: " + normalize_version);

auto extract_path = finishedTask.items[0].localPath.parent_path();

Expand All @@ -309,7 +326,7 @@ cpp::result<void, std::string> EngineService::DownloadEngineV2(

auto variant = engine_matcher_utils::GetVariantFromNameAndVersion(
selected_variant->name, engine, normalize_version);
CLI_LOG("Extracted variant: " + variant.value());
CTL_INF("Extracted variant: " + variant.value());
// set as default
auto res =
SetDefaultEngineVariant(engine, normalize_version, variant.value());
Expand Down
24 changes: 24 additions & 0 deletions engine/test/components/test_engine_matcher_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,27 @@ TEST_F(EngineMatcherUtilsTestSuite, TestValidate) {
"cortex.llamacpp-0.1.25-25.08.24-windows-amd64-avx2.tar.gz");
}
}

TEST_F(EngineMatcherUtilsTestSuite, TestGetVersionAndArch) {
{
std::string variant =
"cortex.llamacpp-0.1.25-25.08.24-linux-amd64-avx-cuda-11-7.tar.gz";
auto [version, arch] = engine_matcher_utils::GetVersionAndArch(variant);
EXPECT_EQ(version, "v0.1.25-25.08.24");
EXPECT_EQ(arch, "linux-amd64-avx-cuda-11-7");
}

{
std::string variant = "cortex.llamacpp-0.1.25-windows-amd64-avx2.tar.gz";
auto [version, arch] = engine_matcher_utils::GetVersionAndArch(variant);
EXPECT_EQ(version, "v0.1.25");
EXPECT_EQ(arch, "windows-amd64-avx2");
}

{
std::string variant = "cortex.llamacpp-0.1.25-25.08.24-mac-amd64.tar.gz";
auto [version, arch] = engine_matcher_utils::GetVersionAndArch(variant);
EXPECT_EQ(version, "v0.1.25-25.08.24");
EXPECT_EQ(arch, "mac-amd64");
}
}
23 changes: 23 additions & 0 deletions engine/utils/engine_matcher_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,27 @@ inline std::string Validate(const std::vector<std::string>& variants,

return cuda_compatible;
}

inline std::pair<std::string, std::string> GetVersionAndArch(
const std::string& file_name) {
// Remove the file extension
std::string base = file_name.substr(0, file_name.find("tar") - 1);

size_t arch_pos = 0;
if (base.find("windows") != std::string::npos) {
arch_pos = base.find("-windows");
} else if (base.find("linux") != std::string::npos) {
arch_pos = base.find("-linux");
} else {
arch_pos = base.find("-mac");
}

// Extract architecture part
auto arch = base.substr(arch_pos + 1);

// Extract version part
size_t v_pos = base.find_first_of('-');
auto version = base.substr(v_pos + 1, arch_pos - v_pos - 1);
return std::pair("v" + version, arch);
}
} // namespace engine_matcher_utils

0 comments on commit 3d02299

Please sign in to comment.