pass the dataset features to the IterableDataset.from_generator function
Opened by bruno-hays (closed)

[5558](https://github.com/huggingface/datasets/issues/5568)

Comments:
_The documentation is not available anymore as the PR was closed or merged._

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

PyArrow==6.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.008753 / 0.011353 (-0.002600) | 0.004877 / 0.011008 (-0.006131) | 0.098320 / 0.038508 (0.059812) | 0.034123 / 0.023109 (0.011014) | 0.289539 / 0.275898 (0.013641) | 0.323584 / 0.323480 (0.000104) | 0.007455 / 0.007986 (-0.000531) | 0.004763 / 0.004328 (0.000434) | 0.074350 / 0.004250 (0.070100) | 0.039018 / 0.037052 (0.001966) | 0.294319 / 0.258489 (0.035830) | 0.348686 / 0.293841 (0.054845) | 0.037814 / 0.128546 (-0.090732) | 0.011808 / 0.075646 (-0.063838) | 0.333808 / 0.419271 (-0.085464) | 0.047758 / 0.043533 (0.004225) | 0.298533 / 0.255139 (0.043394) | 0.320790 / 0.283200 (0.037590) | 0.095909 / 0.141683 (-0.045774) | 1.434422 / 1.452155 (-0.017732) | 1.509703 / 1.492716 (0.016987) |

### 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.201728 / 0.018006 (0.183722) | 0.432243 / 0.000490 (0.431753) | 0.002760 / 0.000200 (0.002560) | 0.000080 / 0.000054 (0.000026) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.026090 / 0.037411 (-0.011321) | 0.105914 / 0.014526 (0.091388) | 0.115869 / 0.176557 (-0.060688) | 0.178291 / 0.737135 (-0.558844) | 0.121435 / 0.296338 (-0.174904) |

### 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.402304 / 0.215209 (0.187095) | 3.995183 / 2.077655 (1.917529) | 1.794548 / 1.504120 (0.290428) | 1.603034 / 1.541195 (0.061839) | 1.643836 / 1.468490 (0.175346) | 0.694934 / 4.584777 (-3.889843) | 3.695128 / 3.745712 (-0.050584) | 2.018582 / 5.269862 (-3.251279) | 1.294315 / 4.565676 (-3.271362) | 0.085346 / 0.424275 (-0.338929) | 0.012201 / 0.007607 (0.004594) | 0.510057 / 0.226044 (0.284012) | 5.123404 / 2.268929 (2.854476) | 2.319089 / 55.444624 (-53.125535) | 1.930935 / 6.876477 (-4.945542) | 1.939700 / 2.142072 (-0.202372) | 0.848282 / 4.805227 (-3.956945) | 0.165561 / 6.500664 (-6.335103) | 0.062028 / 0.075469 (-0.013441) |

### 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.220576 / 1.841788 (-0.621212) | 14.413853 / 8.074308 (6.339544) | 14.027156 / 10.191392 (3.835764) | 0.170109 / 0.680424 (-0.510315) | 0.029412 / 0.534201 (-0.504789) | 0.443898 / 0.579283 (-0.135386) | 0.433059 / 0.434364 (-0.001305) | 0.533465 / 0.540337 (-0.006872) | 0.626562 / 1.386936 (-0.760374) |

</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.007148 / 0.011353 (-0.004205) | 0.005019 / 0.011008 (-0.005989) | 0.073132 / 0.038508 (0.034624) | 0.032763 / 0.023109 (0.009654) | 0.329309 / 0.275898 (0.053411) | 0.361658 / 0.323480 (0.038178) | 0.005683 / 0.007986 (-0.002302) | 0.003793 / 0.004328 (-0.000536) | 0.071858 / 0.004250 (0.067608) | 0.045160 / 0.037052 (0.008107) | 0.335852 / 0.258489 (0.077363) | 0.384274 / 0.293841 (0.090433) | 0.036647 / 0.128546 (-0.091899) | 0.012217 / 0.075646 (-0.063430) | 0.086265 / 0.419271 (-0.333007) | 0.049223 / 0.043533 (0.005690) | 0.331460 / 0.255139 (0.076321) | 0.353175 / 0.283200 (0.069975) | 0.102214 / 0.141683 (-0.039469) | 1.491451 / 1.452155 (0.039296) | 1.553702 / 1.492716 (0.060985) |

### 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.222972 / 0.018006 (0.204966) | 0.432862 / 0.000490 (0.432372) | 0.000421 / 0.000200 (0.000221) | 0.000059 / 0.000054 (0.000005) |

### Benchmark: benchmark_indices_mapping.json

| metric | select | shard | shuffle | sort | train_test_split |
|--------|---|---|---|---|---|
| new / old (diff) | 0.028401 / 0.037411 (-0.009010) | 0.109331 / 0.014526 (0.094805) | 0.119246 / 0.176557 (-0.057311) | 0.187997 / 0.737135 (-0.549138) | 0.124212 / 0.296338 (-0.172127) |

### 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.427240 / 0.215209 (0.212031) | 4.271619 / 2.077655 (2.193964) | 2.104948 / 1.504120 (0.600828) | 1.910624 / 1.541195 (0.369430) | 1.943812 / 1.468490 (0.475322) | 0.711466 / 4.584777 (-3.873311) | 3.778987 / 3.745712 (0.033275) | 2.976258 / 5.269862 (-2.293604) | 1.807591 / 4.565676 (-2.758086) | 0.088286 / 0.424275 (-0.335989) | 0.012461 / 0.007607 (0.004854) | 0.527554 / 0.226044 (0.301509) | 5.279461 / 2.268929 (3.010532) | 2.517911 / 55.444624 (-52.926713) | 2.176557 / 6.876477 (-4.699920) | 2.205322 / 2.142072 (0.063249) | 0.855012 / 4.805227 (-3.950215) | 0.170007 / 6.500664 (-6.330658) | 0.065273 / 0.075469 (-0.010196) |

### 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.282785 / 1.841788 (-0.559003) | 14.819500 / 8.074308 (6.745192) | 13.282211 / 10.191392 (3.090819) | 0.161804 / 0.680424 (-0.518620) | 0.017615 / 0.534201 (-0.516586) | 0.420159 / 0.579283 (-0.159124) | 0.441304 / 0.434364 (0.006940) | 0.531704 / 0.540337 (-0.008634) | 0.627477 / 1.386936 (-0.759459) |

</details>
</details>

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


Hmm I think we need to add more tests. Not sure what would happen with :
- decodable features that may end up decoded twice 
- formatted datasets 

I'd be in favor of reverting this until we checked those