docstr: Checks each worker is getting sucessive indices.
docstr_tok: ["Checks","each","worker","is","getting","sucessive","indices","."]
code: def _validate(self) -> None:
      """Checks each worker is getting sucessive indices."""
      if self._num_workers > 1 and not self._cache.filled:
          batches: Dict[int, Any] = {}
          for batch_index, batch_indices in enumerate(self):
              self._length += 1
              worker_index = batch_index % self._num_workers
              if worker_index not in batches:
                  batches[worker_index] = []
                  batches[worker_index].extend(batch_indices)
              elif len(batch_indices) > 0:
                  batches[worker_index].extend(batch_indices)
  
          for indices in batches.values():
              indices = np.asarray(indices)
              diff = indices[1:] - (indices[:-1] + 1)
              if diff.sum() != 0:
                  raise RuntimeError(
                      "This shouldn't have happened. There is a bug in the CacheSampler."
                  )
  
file_path: pytorch-lightning/src/lightning/data/streaming/sampler.py
imports: import logging
  from dataclasses import dataclass
  from typing import Any, Dict, Iterator, List, Optional, Union
  import numpy
label_desc: Use image node_id 2 for calling the CacheBatchSampler obj's underlying member method code with example usage: obj._validate() without return types