Skip to content

docs: add "Use with Hugging Face Jobs" guide - #8717

Open
davanstrien wants to merge 7 commits into
huggingface:mainfrom
davanstrien:docs/use-with-jobs
Open

davanstrien wants to merge 7 commits into
huggingface:mainfrom
davanstrien:docs/use-with-jobs

Conversation

@davanstrien

Copy link
Copy Markdown
Member

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 (using CPU_CORES, since os.cpu_count() reports the host's CPUs inside a Job)
  • GPUs in map with with_rank: one process per GPU, with the model loaded lazily in each worker
  • streaming, then IterableDataset.push_to_hub(num_proc=…) for datasets larger than the Job's disk
  • splitting work across several Jobs with split_dataset_by_node
  • Storage Buckets for results (to_parquet / save_to_disk to hf://buckets/…) and for reusing the cache across Jobs (HF_DATASETS_CACHE on 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-largex2 and a10g-largex4.

Opening as a draft because a couple of details may change soon:

Two questions:

  1. IterableDataset.to_parquet collects the whole output in memory. It runs pa.concat_tables(list(self.with_format("arrow").iter(...))) before writing (iterable_dataset.py), even though the batch_size docstring 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 with pq.ParquetWriter would simplify the example, and would also bound the memory of IterableDataset.push_to_hub(num_proc): with FineWeb-Edu 10BT, num_proc=8 ran out of memory at 32 GB.
  2. GPU map: the Multiprocessing section loads the model in the main process and says spawn is required, or you'll see a RuntimeError. When we tried that with the default fork, the Job hung silently instead of raising. The pattern in this guide, loading the model inside the mapped function, works with fork, forkserver and spawn, and avoids an extra model load per worker. Worth suggesting it in that section too?

cc @lhoestq

🤖 Generated with Claude Code

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>
@HuggingFaceDocBuilderDev

HuggingFaceDocBuilderDev commented Oct 1, 2026 •

Copy link
Copy Markdown

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:

@lhoestq lhoestq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really cool !

Comment thread docs/source/use_with_jobs.mdx Resolved
Comment thread docs/source/use_with_jobs.mdx Resolved
Comment thread docs/source/use_with_jobs.mdx Resolved
Comment on lines +141 to +144
# 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")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes me think we should have push_to_hub(..., append=True) to make it easier or something like that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah think that could be nice! I feel like I / my agent is implementing something like this quite often

Comment thread docs/source/use_with_jobs.mdx Resolved
davanstrien and others added 4 commits October 1, 2026 15:16
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>
@davanstrien

Copy link
Copy Markdown
Member Author

Jobs plans to set PYTHON_CPU_COUNT / OMP_NUM_THREADS from CPU_CORES, which may simplify the num_proc advice.

cc @christophe-rannou, will update this in the guide when this is set Jobs side

@davanstrien
davanstrien marked this pull request as ready for review October 2, 2026 11:06
@davanstrien

Copy link
Copy Markdown
Member Author

Updated the num_proc tip now that PYTHON_CPU_COUNT is live on Jobs (keeping CPU_CORES in the example so it also works on Python ≤ 3.12, where os.cpu_count() ignores PYTHON_CPU_COUNT), and added a quick mention of the hf_jobs dataset card tag from #9168.

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 HF_JOB_ID and CPU_CORES, would it be worth warning in map/filter if num_proc > int(CPU_CORES) — e.g. when someone passes os.cpu_count() on Python 3.12?)

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.

3 participants