-
Notifications
You must be signed in to change notification settings - Fork 12k
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
server: --offline mode #13804
Conversation
also support OFFLINE=1 ./tests.sh for server tests
Co-Authored-By: ochafik <ochafik@google.com>
Co-Authored-By: ochafik <ochafik@google.com>
Co-Authored-By: ochafik <ochafik@google.com>
common/arg.cpp
Outdated
if (!file_exists || !offline) | ||
{ | ||
bool should_download = !file_exists; // by default, we should download if the file does not exist | ||
|
There was a problem hiding this comment.
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
{
There was a problem hiding this comment.
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;
}
}
Co-Authored-By: ochafik <ochafik@google.com>
@@ -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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
tools/server/tests/utils.py
Outdated
if "OFFLINE" in os.environ: | ||
server_args.append("--offline") |
There was a problem hiding this comment.
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)
Co-Authored-By: ochafik <ochafik@google.com>
Co-authored-by: Xuan-Son Nguyen <thichthat@gmail.com>
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.