8000 server: --offline mode by ochafik · Pull Request #13804 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

server: --offline mode #13804

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 11 commits into from
May 26, 2025
Merged

server: --offline mode #13804

merged 11 commits into from
May 26, 2025

Conversation

ochafik
Copy link
Collaborator
@ochafik ochafik commented May 26, 2025

This adds --offline flag (env: LLAMA_OFFLINE) to use locally cached manifests & models if available, or fail

@ngxson I know you told me you've incubated something similar (here?) but since I was stuck in a plane with ~zero internet all day yesterday, I ended up hacking this together. Feel free to merge later or ignore in favour of your approach.

ochafik and others added 2 commits May 26, 2025 01:52
also support OFFLINE=1 ./tests.sh for server tests
@github-actions github-actions bot added examples python python script changes server labels May 26, 2025
ochafik and others added 4 commits May 26, 2025 08:16
Co-Authored-By: ochafik <ochafik@google.com>
Co-Authored-By: ochafik <ochafik@google.com>
Co-Authored-By: ochafik <ochafik@google.com>
@ochafik ochafik marked this pull request as ready for review May 26, 2025 17:29
@ochafik ochafik requested a review from ngxson as a code owner May 26, 2025 17:29
common/arg.cpp Outdated
Comment on lines 289 to 292
if (!file_exists || !offline)
{
bool should_download = !file_exists; // by default, we should download if the file does not exist

Copy link
Collaborator
@ngxson ngxson May 26, 2025

Choose a reason for hiding this comment

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

I think we don't need to put this code block inside a long if..else like this. Instead, there is a more simple way:

    if (file_exists && offline) {
        LOG_INF("%s: using cached file (offline mode): %s\n", __func__, path.c_str());
        return true; // skip verification/downloading
    }

    // keep the rest of the code as-is

    common_load_model_from_url_headers headers;
    bool head_request_ok = false;
    bool should_download = !file_exists; // by default, we should download if the file does not exist

    // get ETag to see if the remote file has changed
    {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or even more fail-safe:

    if (offline) {
        if (file_exists) {
            // if offline mode is enabled and the file exists, we can use it
            LOG_INF("%s: using cached file (offline mode): %s\n", __func__, path.c_str());
            return true; // skip verification/downloading
        } else {
            LOG_ERR("%s: required file is not available in cache (offline mode): %s\n", __func__, path.c_str());
            return false;
        }
    }

ochafik and others added 2 commits May 26, 2025 13:48
@@ -298,6 +272,9 @@ static bool common_download_file_single(const std::string & url, const std::stri
// if we cannot open the metadata file, we assume that the downloaded file is not valid (etag and last-modified are left empty, so we will download it again)
} else {
LOG_INF("%s: no previous model file found %s\n", __func__, path.c_str());
if (offline) {
return false;
Copy link
Collaborator
@ngxson ngxson May 26, 2025

Choose a reason for hiding this comment

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

This code branch will be trigger when file_exists == false && offline == true, so technically one of the condition inside if (offline) below now become dead code.

Instead, you can move the if (offline) to above of if (file_exists). So if file exist, we completely skip reading metadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah ofc, rearranged to skip, thanks!

Co-Authored-By: ochafik <ochafik@google.com>
Comment on lines 124 to 125
if "OFFLINE" in os.environ:
server_args.append("--offline")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we don't need this, because you can do LLAMA_OFFLINE=1 (not sure if the env is forwarded to child process though)

ochafik and others added 2 commits May 26, 2025 14:32
Co-Authored-By: ochafik <ochafik@google.com>
Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
@ochafik ochafik merged commit cdf94a1 into ggml-org:master May 26, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples python python script changes server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0