Skip to content

Conversation

lhoestq
Copy link
Member

@lhoestq lhoestq commented Oct 15, 2025

(and also reorder the hffs args to improve caching)

When using DataLoader(iterable_dataset, num_workers=...) the dataset is pickled and passed to the worker. However previously the resulting dataset would be in a process with an empty hffs cache. By keeping the cache attached to IterableDataset, the cached hffs instances are pickled with the dataset and re-populates the cache in the DataLoader workers

this requires huggingface/huggingface_hub#3443 to work effectively though, otherwise the unpickled hffs cache would start empty

cc @andimarafioti @LTMeyer

@HuggingFaceDocBuilderDev

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.

Copy link
Member

@andimarafioti andimarafioti left a comment

Choose a reason for hiding this comment

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

I'll try this :)

if name == "token" and getattr(self, "storage_options", None) is not None:
if "hf" not in self.storage_options:
self.storage_options["hf"] = {"token": value, "endpoint": config.HF_ENDPOINT}
self.storage_options["hf"] = {"endpoint": config.HF_ENDPOINT, "token": value}
Copy link
Member

Choose a reason for hiding this comment

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

Did you need to make this change? seems weird since dicts aren't ordered in python

Copy link
Member Author

Choose a reason for hiding this comment

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

because fsspec cache that maps a filesystem argument to the cached instance is sensitive to the order ^^'

with those changes every instance of HfFileSystem in datasets uses the same order

storage_options = {
"token": token,
"endpoint": config.HF_ENDPOINT,
"token": token,
Copy link
Member

Choose a reason for hiding this comment

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

same, weird that you need this :S

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