code: def test_resumable_dataset_two_workers(tmpdir):
      seed_everything(42)
  
      data_dir = os.path.join(tmpdir, "data")
      cache_dir = os.path.join(tmpdir, "cache_dir")
  
      os.makedirs(data_dir)
      os.makedirs(cache_dir)
  
      block_size = 20
      cache = Cache(
          input_dir=str(data_dir),
          chunk_size=40,
          item_loader=TokensLoader(block_size),
      )
  
      counter = 0
      for i in range(100):
          text_ids = torch.arange(counter, counter + 20).to(torch.int)
          cache[i] = text_ids
          counter += 20
  
      cache.done()
      cache.merge()
  
      assert (
          len([f for f in os.listdir(data_dir) if f.endswith(".bin")])
          == 50
      )
  
      dataset = EmulateS3StreamingDataset(
          input_dir=RemoteDir(cache_dir, data_dir),
          item_loader=TokensLoader(block_size),
          shuffle=True,
      )
  
      dataset.current_epoch = 1
      dataloader = StreamingDataLoader(
          dataset, num_workers=2, batch_size=2, prefetch_factor=1
      )
  
      dataloader_iter = iter(dataloader)
  
      _ = next(dataloader_iter)
      state_dict_0 = dataloader.state_dict()
      assert state_dict_0["0"]["num_samples_yielded"] == 2
      assert state_dict_0["0"]["num_workers"] == 2
      assert state_dict_0["0"]["batch_size"] == 2
  
      _ = next(dataloader_iter)
      state_dict_1 = dataloader.state_dict()
      assert state_dict_1["0"]["num_samples_yielded"] == 4
      assert state_dict_1["0"]["num_workers"] == 2
      assert state_dict_1["0"]["batch_size"] == 2
  
      batch_2 = next(dataloader_iter)
      state_dict_2 = dataloader.state_dict()
      assert state_dict_2["0"]["num_samples_yielded"] == 6
      assert state_dict_2["0"]["num_workers"] == 2
      assert state_dict_2["0"]["batch_size"] == 2
  
      dataset = EmulateS3StreamingDataset(
          input_dir=RemoteDir(cache_dir, data_dir),
          item_loader=TokensLoader(block_size),
          shuffle=True,
      )
  
      dataset.load_state_dict(state_dict_1)
      dataloader = StreamingDataLoader(
          dataset, num_workers=2, batch_size=2, prefetch_factor=1
      )
  
      dataloader_iter = iter(dataloader)
      batch_0_restart = next(dataloader_iter)
  
      state_dict_2 = dataloader.state_dict()
      assert len(state_dict_2) == 2
      assert state_dict_2["0"]["num_samples_yielded"] == 4
      assert state_dict_2["0"]["num_workers"] == 2
      assert state_dict_2["0"]["batch_size"] == 2
  
      assert state_dict_2["1"]["num_samples_yielded"] == 2
      assert state_dict_2["1"]["num_workers"] == 2
      assert state_dict_2["1"]["batch_size"] == 2
  
      assert torch.equal(batch_2, batch_0_restart)
  
imports: import os
  import sys
  from time import sleep
  from unittest import mock
  import numpy
  import pytest
  import torch
  from lightning import seed_everything
  from lightning.data.streaming import Cache, functions
  from lightning.data.streaming.dataloader import StreamingDataLoader
  from lightning.data.streaming.dataset import _INDEX_FILENAME, Dir, RemoteDir, StreamingDataset, _associate_chunks_to_workers, _replay_chunks_sampling, _replay_sampling, _should_replace_path, _try_create_cache_dir
  from lightning.data.streaming.item_loader import TokensLoader
  from lightning.data.streaming.shuffle import FullShuffle, NoShuffle
  from lightning.data.utilities.env import Environment, _DistributedEnv, _WorkerEnv
  from torch.utils.data import DataLoader
label_desc: Use image node_id 15 for calling a global function with example usage: test_resumable_dataset_two_workers(tmpdir) without return types