Warn when a restricted Hugging Face download resolves no HUGGING_FACE_TOKEN - #540
Open
MaxGhenis wants to merge 1 commit into
Open
Warn when a restricted Hugging Face download resolves no HUGGING_FACE_TOKEN#540MaxGhenis wants to merge 1 commit into
MaxGhenis wants to merge 1 commit into
Conversation
download_huggingface_dataset keeps passing token=None through to hf_hub_download when a private repo yields no HUGGING_FACE_TOKEN (per #422: huggingface_hub then applies its own cached token, so `hf auth login` users keep working), but now emits a UserWarning first so that the bare 401 huggingface_hub raises when that fallback is empty too can be traced to the missing or unapproved token (#529). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Diagnostic follow-up to #529 (the fix for gated repos itself is #538).
download_huggingface_datasetnow emits aUserWarningwhen the repo requires authentication (model_inforeportsprivate=True, or raisesRepositoryNotFoundError) andget_or_prompt_hf_token()returnedNone. The warning names the repo, says noHUGGING_FACE_TOKENwas available, that huggingface_hub's own cached token (HF_TOKENor thehf auth loginfile) will be used if present, and that a 401 that follows (RepositoryNotFoundErrororGatedRepoError) means neither was set or the token is not approved for the repo.Behaviour is otherwise unchanged, deliberately (per #422):
token=Noneis still passed through tohf_hub_download, there is no raise, no prompt, and core does not readHF_TOKEN. The fallback is huggingface_hub's own: in 1.4.1,utils/_headers.py::get_token_to_sendcallsget_token()whentoken is None, andutils/_http.py::hf_raise_for_statusmaps a 401 toGatedRepoError(X-Error-Code: GatedRepo) orRepositoryNotFoundError.The warning uses
stacklevel=2, so it points at the caller (for exampleDataset.download_from_huggingface), and it is not emitted for public repos, which also passtoken=None. The module's import-timewarnings.catch_warnings()block is a no-op and is not relied on.Tests
TestNoTokenWarningintests/core/tools/test_hugging_face.py: the warning fires for private-flag and not-found lookups, across token unset, token empty, and only-HF_TOKEN-set environments non-interactively, and for an empty interactive prompt, withtoken=Nonepassed on and no prompt; no warning for public repos or when a token was resolved from the environment or a prompt; message content andstacklevelare asserted.uv run pytest tests/core/tools/test_hugging_face.py: 27 passed.uv run pytest tests/core: 708 passed, 1 skipped, 1 xfailed.uvx ruff format --check .anduvx ruff check .: clean.make test(full suite with coverage and reruns) andmake documentation; CI covers them and no docs pages change.Overlap with #538 and #539
Both are still open, so this branch is from
master(9125de0). Checked locally by merging each into this branch:test_download_private_repo_no_token): merges cleanly, 29 passed. Its three cases now emit this warning and tolerate it (there is nofilterwarnings = errorsetting in the repo).TestNoTokenWarningasserts the warning for the same three environments, so Fix vacuous test for private Hugging Face repo download without a token #539's test does not need to.if is_repo_private:block. Resolution: keep Send HUGGING_FACE_TOKEN for public but gated Hugging Face repos #538'srequires_authenticationpredicate and nest the warning under it. With that resolution, 33 passed.Documentation review
Warns:section in thedownload_huggingface_datasetdocstring, and the towncrier fragmentchangelog.d/warn-hf-no-token.changed.md. Nodocs/page describes this function's token handling, so nothing else needed updating.🤖 Generated with Claude Code