Add HuggingFace storage bucket support#484
Merged
Merged
Conversation
New HuggingFaceBucketWriter for staged uploads to HF buckets via batch_bucket_files(). Fix DiskWriter retry path for bucket URLs. Bump huggingface-hub>=1.5.0. Update docs to recommend buckets for raw/intermediate data. Made-with: Cursor
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.
Problem
Datatrove had no first-class support for HF storage buckets (
hf://buckets/...). WhileHfFileSystem(fsspec) already handles bucket URLs for basic reads, the writer path had gaps:DiskWriter.close_file()would crash on retry for bucket paths (it assumed Git-repo attributes likepath_in_repo), and there was no high-level writer equivalent toHuggingFaceDatasetWriterfor staged uploads to buckets.Solution
New
HuggingFaceBucketWriter— aParquetWritersubclass that stages files locally and uploads them to a bucket viabatch_bucket_files()(Xet-optimized). Key features:create_bucket(exist_ok=True))max_file_size) and onclose()overwrite=Truemode: lists and deletes existing files at the prefix before the first uploadFixed
DiskWriter.close_file()retry path — now detectsHfFileSystemResolvedBucketPathand usesbatch_bucket_files()instead ofupload_file()for retries, soJsonlWriter/ParquetWriterwriting directly tohf://buckets/...won't crash on transient errors.Bumped
huggingface-hub>=1.5.0(from>=1.0.0) for bucket API support.Documentation — README updated to position buckets as the recommended storage for raw/intermediate data, with datasets for published data. New "HF Storage Buckets" section covers all four access patterns:
HuggingFaceBucketWriter, direct fsspec,hf-mount, and HF Jobs volume mounts.Testing
HuggingFaceBucketWriter(init, upload, overwrite, cleanup, close, file switch, full write cycle)DiskWriterbucket retry path (transient error, non-retryable, max retries, regression)DataFolderwithhf://buckets/paths (resolve, list, shard, is_local)HuggingFaceBucketWriter→ParquetReadertests/manual/for live Hub and Slurm integration — bucket writer round-trip and bucket-backedlogging_dirverified against live HubMade with Cursor
Note
Medium Risk
Touches core writer close/retry behavior and adds new upload logic against Hugging Face Hub bucket APIs, so regressions could impact pipeline output reliability under transient failures. Test coverage is expanded, but real-world behavior depends on Hub/Xet semantics and permissions.
Overview
Adds first-class support for Hugging Face storage buckets (
hf://buckets/...) by introducingHuggingFaceBucketWriter, which stages Parquet shards locally and uploads them viabatch_bucket_files, with optionaloverwrite(prefix delete-once) behavior and uploads on rotation/close.Fixes
DiskWriter.close_file()retry handling for bucket-backed fsspec files by detectingHfFileSystemResolvedBucketPathand retrying with the bucket upload API instead of repoupload_file(), preventing crashes on transient Hub errors. Also bumpshuggingface-hubto>=1.5.0, updates README guidance (buckets for raw/intermediate, datasets for publish), and adds an example plus unit/integration/manual tests covering bucket paths, logging dirs, and retry behavior.Reviewed by Cursor Bugbot for commit a06de9b. Configure here.