Skip to content

Cmake builds libgit2 and --pull_hf_mode for ovms #3105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 73 commits into from
Apr 25, 2025
Merged

Conversation

rasapala
Copy link
Collaborator

@rasapala rasapala commented Mar 4, 2025

🛠 Summary

JIRA CVS-163308
Current usage:
bazel-bin/src/ovms --pull_hf_model --source_model OpenVINO/TinyLlama-1.1B-Chat-v1.0-int8-ov --repo_path /download

🧪 Checklist

  • Unit tests added.
  • The documentation updated.
  • Change follows security best practices.
    ``

src/server.cpp Outdated
parser.prepare(&serverSettings, &modelsSettings);
parser.prepare(&serverSettings, &modelsSettings, &hfDownloader);

if (hfDownloader.pull_hf_model) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be responsibility of ServableModule?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should separate the server mode and hf download mode.

@rasapala rasapala changed the title Cmake builds libgit2 [WIP] Cmake builds libgit2 Mar 19, 2025
@@ -84,6 +84,11 @@ patchelf --debug --set-rpath '$ORIGIN' /ovms_release/lib/libopenvino.so
patchelf --debug --set-rpath '$ORIGIN' /ovms_release/lib/lib*plugin.so
if [ -f /ovms_release/lib/libopenvino_nvidia_gpu_plugin.so ] && [ "$BASE_OS" != "redhat" ]; then patchelf --replace-needed libcutensor.so.1 /usr/lib/x86_64-linux-gnu/libcutensor/11/libcutensor.so.1 /ovms_release/lib/libopenvino_nvidia_gpu_plugin.so ; fi

wget https://github.com/git-lfs/git-lfs/releases/download/v3.6.1/git-lfs-linux-arm64-v3.6.1.tar.gz
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is duplicated with dockerfile

@@ -126,6 +127,20 @@ void CLIParser::parse(int argc, char** argv) {
"Absolute path to json configuration file",
cxxopts::value<std::string>(), "CONFIG_PATH");

options->add_options("pull hf model")
("pull_hf_model",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pull would be simpler and in like with ollama

"HF source model path",
cxxopts::value<std::string>(),
"HF_SOURCE")
("repo_path",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is repo path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destination path for git clone. Needed for testing in current status.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be changed in implementation of other tasks.

atobiszei
atobiszei previously approved these changes Apr 22, 2025

class HfPullModelModule : public Module {
protected:
mutable HFSettingsImpl hfSettings;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mutable?

@@ -0,0 +1,78 @@
//***************************************************************************
// Copyright 2022 Intel Corporation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

year

src/BUILD Outdated
@@ -2712,6 +2715,7 @@ cc_test(
"test/pipelinedefinitionstatus_test.cpp",
"test/predict_validation_test.cpp",
"test/prediction_service_test.cpp",
"test/pull_hf_model_test.cpp",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but it will rebuild unnecessarily if any of ovms_tests dependency is changed

Comment on lines +365 to +373
+ git_process_free(process);
+ git__free(payload);
+ return;
+
+on_error:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ git_process_free(process);
+ git__free(payload);
+ return;
+
+on_error:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}
+on_exit:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}

You will need to rename on_error everywhere as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_error is standard label in this library.

Comment on lines +365 to +373
+ git_process_free(process);
+ git__free(payload);
+ return;
+
+on_error:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ git_process_free(process);
+ git__free(payload);
+ return;
+
+on_error:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}
+on_exit_:
+ git_process_free(process);
+ git__free(payload);
+ return;
+}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on_error: is the library convention.

src/config.cpp Outdated
@@ -30,6 +30,7 @@

#include "capi_frontend/server_settings.hpp"
#include "cli_parser.hpp"
#include "libgt2/libgt2.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

src/config.hpp Outdated
@@ -48,7 +48,7 @@ class Config {
ServerSettingsImpl serverSettings;

public:
ServerSettingsImpl getServerSettings() {
const ServerSettingsImpl getServerSettings() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we return const why no const&?

return StatusCode::HF_FAILED_TO_INIT_LIBGIT2;
}
std::unique_ptr<HfDownloader> hfDownloader = std::make_unique<HfDownloader>(this->hfSettings.sourceModel, this->hfSettings.repoPath, this->hfSettings.pullHfModelMode);
// TODO: Do we want to set timeout for this operation ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have ticket for that?

std::unique_ptr<std::thread> t;

void ServerPullHfModel(std::string& sourceModel, std::string& repoPath) {
::SetUpServerForDownload(this->t, this->server, sourceModel, repoPath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to start whole server to verify HfDownloader

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use the class functionality but I wanted to have integration tests -> end to end with small model.
This can be late reused to test final solution.

return hfEndpoint;
}

std::string HfDownloader::GetRepoUrl(std::string& hfEndpoint) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for creating url based on various TOKEN, ENDPOINTS. Add negative tests

@atobiszei atobiszei self-requested a review April 22, 2025 10:05
@@ -82,6 +82,7 @@ pipeline {
when { expression { image_build_needed == "true" } }
steps {
sh "echo build --remote_cache=${env.OVMS_BAZEL_REMOTE_CACHE_URL} > .user.bazelrc"
sh "echo test:linux --test_env https_proxy=${env.HTTPS_PROXY} > .user.bazelrc"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this overwrite effect of the command above? ">>" probably should be used

@@ -26,6 +26,7 @@
#include <ntstatus.h>
#endif
#include "capi_frontend/server_settings.hpp"
#include "libgt2/libgt2.hpp"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bump

src/BUILD Outdated
@@ -340,6 +340,7 @@ cc_library(
"@com_github_jarro2783_cxxopts//:cxxopts",
"libovms_server_settings",
"libovms_version",
"//src/libgt2:libgt2",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependency leakage

src/BUILD Outdated
@@ -549,6 +550,8 @@ cc_library(
"get_model_metadata_impl.hpp",
"global_sequences_viewer.hpp",
"global_sequences_viewer.cpp",
"hf_pull_model_module.hpp",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate target

@@ -93,6 +93,10 @@ bool Config::check_hostname_or_ip(const std::string& input) {
}

bool Config::validate() {
// TODO: Add validation of all parameters once the CLI model export flags will be implemented
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO should be part of a ticket.

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't those two files be in libgt2 dir?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can move it there.

}

bool HfDownloader::CheckIfProxySet() {
const char* envCred = std::getenv("https_proxy");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still do have get env in HfDownloader

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed today.

if (envCred) {
hfEndpoint = std::string(envCred);
} else {
SPDLOG_DEBUG("HF_ENDPOINT environment variable not set");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this reason to stop OVMS if we require to pull but endpoint is not set?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use default endpoint huggingface.co


ASSERT_EQ(hfDownloader->GetRepoUrl(hfEndpoint), "https://www.new_hf.com/model/name");

ASSERT_EQ(hfDownloader->GetRepositoryUrlWithPassword(hfEndpoint), "https://123$$o_O123!AAbb:[email protected]_hf.com/model/name");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach with envs with leak env in case of failura at asserts. We could have instead
ASSERT_EQ(HfDownloader(modelName, downloadPath, false, hfEndpoint, hf_token, useProxy).GetRepositoryUrlWithPassword(), "https://123$$o_O123!AAbb:[email protected]_hf.com/model/name");

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you could easily add additional lines for testing incorrect downloadPaths vaildation, invalid modelName convetions (special characters?), endpoint not being proper url, etc. instead of having setup envs separaterly each time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added task for additional validation of variables from the user.

@atobiszei atobiszei self-requested a review April 23, 2025 12:17
std::string hfEndpoint;
std::string hfToken;
std::string httpProxy;
bool pullHfModelMode;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? Either we create module for pulling or not. I don't see a point.

Copy link
Collaborator Author

@rasapala rasapala Apr 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left from previous implementation. Good catch to remove.

Comment on lines +92 to +93
ASSERT_EQ(hfDownloader->getEndpoint(), "www.new_hf.com/");
ASSERT_EQ(hfDownloader->GetRepoUrl(), "https://www.new_hf.com/model/name");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are verified in GetRepositoryUrlWithPassword. We don't need to test if setting those values in constructor works.

Only checking for proxy makes sense but even then it is better to document what is considered proxy not set for hf downloader with
EXPECT_EQ(TestHfDownloader(modelName, downloadPath, false, hfEndpoint, hfToken, "").isProxySet(), false)
or
EXPECT_EQ(TestHfDownloader(modelName, downloadPath, false, hfEndpoint, hfToken, "").isProxySet(), false)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is standard unit test approach to test all methods of a class. Specifically when one method returns values that are used in another method. I can change the EXPECT_EQ for proxy though for better readability.

@atobiszei atobiszei self-requested a review April 24, 2025 14:27
rasapala and others added 2 commits April 25, 2025 13:15
@rasapala rasapala merged commit 4b7a96e into main Apr 25, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants