Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate config name and data_files in packaged modules #6915

Merged
merged 7 commits into from
Jun 6, 2024

Conversation

albertvillanova
Copy link
Member

Validate the config attributes name and data_files in packaged modules by making the derived classes call their parent __post_init__ method.

Note that their parent BuilderConfig validates its attributes name and data_files in its __post_init__ method:

def __post_init__(self):
# The config name is used to name the cache directory.
for invalid_char in INVALID_WINDOWS_CHARACTERS_IN_PATH:
if invalid_char in self.name:
raise InvalidConfigName(
f"Bad characters from black list '{INVALID_WINDOWS_CHARACTERS_IN_PATH}' found in '{self.name}'. "
f"They could create issues when creating a directory for this config on Windows filesystem."
)
if self.data_files is not None and not isinstance(self.data_files, (DataFilesDict, DataFilesPatternsDict)):
raise ValueError(f"Expected a DataFilesDict in data_files but got {self.data_files}")

This PR makes the derived config classes call their parent __post_init__ method to validate their name and data_files attributes.

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

@@ -1749,7 +1749,7 @@ def test_resolve_trust_remote_code_future(trust_remote_code, expected):
def test_reload_old_cache_from_2_15(tmp_path: Path):
cache_dir = tmp_path / "test_reload_old_cache_from_2_15"
builder_cache_dir = (
cache_dir / "polinaeterna___audiofolder_two_configs_in_metadata/v2-374bfde4f55442bc/0.0.0/7896925d64deea5d"
cache_dir / "polinaeterna___audiofolder_two_configs_in_metadata/v2-374bfde4f55442bc/0.0.0/cf191ad706de653e"
Copy link
Member Author

Choose a reason for hiding this comment

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

@lhoestq note that the hash now will be different from before this PR. I hope this does not have a negative impact...

Copy link
Member

Choose a reason for hiding this comment

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

ah it's not supposed to change if we want to support reloading old cache directories

Copy link
Member Author

@albertvillanova albertvillanova Jun 5, 2024

Choose a reason for hiding this comment

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

@lhoestq then we cannot change the packaged builders code anymore?

@lhoestq
Copy link
Member

lhoestq commented Jun 5, 2024

I pushed a change that fixes 2.15 cache reloading (I fixed the packaged module hash), feel free to merge if this change is fine for you

Copy link
Member Author

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

@lhoestq then we cannot change the packaged builders code anymore?

Oh, I saw your fix!
That will make the code more stable against future changes in the package builder files. Thanks.

@albertvillanova
Copy link
Member Author

albertvillanova commented Jun 6, 2024

Something weird happened in GitHub: I just merged this PR to main, See: 5bbbf1b

However this PR still appears as Open...

If I retry to merge this PR, an error appears: "Merge attempt failed: Merge already in progress"
Screenshot from 2024-06-06 06-29-22

@albertvillanova albertvillanova merged commit 09ebf51 into main Jun 6, 2024
12 checks passed
@albertvillanova albertvillanova deleted the fix-packaged-configs branch June 6, 2024 09:24
albertvillanova added a commit that referenced this pull request Jun 6, 2024
Copy link

github-actions bot commented Jun 6, 2024

Show benchmarks

PyArrow==8.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.005543 / 0.011353 (-0.005810) 0.004059 / 0.011008 (-0.006949) 0.064678 / 0.038508 (0.026170) 0.032615 / 0.023109 (0.009506) 0.245883 / 0.275898 (-0.030015) 0.273545 / 0.323480 (-0.049935) 0.004268 / 0.007986 (-0.003718) 0.003160 / 0.004328 (-0.001168) 0.051982 / 0.004250 (0.047731) 0.051186 / 0.037052 (0.014134) 0.254009 / 0.258489 (-0.004480) 0.289594 / 0.293841 (-0.004247) 0.028459 / 0.128546 (-0.100087) 0.011061 / 0.075646 (-0.064585) 0.203571 / 0.419271 (-0.215700) 0.038049 / 0.043533 (-0.005484) 0.243700 / 0.255139 (-0.011439) 0.264816 / 0.283200 (-0.018383) 0.019556 / 0.141683 (-0.122127) 1.114395 / 1.452155 (-0.337759) 1.168915 / 1.492716 (-0.323802)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.098814 / 0.018006 (0.080808) 0.308218 / 0.000490 (0.307728) 0.000221 / 0.000200 (0.000022) 0.000047 / 0.000054 (-0.000008)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.019660 / 0.037411 (-0.017752) 0.070542 / 0.014526 (0.056017) 0.078906 / 0.176557 (-0.097650) 0.126658 / 0.737135 (-0.610477) 0.080427 / 0.296338 (-0.215911)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.280686 / 0.215209 (0.065477) 2.767480 / 2.077655 (0.689825) 1.455325 / 1.504120 (-0.048795) 1.336677 / 1.541195 (-0.204518) 1.380359 / 1.468490 (-0.088131) 0.576310 / 4.584777 (-4.008467) 2.431829 / 3.745712 (-1.313883) 2.815266 / 5.269862 (-2.454595) 1.908962 / 4.565676 (-2.656714) 0.065306 / 0.424275 (-0.358969) 0.005229 / 0.007607 (-0.002378) 0.336018 / 0.226044 (0.109973) 3.349283 / 2.268929 (1.080355) 1.814696 / 55.444624 (-53.629929) 1.520969 / 6.876477 (-5.355508) 1.735322 / 2.142072 (-0.406751) 0.661513 / 4.805227 (-4.143714) 0.121465 / 6.500664 (-6.379199) 0.044505 / 0.075469 (-0.030964)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 0.989204 / 1.841788 (-0.852584) 12.608414 / 8.074308 (4.534106) 10.133358 / 10.191392 (-0.058034) 0.133986 / 0.680424 (-0.546438) 0.014332 / 0.534201 (-0.519869) 0.293207 / 0.579283 (-0.286076) 0.265657 / 0.434364 (-0.168707) 0.325972 / 0.540337 (-0.214365) 0.478103 / 1.386936 (-0.908833)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.006070 / 0.011353 (-0.005283) 0.004122 / 0.011008 (-0.006886) 0.050572 / 0.038508 (0.012064) 0.033732 / 0.023109 (0.010623) 0.271282 / 0.275898 (-0.004616) 0.296247 / 0.323480 (-0.027233) 0.004400 / 0.007986 (-0.003585) 0.002914 / 0.004328 (-0.001415) 0.049332 / 0.004250 (0.045082) 0.042213 / 0.037052 (0.005161) 0.281230 / 0.258489 (0.022741) 0.315514 / 0.293841 (0.021673) 0.030864 / 0.128546 (-0.097682) 0.011185 / 0.075646 (-0.064461) 0.059227 / 0.419271 (-0.360044) 0.034006 / 0.043533 (-0.009527) 0.270059 / 0.255139 (0.014920) 0.284014 / 0.283200 (0.000814) 0.019502 / 0.141683 (-0.122181) 1.143650 / 1.452155 (-0.308505) 1.190968 / 1.492716 (-0.301749)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.100502 / 0.018006 (0.082496) 0.307863 / 0.000490 (0.307373) 0.000212 / 0.000200 (0.000012) 0.000043 / 0.000054 (-0.000012)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.023442 / 0.037411 (-0.013969) 0.080185 / 0.014526 (0.065659) 0.089372 / 0.176557 (-0.087185) 0.131030 / 0.737135 (-0.606105) 0.091174 / 0.296338 (-0.205165)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.304187 / 0.215209 (0.088978) 3.043055 / 2.077655 (0.965400) 1.629578 / 1.504120 (0.125459) 1.533762 / 1.541195 (-0.007432) 1.546134 / 1.468490 (0.077643) 0.577739 / 4.584777 (-4.007038) 0.986310 / 3.745712 (-2.759402) 2.791650 / 5.269862 (-2.478212) 1.841190 / 4.565676 (-2.724487) 0.064943 / 0.424275 (-0.359333) 0.005251 / 0.007607 (-0.002356) 0.355009 / 0.226044 (0.128965) 3.560935 / 2.268929 (1.292007) 1.991995 / 55.444624 (-53.452629) 1.708796 / 6.876477 (-5.167681) 1.917721 / 2.142072 (-0.224351) 0.667667 / 4.805227 (-4.137561) 0.119956 / 6.500664 (-6.380708) 0.042069 / 0.075469 (-0.033400)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.006242 / 1.841788 (-0.835546) 13.321644 / 8.074308 (5.247336) 10.712409 / 10.191392 (0.521017) 0.134036 / 0.680424 (-0.546388) 0.017645 / 0.534201 (-0.516555) 0.289077 / 0.579283 (-0.290206) 0.131356 / 0.434364 (-0.303007) 0.333062 / 0.540337 (-0.207275) 0.425327 / 1.386936 (-0.961609)

@albertvillanova
Copy link
Member Author

albertvillanova commented Jun 6, 2024

Indeed, the merge commit is: 5bbbf1b

The following commit is just empty: 09ebf51

lhoestq added a commit to EthanSteinberg/datasets that referenced this pull request Jun 7, 2024
…6915)

* Make configs call super post_init in packaged modules

* Update hash in test

* Add tests

* Add tests for BuilderConfig

* Fix syntax

* use old hash for 2.15 cache reload

---------

Co-authored-by: Quentin Lhoest <lhoest.q@gmail.com>
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