Make CLI test support multi-processing
State: closed | Author: albertvillanova (MEMBER)

Support passing `--num_proc` to CLI test.

This was really useful recently to run the command on `pubmed`: https://huggingface.co/datasets/pubmed/discussions/11

Comments: The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/datasets/pr_6628). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@huggingface/datasets, feel free to review this PR so that it can be included in the next release.

<details>
<summary>Show benchmarks</summary>

PyArrow==8.0.0

<details>
<summary>Show updated benchmarks!</summary>

### 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.004907 / 0.011353 (-0.006446) | 0.003200 / 0.011008 (-0.007808) | 0.062601 / 0.038508 (0.024093) | 0.028607 / 0.023109 (0.005498) | 0.242688 / 0.275898 (-0.033210) | 0.263754 / 0.323480 (-0.059726) | 0.003084 / 0.007986 (-0.004901) | 0.002744 / 0.004328 (-0.001585) | 0.048686 / 0.004250 (0.044436) | 0.040734 / 0.037052 (0.003682) | 0.262585 / 0.258489 (0.004096) | 0.282822 / 0.293841 (-0.011019) | 0.027470 / 0.128546 (-0.101076) | 0.010356 / 0.075646 (-0.065290) | 0.206397 / 0.419271 (-0.212874) | 0.035440 / 0.043533 (-0.008093) | 0.248599 / 0.255139 (-0.006540) | 0.268869 / 0.283200 (-0.014331) | 0.018542 / 0.141683 (-0.123141) | 1.128139 / 1.452155 (-0.324016) | 1.172115 / 1.492716 (-0.320602) |

### 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.107939 / 0.018006 (0.089933) | 0.301801 / 0.000490 (0.301311) | 0.000207 / 0.000200 (0.000007) | 0.000043 / 0.000054 (-0.000012) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.018505 / 0.037411 (-0.018906) | 0.061350 / 0.014526 (0.046824) | 0.072645 / 0.176557 (-0.103912) | 0.119459 / 0.737135 (-0.617676) | 0.074711 / 0.296338 (-0.221628) |

### 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.275132 / 0.215209 (0.059922) | 2.714936 / 2.077655 (0.637281) | 1.434204 / 1.504120 (-0.069916) | 1.328358 / 1.541195 (-0.212837) | 1.320706 / 1.468490 (-0.147784) | 0.555723 / 4.584777 (-4.029054) | 2.401335 / 3.745712 (-1.344378) | 2.765609 / 5.269862 (-2.504253) | 1.715207 / 4.565676 (-2.850470) | 0.074990 / 0.424275 (-0.349285) | 0.004999 / 0.007607 (-0.002608) | 0.328435 / 0.226044 (0.102390) | 3.254945 / 2.268929 (0.986017) | 1.781105 / 55.444624 (-53.663519) | 1.509491 / 6.876477 (-5.366985) | 1.520670 / 2.142072 (-0.621402) | 0.636411 / 4.805227 (-4.168817) | 0.115616 / 6.500664 (-6.385048) | 0.041633 / 0.075469 (-0.033836) |

### 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.975462 / 1.841788 (-0.866326) | 11.480359 / 8.074308 (3.406051) | 10.528665 / 10.191392 (0.337273) | 0.141323 / 0.680424 (-0.539100) | 0.013510 / 0.534201 (-0.520691) | 0.293570 / 0.579283 (-0.285713) | 0.259956 / 0.434364 (-0.174408) | 0.331440 / 0.540337 (-0.208898) | 0.453487 / 1.386936 (-0.933449) |

</details>
PyArrow==latest

<details>
<summary>Show updated benchmarks!</summary>

### 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.005278 / 0.011353 (-0.006075) | 0.003400 / 0.011008 (-0.007608) | 0.049442 / 0.038508 (0.010934) | 0.031738 / 0.023109 (0.008628) | 0.292334 / 0.275898 (0.016436) | 0.308931 / 0.323480 (-0.014549) | 0.004290 / 0.007986 (-0.003696) | 0.002738 / 0.004328 (-0.001591) | 0.048944 / 0.004250 (0.044694) | 0.044273 / 0.037052 (0.007221) | 0.301434 / 0.258489 (0.042945) | 0.333067 / 0.293841 (0.039226) | 0.048741 / 0.128546 (-0.079805) | 0.010357 / 0.075646 (-0.065289) | 0.057777 / 0.419271 (-0.361495) | 0.033892 / 0.043533 (-0.009641) | 0.286921 / 0.255139 (0.031782) | 0.306204 / 0.283200 (0.023005) | 0.018764 / 0.141683 (-0.122919) | 1.142000 / 1.452155 (-0.310155) | 1.206728 / 1.492716 (-0.285988) |

### 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.094233 / 0.018006 (0.076227) | 0.302553 / 0.000490 (0.302063) | 0.000213 / 0.000200 (0.000013) | 0.000044 / 0.000054 (-0.000010) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.021814 / 0.037411 (-0.015598) | 0.075143 / 0.014526 (0.060617) | 0.087717 / 0.176557 (-0.088840) | 0.126079 / 0.737135 (-0.611056) | 0.089083 / 0.296338 (-0.207255) |

### 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.293844 / 0.215209 (0.078635) | 2.859481 / 2.077655 (0.781827) | 1.580366 / 1.504120 (0.076246) | 1.462633 / 1.541195 (-0.078562) | 1.471052 / 1.468490 (0.002562) | 0.574755 / 4.584777 (-4.010022) | 2.408925 / 3.745712 (-1.336787) | 2.673618 / 5.269862 (-2.596243) | 1.746218 / 4.565676 (-2.819459) | 0.063435 / 0.424275 (-0.360840) | 0.005023 / 0.007607 (-0.002584) | 0.341990 / 0.226044 (0.115946) | 3.430862 / 2.268929 (1.161933) | 1.953869 / 55.444624 (-53.490755) | 1.661276 / 6.876477 (-5.215201) | 1.761575 / 2.142072 (-0.380498) | 0.656388 / 4.805227 (-4.148839) | 0.117774 / 6.500664 (-6.382890) | 0.040290 / 0.075469 (-0.035179) |

### 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.004315 / 1.841788 (-0.837473) | 12.249719 / 8.074308 (4.175411) | 10.942703 / 10.191392 (0.751311) | 0.128552 / 0.680424 (-0.551872) | 0.015958 / 0.534201 (-0.518242) | 0.287330 / 0.579283 (-0.291953) | 0.274336 / 0.434364 (-0.160028) | 0.326233 / 0.540337 (-0.214104) | 0.414548 / 1.386936 (-0.972388) |

</details>
</details>

![](https://cml.dev/watermark.png#db47d6d95c5346368710d3c852f20ffc1b0f1c1c "CML watermark")