[Regression] IterableDataset is broken on 2.20.0
NONE
@lhoestq I detected this regression over on [DataDreamer](https://github.com/datadreamer-dev/DataDreamer)'s test suite. I put in these [monkey patches](https://github.com/datadreamer-dev/DataDreamer/blob/4cbaf9f39cf7bedde72bbaa68346e169788fbecb/src/_patches/datasets_reset_state_hack.py) in case that fixed it our tests failing in case it helps you figure out where this is coming from. I found it hard to reason through the resumable IterableDataset code though, so hopefully you have more intuition to implement a proper fix.
2024-07-31T13:36:33Z
https://github.com/huggingface/datasets/issues/7085#issuecomment-2260545897
https://api.github.com/repos/huggingface/datasets/issues/7085
IC_kwDODunzps6GvTFp
https://api.github.com/repos/huggingface/datasets/issues/comments/2260545897/reactions
2024-07-31T13:36:33Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2260545897
https://avatars.githubusercontent.com/u/5404177?v=4
https://api.github.com/users/AjayP13/events{/privacy}
https://api.github.com/users/AjayP13/followers
https://api.github.com/users/AjayP13/following{/other_user}
https://api.github.com/users/AjayP13/gists{/gist_id}
https://github.com/AjayP13
AjayP13
MDQ6VXNlcjU0MDQxNzc=
https://api.github.com/users/AjayP13/orgs
https://api.github.com/users/AjayP13/received_events
https://api.github.com/users/AjayP13/repos
https://api.github.com/users/AjayP13/starred{/owner}{/repo}
https://api.github.com/users/AjayP13/subscriptions
User
https://api.github.com/users/AjayP13
public
NONE
I believe these lines in `TypedExamplesIterable` are responsible for stopping the re-iteration of `IterableDataset`:

https://github.com/huggingface/datasets/blob/ebec2691fb1e40145429f63375cef3f46d3011ab/src/datasets/iterable_dataset.py#L1616-L1619

In contrast to other `Iterable`s, there is no check on whether `self._state_dict` is None or not. This particular case stands out and seems less straightforward to comprehend why.  @lhoestq could you please assist us with this? Your help is much appreciated.
2024-08-14T16:04:22Z
https://github.com/huggingface/datasets/issues/7085#issuecomment-2289202848
https://api.github.com/repos/huggingface/datasets/issues/7085
IC_kwDODunzps6Icnag
https://api.github.com/repos/huggingface/datasets/issues/comments/2289202848/reactions
2024-08-14T16:04:22Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2289202848
https://avatars.githubusercontent.com/u/18899212?v=4
https://api.github.com/users/VeryLazyBoy/events{/privacy}
https://api.github.com/users/VeryLazyBoy/followers
https://api.github.com/users/VeryLazyBoy/following{/other_user}
https://api.github.com/users/VeryLazyBoy/gists{/gist_id}
https://github.com/VeryLazyBoy
VeryLazyBoy
MDQ6VXNlcjE4ODk5MjEy
https://api.github.com/users/VeryLazyBoy/orgs
https://api.github.com/users/VeryLazyBoy/received_events
https://api.github.com/users/VeryLazyBoy/repos
https://api.github.com/users/VeryLazyBoy/starred{/owner}{/repo}
https://api.github.com/users/VeryLazyBoy/subscriptions
User
https://api.github.com/users/VeryLazyBoy
public
MEMBER
Thanks for reporting for investigating - your assumption was correct @VeryLazyBoy !
2024-08-22T14:49:36Z
https://github.com/huggingface/datasets/issues/7085#issuecomment-2304867739
https://api.github.com/repos/huggingface/datasets/issues/7085
IC_kwDODunzps6JYX2b
https://api.github.com/repos/huggingface/datasets/issues/comments/2304867739/reactions
2024-08-22T14:49:36Z
https://api.github.com/repos/huggingface/datasets/issues/comments/2304867739
https://avatars.githubusercontent.com/u/42851186?v=4
https://api.github.com/users/lhoestq/events{/privacy}
https://api.github.com/users/lhoestq/followers
https://api.github.com/users/lhoestq/following{/other_user}
https://api.github.com/users/lhoestq/gists{/gist_id}
https://github.com/lhoestq
lhoestq
MDQ6VXNlcjQyODUxMTg2
https://api.github.com/users/lhoestq/orgs
https://api.github.com/users/lhoestq/received_events
https://api.github.com/users/lhoestq/repos
https://api.github.com/users/lhoestq/starred{/owner}{/repo}
https://api.github.com/users/lhoestq/subscriptions
User
https://api.github.com/users/lhoestq
public
### Describe the bug

In the latest version of datasets there is a major regression, after creating an `IterableDataset` from a generator and applying a few operations (`map`, `select`), you can no longer iterate through the dataset multiple times.

The issue seems to stem from the recent addition of "resumable IterableDatasets" (#6658) (@lhoestq). It seems like it's keeping state when it shouldn't.



### Steps to reproduce the bug

Minimal Reproducible Example (comparing `datasets==2.17.0` and `datasets==2.20.0`)

```
#!/bin/bash

# List of dataset versions to test
versions=("2.17.0" "2.20.0")

# Loop through each version
for version in "${versions[@]}"; do
    # Install the specific version of the datasets library
    pip3 install -q datasets=="$version" 2>/dev/null

    # Run the Python script
    python3 - <<EOF
from datasets import IterableDataset
from datasets.features.features import Features, Value

def test_gen():
    yield from [{"foo": i} for i in range(10)]

features = Features([("foo", Value("int64"))])
d = IterableDataset.from_generator(test_gen, features=features)
mapped = d.map(lambda row: {"foo": row["foo"] * 2})
column = mapped.select_columns(["foo"])
print("Version $version - Iterate Once:", list(column))
print("Version $version - Iterate Twice:", list(column))
EOF
done
```

The output looks like this:
```
Version 2.17.0 - Iterate Once: [{'foo': 0}, {'foo': 2}, {'foo': 4}, {'foo': 6}, {'foo': 8}, {'foo': 10}, {'foo': 12}, {'foo': 14}, {'foo': 16}, {'foo': 18}]
Version 2.17.0 - Iterate Twice: [{'foo': 0}, {'foo': 2}, {'foo': 4}, {'foo': 6}, {'foo': 8}, {'foo': 10}, {'foo': 12}, {'foo': 14}, {'foo': 16}, {'foo': 18}]
Version 2.20.0 - Iterate Once: [{'foo': 0}, {'foo': 2}, {'foo': 4}, {'foo': 6}, {'foo': 8}, {'foo': 10}, {'foo': 12}, {'foo': 14}, {'foo': 16}, {'foo': 18}]
Version 2.20.0 - Iterate Twice: []
```

### Expected behavior

The expected behavior is it version 2.20.0 should behave the same as 2.17.0.

### Environment info

`datasets==2.20.0` on any platform.