|
63 | 63 |
|
64 | 64 | _are_symlinks_supported_in_dir: dict[str, bool] = {} |
65 | 65 |
|
| 66 | +# Internal retry timeout for metadata fetch when no local file exists |
| 67 | +_ETAG_RETRY_TIMEOUT = 60 |
| 68 | + |
66 | 69 |
|
67 | 70 | def are_symlinks_supported(cache_dir: Union[str, Path, None] = None) -> bool: |
68 | 71 | """Return whether the symlinks are supported on the machine. |
@@ -1131,8 +1134,28 @@ def _hf_hub_download_to_cache_dir( |
1131 | 1134 | if not force_download: |
1132 | 1135 | return pointer_path |
1133 | 1136 |
|
1134 | | - # Otherwise, raise appropriate error |
1135 | | - _raise_on_head_call_error(head_call_error, force_download, local_files_only) |
| 1137 | + # No local file found, retry with longer timeout if it was a timeout error |
| 1138 | + if isinstance(head_call_error, httpx.TimeoutException): |
| 1139 | + logger.info("Metadata fetch timed out and no local file found. Retrying with longer timeout..") |
| 1140 | + (url_to_download, etag, commit_hash, expected_size, xet_file_data, head_call_error) = ( |
| 1141 | + _get_metadata_or_catch_error( |
| 1142 | + repo_id=repo_id, |
| 1143 | + filename=filename, |
| 1144 | + repo_type=repo_type, |
| 1145 | + revision=revision, |
| 1146 | + endpoint=endpoint, |
| 1147 | + etag_timeout=_ETAG_RETRY_TIMEOUT, |
| 1148 | + headers=headers, |
| 1149 | + token=token, |
| 1150 | + local_files_only=local_files_only, |
| 1151 | + storage_folder=storage_folder, |
| 1152 | + relative_filename=relative_filename, |
| 1153 | + ) |
| 1154 | + ) |
| 1155 | + |
| 1156 | + # If still error, raise |
| 1157 | + if head_call_error is not None: |
| 1158 | + _raise_on_head_call_error(head_call_error, force_download, local_files_only) |
1136 | 1159 |
|
1137 | 1160 | # From now on, etag, commit_hash, url and size are not None. |
1138 | 1161 | assert etag is not None, "etag must have been retrieved from server" |
@@ -1300,9 +1323,26 @@ def _hf_hub_download_to_local_dir( |
1300 | 1323 | ) |
1301 | 1324 | if not force_download: |
1302 | 1325 | return local_path |
| 1326 | + elif not force_download and isinstance(head_call_error, httpx.TimeoutException): |
| 1327 | + # No local file found, retry with longer timeout if it was a timeout error |
| 1328 | + logger.info("Metadata fetch timed out and no local file found. Retrying with longer timeout...") |
| 1329 | + (url_to_download, etag, commit_hash, expected_size, xet_file_data, head_call_error) = ( |
| 1330 | + _get_metadata_or_catch_error( |
| 1331 | + repo_id=repo_id, |
| 1332 | + filename=filename, |
| 1333 | + repo_type=repo_type, |
| 1334 | + revision=revision, |
| 1335 | + endpoint=endpoint, |
| 1336 | + etag_timeout=_ETAG_RETRY_TIMEOUT, |
| 1337 | + headers=headers, |
| 1338 | + token=token, |
| 1339 | + local_files_only=local_files_only, |
| 1340 | + ) |
| 1341 | + ) |
1303 | 1342 |
|
1304 | | - # Otherwise => raise |
1305 | | - _raise_on_head_call_error(head_call_error, force_download, local_files_only) |
| 1343 | + # If still error, raise |
| 1344 | + if head_call_error is not None: |
| 1345 | + _raise_on_head_call_error(head_call_error, force_download, local_files_only) |
1306 | 1346 |
|
1307 | 1347 | # From now on, etag, commit_hash, url and size are not None. |
1308 | 1348 | assert etag is not None, "etag must have been retrieved from server" |
|
0 commit comments