Speed up local 'get_data_patterns' by avoiding repeated recursive scans#8014
Open
AsymptotaX wants to merge 2 commits intohuggingface:mainfrom
Open
Speed up local 'get_data_patterns' by avoiding repeated recursive scans#8014AsymptotaX wants to merge 2 commits intohuggingface:mainfrom
AsymptotaX wants to merge 2 commits intohuggingface:mainfrom
Conversation
lhoestq
approved these changes
Feb 24, 2026
Member
lhoestq
left a comment
There was a problem hiding this comment.
lgtm ! can you run make style to fix the CI before we merge ?
|
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. |
Author
done. All good, no warnings. |
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.
This PR speeds up
get_data_patternsfor local paths.Problem
For
load_dataset("imagefolder", data_dir=...),get_data_patternswas repeatedly scanning the same local directory tree for many split patterns (train,test, etc.).With large folders, this became very slow. This has also been reported before in earlier performance discussions/issues.
Change
In
get_data_patterns(local paths only):resolve_pattern("**", ...))Remote paths keep the old behavior.
No API changes.
My Env
Benchmarks
imagefolderwith local.jpgfilesdata_dir_only:4.35s -> 1.40s(3.10x)33.48s -> 9.77s(3.43x)160.20s -> 35.81s(4.47x)1877.70s -> 164.17s(11.44x) 🔥explicit_data_files:0.75s -> 0.79s7.23s -> 7.29s25.44s -> 24.26s115.85s -> 112.66sAs expected, the improvement is on
data_dir_only(auto pattern detection path).Memory usage did not show a consistent regression in these runs and stayed within normal run-to-run variance for this benchmark setup.