Title: Faster webdataset streaming
State: closed

requests.get(..., streaming=True) is faster than using HTTP range requests when streaming large TAR files

it can be enabled using block_size=0 in fsspec

cc @rwightman 

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

I added faster streaming support using streaming Requests instances in `huggingface_hub` and will be available in 0.21.

This PR can be used with https://github.com/huggingface/huggingface_hub/pull/1967 to get fast WebDataset streaming

<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.004941 / 0.011353 (-0.006412) | 0.003431 / 0.011008 (-0.007577) | 0.062768 / 0.038508 (0.024260) | 0.029212 / 0.023109 (0.006103) | 0.253053 / 0.275898 (-0.022845) | 0.273061 / 0.323480 (-0.050419) | 0.004114 / 0.007986 (-0.003871) | 0.002713 / 0.004328 (-0.001616) | 0.048481 / 0.004250 (0.044231) | 0.040001 / 0.037052 (0.002949) | 0.268461 / 0.258489 (0.009971) | 0.287767 / 0.293841 (-0.006074) | 0.027885 / 0.128546 (-0.100661) | 0.010474 / 0.075646 (-0.065172) | 0.207989 / 0.419271 (-0.211282) | 0.035893 / 0.043533 (-0.007640) | 0.256833 / 0.255139 (0.001694) | 0.274197 / 0.283200 (-0.009003) | 0.017283 / 0.141683 (-0.124400) | 1.133597 / 1.452155 (-0.318558) | 1.206661 / 1.492716 (-0.286055) |

### 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.089610 / 0.018006 (0.071604) | 0.306051 / 0.000490 (0.305562) | 0.000217 / 0.000200 (0.000017) | 0.000042 / 0.000054 (-0.000012) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.018686 / 0.037411 (-0.018725) | 0.061253 / 0.014526 (0.046727) | 0.073654 / 0.176557 (-0.102903) | 0.120499 / 0.737135 (-0.616637) | 0.074827 / 0.296338 (-0.221511) |

### 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.293756 / 0.215209 (0.078547) | 2.897755 / 2.077655 (0.820100) | 1.558146 / 1.504120 (0.054026) | 1.458020 / 1.541195 (-0.083174) | 1.453489 / 1.468490 (-0.015001) | 0.576666 / 4.584777 (-4.008111) | 2.423441 / 3.745712 (-1.322271) | 2.727760 / 5.269862 (-2.542102) | 1.750287 / 4.565676 (-2.815390) | 0.062094 / 0.424275 (-0.362181) | 0.004940 / 0.007607 (-0.002667) | 0.338815 / 0.226044 (0.112770) | 3.342677 / 2.268929 (1.073748) | 1.928335 / 55.444624 (-53.516290) | 1.629965 / 6.876477 (-5.246511) | 1.651836 / 2.142072 (-0.490236) | 0.644354 / 4.805227 (-4.160874) | 0.117890 / 6.500664 (-6.382774) | 0.041907 / 0.075469 (-0.033562) |

### 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.984399 / 1.841788 (-0.857389) | 11.516572 / 8.074308 (3.442264) | 10.326922 / 10.191392 (0.135530) | 0.130821 / 0.680424 (-0.549603) | 0.014084 / 0.534201 (-0.520117) | 0.287078 / 0.579283 (-0.292205) | 0.263466 / 0.434364 (-0.170898) | 0.326867 / 0.540337 (-0.213470) | 0.425313 / 1.386936 (-0.961623) |

</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.005305 / 0.011353 (-0.006048) | 0.003646 / 0.011008 (-0.007362) | 0.049402 / 0.038508 (0.010894) | 0.031719 / 0.023109 (0.008610) | 0.272579 / 0.275898 (-0.003319) | 0.295241 / 0.323480 (-0.028239) | 0.004309 / 0.007986 (-0.003677) | 0.002781 / 0.004328 (-0.001548) | 0.048134 / 0.004250 (0.043883) | 0.044702 / 0.037052 (0.007650) | 0.288201 / 0.258489 (0.029712) | 0.320351 / 0.293841 (0.026510) | 0.051327 / 0.128546 (-0.077219) | 0.011019 / 0.075646 (-0.064628) | 0.057983 / 0.419271 (-0.361288) | 0.034211 / 0.043533 (-0.009322) | 0.272856 / 0.255139 (0.017717) | 0.290007 / 0.283200 (0.006807) | 0.018656 / 0.141683 (-0.123027) | 1.135017 / 1.452155 (-0.317138) | 1.183904 / 1.492716 (-0.308813) |

### 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.090854 / 0.018006 (0.072847) | 0.299654 / 0.000490 (0.299165) | 0.000224 / 0.000200 (0.000024) | 0.000063 / 0.000054 (0.000009) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.021882 / 0.037411 (-0.015529) | 0.075297 / 0.014526 (0.060771) | 0.086620 / 0.176557 (-0.089937) | 0.127125 / 0.737135 (-0.610011) | 0.088622 / 0.296338 (-0.207717) |

### 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.287104 / 0.215209 (0.071895) | 2.802723 / 2.077655 (0.725068) | 1.570137 / 1.504120 (0.066017) | 1.452234 / 1.541195 (-0.088961) | 1.465457 / 1.468490 (-0.003033) | 0.564965 / 4.584777 (-4.019812) | 2.416724 / 3.745712 (-1.328988) | 2.645057 / 5.269862 (-2.624805) | 1.727599 / 4.565676 (-2.838078) | 0.063338 / 0.424275 (-0.360937) | 0.005018 / 0.007607 (-0.002589) | 0.345280 / 0.226044 (0.119235) | 3.384323 / 2.268929 (1.115395) | 1.957227 / 55.444624 (-53.487397) | 1.667620 / 6.876477 (-5.208856) | 1.795339 / 2.142072 (-0.346733) | 0.642049 / 4.805227 (-4.163178) | 0.114853 / 6.500664 (-6.385811) | 0.040459 / 0.075469 (-0.035010) |

### 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.023640 / 1.841788 (-0.818147) | 11.998130 / 8.074308 (3.923822) | 10.858137 / 10.191392 (0.666744) | 0.130235 / 0.680424 (-0.550189) | 0.016201 / 0.534201 (-0.518000) | 0.289743 / 0.579283 (-0.289540) | 0.275100 / 0.434364 (-0.159264) | 0.329299 / 0.540337 (-0.211039) | 0.418632 / 1.386936 (-0.968304) |

</details>
</details>

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