-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[misc] Add retries with exponential backoff for HF file existence check #13008
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| import os | ||
| from pathlib import Path | ||
| from typing import Any, Dict, Literal, Optional, Type, Union | ||
|
|
||
| import time | ||
| import huggingface_hub | ||
| from huggingface_hub import (file_exists, hf_hub_download, list_repo_files, | ||
| try_to_load_from_cache) | ||
|
|
@@ -100,15 +100,26 @@ | |
|
|
||
| # NB: file_exists will only check for the existence of the config file on | ||
| # hf_hub. This will fail in offline mode. | ||
| try: | ||
| return file_exists(model, | ||
| config_name, | ||
| revision=revision, | ||
| token=HF_TOKEN) | ||
| except huggingface_hub.errors.OfflineModeIsEnabled: | ||
| # Don't raise in offline mode, all we know is that we don't have this | ||
| # file cached. | ||
| return False | ||
|
|
||
| # Call HF to check if the file exists, with 3 retries and exponential backoff | ||
| max_retries = 3 | ||
| retry_delay = 2 | ||
| for attempt in range(max_retries): | ||
| try: | ||
| return file_exists(model, | ||
| config_name, | ||
| revision=revision, | ||
| token=HF_TOKEN) | ||
| except huggingface_hub.errors.OfflineModeIsEnabled: | ||
| # Don't raise in offline mode, all we know is that we don't have this | ||
| # file cached. | ||
| return False | ||
| except Exception as e: | ||
| logger.error(f"Error checking file existence: {e}") | ||
| if attempt == max_retries - 1: | ||
| raise | ||
| time.sleep(retry_delay) | ||
| retry_delay *= 2 | ||
|
|
||
|
|
||
| def patch_rope_scaling(config: PretrainedConfig) -> None: | ||
|
|
@@ -193,10 +204,22 @@ | |
| # raise an offline mode error to indicate to the user that they | ||
| # don't have files cached and may need to go online. | ||
| # This is conveniently triggered by calling file_exists(). | ||
| file_exists(model, | ||
| HF_CONFIG_NAME, | ||
| revision=revision, | ||
| token=HF_TOKEN) | ||
|
|
||
| # Call HF to check if the file exists, with 3 retries and exponential backoff | ||
| max_retries = 3 | ||
| retry_delay = 2 | ||
| for attempt in range(max_retries): | ||
| try: | ||
| file_exists(model, | ||
| HF_CONFIG_NAME, | ||
| revision=revision, | ||
| token=HF_TOKEN) | ||
| except Exception as e: | ||
| logger.error(f"Error checking file existence: {e}") | ||
| if attempt == max_retries - 1: | ||
| raise e | ||
| time.sleep(retry_delay) | ||
| retry_delay *= 2 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
|
|
||
| raise ValueError(f"No supported config format found in {model}") | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hmm - doesn't this mean we're printing the
logger.errorfor the first two retries but not actually raising? This can be misleading to users sometimes.Can we do something like the below?
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 yes this makes sense.. fixing