@@ -217,13 +217,11 @@ struct curl_slist_ptr {
217217#define CURL_MAX_RETRY 3
218218#define CURL_RETRY_DELAY_SECONDS 2
219219
220- static bool curl_perform_with_retry (const std::string & url, CURL * curl, int max_attempts, int retry_delay_seconds) {
220+ static bool curl_perform_with_retry (const std::string & url, CURL * curl, int max_attempts, int retry_delay_seconds, const char * method_name ) {
221221 int remaining_attempts = max_attempts;
222- char * method = nullptr ;
223- curl_easy_getinfo (curl, CURLINFO_EFFECTIVE_METHOD, &method);
224222
225223 while (remaining_attempts > 0 ) {
226- LOG_INF (" %s: %s %s (attempt %d of %d)...\n " , __func__ , method , url.c_str (), max_attempts - remaining_attempts + 1 , max_attempts);
224+ LOG_INF (" %s: %s %s (attempt %d of %d)...\n " , __func__ , method_name , url.c_str (), max_attempts - remaining_attempts + 1 , max_attempts);
227225
228226 CURLcode res = curl_easy_perform (curl);
229227 if (res == CURLE_OK) {
@@ -287,24 +285,17 @@ static bool common_download_file_single(const std::string & url, const std::stri
287285 try {
288286 metadata_in >> metadata;
289287 LOG_DBG (" %s: previous metadata file found %s: %s\n " , __func__, metadata_path.c_str (), metadata.dump ().c_str ());
290- if (metadata.contains (" url" ) && metadata.at (" url" ).is_string ()) {
291- auto previous_url = metadata.at (" url" ).get <std::string>();
292- if (previous_url != url) {
293- LOG_ERR (" %s: Model URL mismatch: %s != %s\n " , __func__, url.c_str (), previous_url.c_str ());
294- return false ;
295- }
296- }
297288 if (metadata.contains (" etag" ) && metadata.at (" etag" ).is_string ()) {
298289 etag = metadata.at (" etag" );
299290 }
300291 if (metadata.contains (" lastModified" ) && metadata.at (" lastModified" ).is_string ()) {
301292 last_modified = metadata.at (" lastModified" );
302293 }
303294 } catch (const nlohmann::json::exception & e) {
304- LOG_ERR (" %s: error reading metadata file %s: %s\n " , __func__, metadata_path.c_str (), e.what ());
305- return false ;
295+ LOG_ERR (" %s: error reading metadata file %s: %s\n " , __func__, metadata_path.c_str (), e.what ());
306296 }
307297 }
298+ // 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)
308299 } else {
309300 LOG_INF (" %s: no previous model file found %s\n " , __func__, path.c_str ());
310301 }
@@ -350,7 +341,7 @@ static bool common_download_file_single(const std::string & url, const std::stri
350341
351342 // we only allow retrying once for HEAD requests
352343 // this is for the use case of using running offline (no internet), retrying can be annoying
353- bool was_perform_successful = curl_perform_with_retry (url, curl.get (), 1 , 0 );
344+ bool was_perform_successful = curl_perform_with_retry (url, curl.get (), 1 , 0 , " HEAD " );
354345 if (!was_perform_successful) {
355346 head_request_ok = false ;
356347 }
@@ -432,7 +423,7 @@ static bool common_download_file_single(const std::string & url, const std::stri
432423 // start the download
433424 LOG_INF (" %s: trying to download model from %s to %s (server_etag:%s, server_last_modified:%s)...\n " , __func__,
434425 llama_download_hide_password_in_url (url).c_str (), path.c_str (), headers.etag .c_str (), headers.last_modified .c_str ());
435- bool was_perform_successful = curl_perform_with_retry (url, curl.get (), CURL_MAX_RETRY, CURL_RETRY_DELAY_SECONDS);
426+ bool was_perform_successful = curl_perform_with_retry (url, curl.get (), CURL_MAX_RETRY, CURL_RETRY_DELAY_SECONDS, " GET " );
436427 if (!was_perform_successful) {
437428 return false ;
438429 }
@@ -2792,7 +2783,10 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
27922783 ).set_examples ({LLAMA_EXAMPLE_SERVER}).set_env (" LLAMA_ARG_THREADS_HTTP" ));
27932784 add_opt (common_arg (
27942785 {" --cache-reuse" }, " N" ,
2795- string_format (" min chunk size to attempt reusing from the cache via KV shifting (default: %d)" , params.n_cache_reuse ),
2786+ string_format (
2787+ " min chunk size to attempt reusing from the cache via KV shifting (default: %d)\n "
2788+ " [(card)](https://ggml.ai/f0.png)" , params.n_cache_reuse
2789+ ),
27962790 [](common_params & params, int value) {
27972791 params.n_cache_reuse = value;
27982792 }
0 commit comments