Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2253,6 +2253,10 @@ struct llama_context_params llama_context_params_from_gpt_params(const gpt_param

#ifdef LLAMA_USE_CURL

#define CURL_MAX_RETRY 3
#define CURL_RETRY_DELAY_SECONDS 2


static bool starts_with(const std::string & str, const std::string & prefix) {
// While we wait for C++20's std::string::starts_with...
return str.rfind(prefix, 0) == 0;
Expand Down Expand Up @@ -2361,10 +2365,20 @@ static bool llama_download_file(const std::string & url, const std::string & pat
curl_easy_setopt(curl.get(), CURLOPT_HEADERFUNCTION, static_cast<CURLOPT_HEADERFUNCTION_PTR>(header_callback));
curl_easy_setopt(curl.get(), CURLOPT_HEADERDATA, &headers);

CURLcode res = curl_easy_perform(curl.get());
if (res != CURLE_OK) {
fprintf(stderr, "%s: curl_easy_perform() failed: %s\n", __func__, curl_easy_strerror(res));
return false;
int remaining_request_attempts = CURL_MAX_RETRY;
while (remaining_request_attempts > 0){
CURLcode res = curl_easy_perform(curl.get());
if (res != CURLE_OK) {
int exponential_backoff_delay = std::pow(CURL_RETRY_DELAY_SECONDS, (CURL_MAX_RETRY - remaining_request_attempts)) * 1000;
fprintf(stderr, "%s: curl_easy_perform() failed: %s, retrying after %d miliseconds\n", __func__, curl_easy_strerror(res), exponential_backoff_delay);
remaining_request_attempts--;
std::this_thread::sleep_for(std::chrono::milliseconds(exponential_backoff_delay));
} else if (remaining_request_attempts <= 0) {
fprintf(stderr, "%s: curl_easy_perform() failed\n", __func__);
return false;
} else {
break;
}
}

long http_code = 0;
Expand Down Expand Up @@ -2438,12 +2452,22 @@ static bool llama_download_file(const std::string & url, const std::string & pat
};

// start the download
fprintf(stderr, "%s: downloading from %s to %s (server_etag:%s, server_last_modified:%s)...\n", __func__,
llama_download_hide_password_in_url(url).c_str(), path.c_str(), headers.etag.c_str(), headers.last_modified.c_str());
auto res = curl_easy_perform(curl.get());
if (res != CURLE_OK) {
fprintf(stderr, "%s: curl_easy_perform() failed: %s\n", __func__, curl_easy_strerror(res));
return false;
int remaining_attempts = CURL_MAX_RETRY;
while (remaining_attempts > 0){
fprintf(stderr, "%s: trying to download model from %s to %s (server_etag:%s, server_last_modified:%s)...\n", __func__,
llama_download_hide_password_in_url(url).c_str(), path.c_str(), headers.etag.c_str(), headers.last_modified.c_str());
auto res = curl_easy_perform(curl.get());
if (res != CURLE_OK) {
int exponential_backoff_delay = std::pow(CURL_RETRY_DELAY_SECONDS, (CURL_MAX_RETRY - remaining_attempts)) * 1000;
fprintf(stderr, "\n%s: curl_easy_perform() failed: %s, retrying after %d miliseconnds\n", __func__, curl_easy_strerror(res), exponential_backoff_delay);
remaining_attempts--;
std::this_thread::sleep_for(std::chrono::milliseconds(exponential_backoff_delay));
} else if (remaining_attempts <= 0) {
fprintf(stderr, "%s: curl_easy_perform() failed\n", __func__);
return false;
} else {
break;
}
}

long http_code = 0;
Expand Down
Loading