PipelineChunkIterator does not provide the correct length
Author: adrianeboyd
Pull request: no

### System Info

- `transformers` version: 4.28.1
- PyTorch version (GPU?): 2.0.0+cu117 (True)

### Who can help?

@Narsil

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Relatively minor in the scheme of things, but I looked into it a bit to make sure it wasn't an issue with batching.

```python
from transformers import pipeline
pipe = pipeline("token-classification")
pipe(["New York " * 600] * 2, stride=0)
```

Leads to noisy warnings from torch:

```none
/tmp/venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py:646: UserWarning: Length of IterableDataset <transformers.pipelines.pt_utils.PipelineChunkIterator object at 0x7f084a9bce50> was reported to be 2 (when accessing len(dataloader)), but 3 samples have been fetched. 
  warnings.warn(warn_msg)
/tmp/venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py:646: UserWarning: Length of IterableDataset <transformers.pipelines.pt_utils.PipelineChunkIterator object at 0x7f084a9bce50> was reported to be 2 (when accessing len(dataloader)), but 4 samples have been fetched. 
  warnings.warn(warn_msg)
/tmp/venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py:646: UserWarning: Length of IterableDataset <transformers.pipelines.pt_utils.PipelineChunkIterator object at 0x7f084a9bce50> was reported to be 2 (when accessing len(dataloader)), but 5 samples have been fetched. 
  warnings.warn(warn_msg)
/tmp/venv/lib/python3.8/site-packages/torch/utils/data/dataloader.py:646: UserWarning: Length of IterableDataset <transformers.pipelines.pt_utils.PipelineChunkIterator object at 0x7f084a9bce50> was reported to be 2 (when accessing len(dataloader)), but 6 samples have been fetched. 
  warnings.warn(warn_msg)
```

### Expected behavior

`PipelineChunkIterator` provides the intended length, no noisy warnings.

Comments:
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Hi @adrianeboyd I am experiencing this same issue. Did you manage to solve this? Or was it just a versioning thingy?

As far as I know this hasn't changed in any newer releases. I think that the implementation works in practice, but it triggers these warnings from pytorch that are trying to protect you from yourself in case you've written a faulty iterator. The problem is that it's returning as the length the number of texts rather than the number of (strided) subtexts that will be processed in the end. But with the multiple levels of iterators involved I wasn't sure how to fix it for all possible use cases.

Cool, thanks for the explanation. I had not spent time on it yet but will ignore and disable the warnings for now.

 I am having the same problem.  Hope it gets fixed soon.

I also wonder if this is a real problem or something I can ignore. 

> I also wonder if this is a real problem or something I can ignore.

i doubt that this is not a real problem

i somehow figured out when i use a qa model `Zamachi/albert-for-question-answering` these warnings are gone. 

Also having the same issue here