Skip to content

Commit

Permalink
Deprecate num_proc parameter in DownloadManager.extract (#5142)
Browse files Browse the repository at this point in the history
* deprecate num_proc

* fix the reviewed changes

* fix the reviewed changes -2

* fix the reviewed changes -3

* format the code
  • Loading branch information
ayushthe1 authored Oct 25, 2022
1 parent f09f781 commit d12fbc1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/datasets/download/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import posixpath
import tarfile
import warnings
from datetime import datetime
from functools import partial
from typing import Callable, Dict, Generator, Iterable, List, Optional, Tuple, Union
Expand Down Expand Up @@ -377,7 +378,7 @@ def iter_files(self, paths: Union[str, List[str]]):
"""
return FilesIterable.from_paths(paths)

def extract(self, path_or_paths, num_proc=None):
def extract(self, path_or_paths, num_proc="deprecated"):
"""Extract given path(s).
Args:
Expand All @@ -386,6 +387,12 @@ def extract(self, path_or_paths, num_proc=None):
num_proc: Use multi-processing if `num_proc` > 1 and the length of
`path_or_paths` is larger than `num_proc`
<Deprecated version="2.6.2">
Pass `DownloadConfig(num_proc=<num_proc>)` to the initializer instead.
</Deprecated>
Returns:
extracted_path(s): `str`, The extracted paths matching the given input
path_or_paths.
Expand All @@ -397,15 +404,22 @@ def extract(self, path_or_paths, num_proc=None):
>>> extracted_files = dl_manager.extract(downloaded_files)
```
"""
if num_proc != "deprecated":
warnings.warn(
"'num_proc' was deprecated in version 2.6.2 and will be removed in 3.0.0. Pass `DownloadConfig(num_proc=<num_proc>)` to the initializer instead.",
FutureWarning,
)
download_config = self.download_config.copy()
download_config.extract_compressed_file = True
# Extract downloads the file first if it is not already downloaded
if download_config.download_desc is None:
download_config.download_desc = "Downloading data"
if download_config.num_proc is None:
download_config.num_proc = 16
extracted_paths = map_nested(
partial(cached_path, download_config=download_config),
path_or_paths,
num_proc=num_proc,
num_proc=download_config.num_proc,
disable_tqdm=not is_progress_bar_enabled(),
desc="Extracting data files",
)
Expand Down

1 comment on commit d12fbc1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Show benchmarks

PyArrow==6.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.020205 / 0.011353 (0.008852) 0.008094 / 0.011008 (-0.002915) 0.166818 / 0.038508 (0.128310) 0.050338 / 0.023109 (0.027229) 0.516798 / 0.275898 (0.240900) 0.552725 / 0.323480 (0.229245) 0.010603 / 0.007986 (0.002618) 0.006403 / 0.004328 (0.002074) 0.136289 / 0.004250 (0.132038) 0.062552 / 0.037052 (0.025499) 0.495094 / 0.258489 (0.236604) 0.563468 / 0.293841 (0.269627) 0.077307 / 0.128546 (-0.051239) 0.026095 / 0.075646 (-0.049551) 0.520522 / 0.419271 (0.101250) 0.066162 / 0.043533 (0.022629) 0.481684 / 0.255139 (0.226545) 0.561132 / 0.283200 (0.277932) 0.138496 / 0.141683 (-0.003186) 2.324939 / 1.452155 (0.872784) 2.288497 / 1.492716 (0.795781)

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.329313 / 0.018006 (0.311307) 0.761346 / 0.000490 (0.760856) 0.004293 / 0.000200 (0.004093) 0.000193 / 0.000054 (0.000139)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.039086 / 0.037411 (0.001674) 0.169533 / 0.014526 (0.155008) 0.178694 / 0.176557 (0.002137) 0.273387 / 0.737135 (-0.463749) 0.189026 / 0.296338 (-0.107313)

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.827812 / 0.215209 (0.612603) 7.877774 / 2.077655 (5.800120) 3.295759 / 1.504120 (1.791639) 2.636258 / 1.541195 (1.095063) 2.821525 / 1.468490 (1.353035) 1.453647 / 4.584777 (-3.131130) 6.843524 / 3.745712 (3.097811) 5.914575 / 5.269862 (0.644713) 3.325797 / 4.565676 (-1.239880) 0.176416 / 0.424275 (-0.247859) 0.019421 / 0.007607 (0.011814) 1.023517 / 0.226044 (0.797473) 10.128025 / 2.268929 (7.859096) 4.080445 / 55.444624 (-51.364179) 3.099578 / 6.876477 (-3.776898) 3.485353 / 2.142072 (1.343280) 1.810329 / 4.805227 (-2.994898) 0.322976 / 6.500664 (-6.177689) 0.089507 / 0.075469 (0.014038)

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) 2.503122 / 1.841788 (0.661335) 20.690944 / 8.074308 (12.616635) 55.128139 / 10.191392 (44.936747) 1.519151 / 0.680424 (0.838728) 0.946113 / 0.534201 (0.411912) 0.729444 / 0.579283 (0.150161) 0.782166 / 0.434364 (0.347802) 0.495323 / 0.540337 (-0.045014) 0.432301 / 1.386936 (-0.954635)
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.015485 / 0.011353 (0.004132) 0.006683 / 0.011008 (-0.004326) 0.186077 / 0.038508 (0.147569) 0.053878 / 0.023109 (0.030769) 0.447326 / 0.275898 (0.171427) 0.572410 / 0.323480 (0.248930) 0.009582 / 0.007986 (0.001596) 0.007205 / 0.004328 (0.002876) 0.133175 / 0.004250 (0.128925) 0.059330 / 0.037052 (0.022278) 0.554467 / 0.258489 (0.295978) 0.661527 / 0.293841 (0.367687) 0.082020 / 0.128546 (-0.046527) 0.020737 / 0.075646 (-0.054909) 0.571299 / 0.419271 (0.152028) 0.086138 / 0.043533 (0.042606) 0.449499 / 0.255139 (0.194360) 0.621071 / 0.283200 (0.337871) 0.150990 / 0.141683 (0.009307) 2.538458 / 1.452155 (1.086303) 2.571620 / 1.492716 (1.078903)

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.354393 / 0.018006 (0.336387) 0.780882 / 0.000490 (0.780392) 0.001312 / 0.000200 (0.001112) 0.000153 / 0.000054 (0.000098)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.038930 / 0.037411 (0.001518) 0.134403 / 0.014526 (0.119877) 0.151682 / 0.176557 (-0.024874) 0.243044 / 0.737135 (-0.494092) 0.143890 / 0.296338 (-0.152448)

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.682030 / 0.215209 (0.466821) 8.178116 / 2.077655 (6.100461) 3.814623 / 1.504120 (2.310503) 3.074840 / 1.541195 (1.533646) 3.321638 / 1.468490 (1.853148) 1.806384 / 4.584777 (-2.778393) 7.068638 / 3.745712 (3.322926) 4.178412 / 5.269862 (-1.091450) 2.692273 / 4.565676 (-1.873403) 0.149171 / 0.424275 (-0.275104) 0.015107 / 0.007607 (0.007500) 1.089143 / 0.226044 (0.863099) 10.884615 / 2.268929 (8.615686) 4.772737 / 55.444624 (-50.671888) 3.855731 / 6.876477 (-3.020746) 4.130249 / 2.142072 (1.988176) 2.029597 / 4.805227 (-2.775630) 0.349781 / 6.500664 (-6.150883) 0.107896 / 0.075469 (0.032426)

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) 2.186203 / 1.841788 (0.344416) 21.227150 / 8.074308 (13.152842) 30.303267 / 10.191392 (20.111875) 1.597685 / 0.680424 (0.917261) 1.107459 / 0.534201 (0.573258) 0.755568 / 0.579283 (0.176285) 0.839893 / 0.434364 (0.405529) 0.460053 / 0.540337 (-0.080285) 0.400778 / 1.386936 (-0.986158)

CML watermark

Please sign in to comment.