code: def adapt_batch_sampler(
      batch_sampler: torch.utils.data.BatchSampler,
      repeat: bool = False,
      skip: int = 0,
      num_replicas: int = 1,
      rank: int = 0,
  ) -> torch.utils.data.BatchSampler:
      """
      Modify the underlying BatchSampler of a constructed DataLoader to account
      for repeating on training datasets, skipping when continuing training, and
      sharding for distributed training.
      """
      if repeat:
          batch_sampler = samplers.RepeatBatchSampler(batch_sampler)
  
      if num_replicas > 1:
          batch_sampler = samplers.DistributedBatchSampler(
              batch_sampler, num_replicas, rank
          )
  
      # SkipBatchSampler is used when we are continuing training. SkipBatchSampler must be applied
      # after DistributedBatchSampler, since the number of batches to skip is based on how many
      # global batches should be skipped, which corresponds with how many batches are emitted by the
      # DistributedBatchSampler, not the initial BatchSampler.
      if skip > 0:
          batch_sampler = samplers.SkipBatchSampler(batch_sampler, skip)
  
      return batch_sampler
  
file_path: determined/harness/determined/pytorch/_data.py
imports: import logging
  from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Set, Type, TypeVar, Union, cast
  import numpy
  import torch
  from packaging import version
  from torch.utils.data import BatchSampler, Dataset, RandomSampler, Sampler, SequentialSampler, _utils
  from determined.pytorch import samplers
label_desc: Use image node_id 2 for calling a global function with example usage: adapt_batch_sampler(batch_sampler, repeat, skip, num_replicas, rank) and returns: batch_sampler