Skip to content

fix: hf.revision property to pin HuggingFace Hub reads#3609

Draft
kszucs wants to merge 2 commits into
apache:mainfrom
kszucs:feat/hf-revision-property
Draft

fix: hf.revision property to pin HuggingFace Hub reads#3609
kszucs wants to merge 2 commits into
apache:mainfrom
kszucs:feat/hf-revision-property

Conversation

@kszucs

@kszucs kszucs commented Jul 6, 2026

Copy link
Copy Markdown
Member

Rationale for this change

HuggingFace Hub (hf://) storage support already works via fsspec's HfFileSystem, but has no way to pin reads to a specific revision (branch/tag/commit) for reproducibility, unlike iceberg-rust's HF_REVISION. 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 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-hf schemes being unaffected.

Are there any user-facing changes?

Yes: new hf.revision table/catalog property, documented in configuration.md.

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.
@kszucs kszucs changed the title Add hf.revision property to pin HuggingFace Hub reads fix: hf.revision property to pin HuggingFace Hub reads Jul 6, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant