-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Support hfh 0.10 implicit auth #5031
Changes from all commits
3c95246
49bb38f
99dde63
536510d
e4472cf
f45116e
136a09a
82554fb
07d0b0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ | |
from typing import List, Optional, Type, TypeVar, Union | ||
from urllib.parse import urljoin, urlparse | ||
|
||
import huggingface_hub | ||
import requests | ||
from huggingface_hub import HfFolder | ||
|
||
from .. import __version__, config | ||
from ..download.download_config import DownloadConfig | ||
|
@@ -218,7 +220,9 @@ def cached_path( | |
|
||
|
||
def get_datasets_user_agent(user_agent: Optional[Union[str, dict]] = None) -> str: | ||
ua = f"datasets/{__version__}; python/{config.PY_VERSION}" | ||
ua = f"datasets/{__version__}" | ||
ua += f"; python/{config.PY_VERSION}" | ||
ua += f"; huggingface_hub/{huggingface_hub.__version__}" | ||
Comment on lines
222
to
+225
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. Would love to hear if you have ideas on how to make this easy to configure. We have the same logic in (not a suggestion to change something here, more as a general question) 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. Since it's only a few lines and pretty easy to modify it, I don't think we can make something significantly better than that |
||
ua += f"; pyarrow/{config.PYARROW_VERSION}" | ||
if config.TORCH_AVAILABLE: | ||
ua += f"; torch/{config.TORCH_VERSION}" | ||
|
@@ -239,13 +243,13 @@ def get_authentication_headers_for_url(url: str, use_auth_token: Optional[Union[ | |
"""Handle the HF authentication""" | ||
headers = {} | ||
if url.startswith(config.HF_ENDPOINT): | ||
token = None | ||
if isinstance(use_auth_token, str): | ||
if use_auth_token is False: | ||
token = None | ||
elif isinstance(use_auth_token, str): | ||
token = use_auth_token | ||
elif bool(use_auth_token): | ||
from huggingface_hub import hf_api | ||
else: | ||
token = HfFolder.get_token() | ||
|
||
token = hf_api.HfFolder.get_token() | ||
if token: | ||
headers["authorization"] = f"Bearer {token}" | ||
return headers | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,9 @@ | |
UNSUPPORTED_ON_WINDOWS = {"code_eval"} | ||
_on_windows = os.name == "nt" | ||
|
||
REQUIRE_TRANSFORMERS = {"bertscore", "frugalscore", "perplexity"} | ||
_has_transformers = importlib.util.find_spec("transformers") is not None | ||
|
||
|
||
def skip_if_metric_requires_fairseq(test_case): | ||
@wraps(test_case) | ||
|
@@ -50,6 +53,17 @@ def wrapper(self, metric_name): | |
return wrapper | ||
|
||
|
||
def skip_if_metric_requires_transformers(test_case): | ||
@wraps(test_case) | ||
def wrapper(self, metric_name): | ||
if not _has_transformers and metric_name in REQUIRE_TRANSFORMERS: | ||
self.skipTest('"test requires transformers"') | ||
else: | ||
test_case(self, metric_name) | ||
|
||
return wrapper | ||
|
||
|
||
Comment on lines
+56
to
+66
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. Why have you added this? 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. I had an env without transformers and I had failing tests x) so I did the same as for other optional deps: excluding the tests when it's not installed |
||
def skip_on_windows_if_not_windows_compatible(test_case): | ||
@wraps(test_case) | ||
def wrapper(self, metric_name): | ||
|
@@ -67,7 +81,9 @@ def get_local_metric_names(): | |
|
||
|
||
@parameterized.named_parameters(get_local_metric_names()) | ||
@for_all_test_methods(skip_if_metric_requires_fairseq, skip_on_windows_if_not_windows_compatible) | ||
@for_all_test_methods( | ||
skip_if_metric_requires_fairseq, skip_if_metric_requires_transformers, skip_on_windows_if_not_windows_compatible | ||
) | ||
@local | ||
@pytest.mark.integration | ||
class LocalMetricTest(parameterized.TestCase): | ||
|
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.
I think you can remove this line because
hf_api
is no longer used in this method?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.
It's still used in hf_api_dataset_info(hf_api, ...) a few lines later ;)