Skip to content

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 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;
        }
    }

} 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 <[email protected]>
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
@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