Repository navigation
docs: add "Use with Hugging Face Jobs" guide - #8717
davanstrien wants to merge 7 commits into
Conversation
Covers running datasets processing on Hugging Face Jobs: map with num_proc on a larger machine, GPUs in map with with_rank, streaming + push_to_hub, splitting work across Jobs with split_dataset_by_node, and Storage Buckets for results and caches. All examples were run on Jobs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
| # One Parquet file per source file, so that only one file is in memory at a time. | ||
| for index in range(dataset.num_shards): | ||
| part = dataset.shard(num_shards=dataset.num_shards, index=index) | ||
| part.to_parquet(f"hf://datasets/{output}/data/validation-{rank:05d}-{index:05d}.parquet") |
There was a problem hiding this comment.
it makes me think we should have push_to_hub(..., append=True) to make it easier or something like that
There was a problem hiding this comment.
yeah think that could be nice! I feel like I / my agent is implementing something like this quite often
Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>
Co-authored-by: Quentin Lhoest <42851186+lhoestq@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GPU warning: lhoestq's wording (the hang comes from pickling the model). - Multi-Job example: IterableDataset.shard + NUM_JOBS instead of split_dataset_by_node + WORLD_SIZE; drop the divisibility warning. Re-tested on 2 Jobs: 8 files, 364,608 rows (full c4 en validation). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cc @christophe-rannou, will update this in the guide when this is set Jobs side |
|
Updated the Ready for a final look / merge whenever you have a moment @lhoestq! (Side thought for a possible follow-up, not blocking this PR: since Jobs sets |
Adds a guide for processing datasets on Hugging Face Jobs, under General usage next to "Use with Spark". 🤗 Datasets works the same in a Job; the guide covers the patterns that are specific to datasets:
map(num_proc=…)on a bigger CPU machine (usingCPU_CORES, sinceos.cpu_count()reports the host's CPUs inside a Job)mapwithwith_rank: one process per GPU, with the model loaded lazily in each workerIterableDataset.push_to_hub(num_proc=…)for datasets larger than the Job's disksplit_dataset_by_nodeto_parquet/save_to_disktohf://buckets/…) and for reusing the cache across Jobs (HF_DATASETS_CACHEon a mounted bucket)General Jobs topics (streaming in general, mounts,
hf://queries with Polars and DuckDB) stay in the Hub docs and are linked rather than repeated.Every example was run on Jobs. The GPU example was tested on 1, 2 and 4 GPUs: 218, 432 and 703 rows/s on
l4x1,a10g-largex2anda10g-largex4.Opening as a draft because a couple of details may change soon:
PYTHON_CPU_COUNT/OMP_NUM_THREADSfromCPU_CORES, which may simplify thenum_procadvice.download_and_prepare("hf://buckets/…")and a remotecache_dirdon't work yet. They wait on Supportcp_file/mvfor buckets inHfFileSystem(breaks write-then-rename libraries liketorch.distributed.checkpointanddatasets) huggingface_hub#5048, so the guide doesn't use them.Two questions:
IterableDataset.to_parquetcollects the whole output in memory. It runspa.concat_tables(list(self.with_format("arrow").iter(...)))before writing (iterable_dataset.py), even though thebatch_sizedocstring suggests batch-wise writes. The multi-Job example works around this by writing one file per source shard. Is that intended? Writing batch by batch withpq.ParquetWriterwould simplify the example, and would also bound the memory ofIterableDataset.push_to_hub(num_proc): with FineWeb-Edu 10BT,num_proc=8ran out of memory at 32 GB.map: the Multiprocessing section loads the model in the main process and saysspawnis required, or you'll see aRuntimeError. When we tried that with the defaultfork, the Job hung silently instead of raising. The pattern in this guide, loading the model inside the mapped function, works withfork,forkserverandspawn, and avoids an extra model load per worker. Worth suggesting it in that section too?cc @lhoestq
🤖 Generated with Claude Code