fix: hf.revision property to pin HuggingFace Hub reads#3609
Draft
kszucs wants to merge 2 commits into
Draft
Conversation
huggingface_hub.HfFileSystem resolves revision per call rather than as a filesystem-wide default, so hf.revision is threaded through as a read-time kwarg on FsspecInputFile. Writes and deletes always target the repository's default branch, since a pinned revision can be an immutable tag or commit.
hf.revision property to pin HuggingFace Hub reads
… test FsspecInputFile.exists() reimplemented exists()-via-info() with a try/except catching only FileNotFoundError, unlike fsspec's own lexists()/exists() which swallow any exception. Delegate to self._fs.exists() directly instead, which already forwards kwargs to info() with the correct broad exception handling. Also add an HF_TOKEN-gated integration test against a real (temporary) Hugging Face dataset repo, demonstrating the concrete problem this property solves: without hf.revision, reads always follow the repo's moving default branch, so a file "written" at one commit silently returns different content once someone pushes a new commit to the same path. Minor: use a _HF_SCHEMES frozenset in _get_fs_kwargs for consistency with the existing _ADLS_SCHEMES dispatch pattern, and de-duplicate/strengthen two tests that asserted only on the private _fs_kwargs attribute.
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.
Rationale for this change
HuggingFace Hub (
hf://) storage support already works viafsspec'sHfFileSystem, but has no way to pin reads to a specific revision (branch/tag/commit) for reproducibility, unlike iceberg-rust'sHF_REVISION.HfFileSystemresolvesrevisionper call rather than as a filesystem-wide default, sohf.revisionis threaded through as a read-time kwarg onFsspecInputFile. Writes and deletes intentionally always target the repository's default branch, since a pinned revision can be an immutable tag or commit and isn't a valid write target.Are these changes tested?
Yes: unit tests covering revision forwarding on reads (
len(),.exists(),.open()), confirming writes don't receive the revision kwarg, the no-revision-set default, and non-hfschemes being unaffected.Are there any user-facing changes?
Yes: new
hf.revisiontable/catalog property, documented inconfiguration.md.