-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
Use commit hash to look in cache instead of calling head #18534
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7dda376
Use commit hash to look in cache instead of calling head
sgugger 4da0aa6
Add tests
sgugger d3ba904
Add attr for local configs too
sgugger 1754652
Stupid typos
sgugger faef990
Fix tests
sgugger 151b90b
Update src/transformers/utils/hub.py
sgugger 7bfbc87
Address Julien's comments
sgugger 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
from typing import Iterator, List, Union | ||
from unittest import mock | ||
|
||
import huggingface_hub | ||
from transformers import logging as transformers_logging | ||
|
||
from .deepspeed import is_deepspeed_available | ||
|
@@ -1588,3 +1589,30 @@ def run_command(command: List[str], return_stdout=False): | |
raise SubprocessCallException( | ||
f"Command `{' '.join(command)}` failed with the following error:\n\n{e.output.decode()}" | ||
) from e | ||
|
||
|
||
class RequestCounter: | ||
""" | ||
Helper class that will count all requests made online. | ||
""" | ||
|
||
def __enter__(self): | ||
self.head_request_count = 0 | ||
self.get_request_count = 0 | ||
self.other_request_count = 0 | ||
self.old_request = huggingface_hub.file_download.requests.request | ||
huggingface_hub.file_download.requests.request = self.new_request | ||
return self | ||
|
||
def __exit__(self, *args, **kwargs): | ||
huggingface_hub.file_download.requests.request = self.old_request | ||
|
||
def new_request(self, method, **kwargs): | ||
if method == "GET": | ||
self.get_request_count += 1 | ||
elif method == "HEAD": | ||
self.head_request_count += 1 | ||
else: | ||
self.other_request_count += 1 | ||
|
||
return self.old_request(method=method, **kwargs) | ||
Comment on lines
+1594
to
+1618
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. OMG Python 🤯 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. Black Python magic ;-) 🪄 |
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.
Ha that's cool! Nice that we test them.