code: def _replay_chunks_sampling(
      workers_intervals: Dict[int, List[Any]], indexes: Dict[int, int]
  ) -> Tuple[Dict[int, int], Dict[int, int]]:
      chunks_index = {}
  
      for worker_idx in range(len(workers_intervals)):
          chunks_index[worker_idx] = 0
  
      for worker_idx, intervals in workers_intervals.items():
          for interval in intervals:
              size = interval[-1] - interval[0]
              if indexes[worker_idx] >= size:
                  indexes[worker_idx] -= size
                  chunks_index[worker_idx] += 1
  
      return chunks_index, indexes
  
imports: import hashlib
  import os
  from dataclasses import dataclass
  from time import time
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from torch.utils.data import IterableDataset, get_worker_info
  from lightning.data.streaming import Cache
  from lightning.data.streaming.constants import _DEFAULT_CACHE_DIR, _INDEX_FILENAME, _LIGHTNING_CLOUD_LATEST
  from lightning.data.streaming.item_loader import BaseItemLoader
  from lightning.data.streaming.sampler import ChunkedIndex
  from lightning.data.streaming.serializers import Serializer
  from lightning.data.streaming.shuffle import FullShuffle, NoShuffle, Shuffle
  from lightning.data.utilities.env import Environment, _DistributedEnv, _WorkerEnv
label_desc: Use image node_id 7 for calling a global function with example usage: _replay_chunks_sampling(workers_intervals, indexes) and returns: chunks_index,  indexes