code: def _make_sampler(
      *,
      dataset,
      type: Optional[SamplerType] = None,
      shuffle: bool = False,
      seed: int = 0,
      size: int = -1,
      advance: int = 0,
  ) -> Optional[Sampler]:
      sample_count = len(dataset)
  
      if type == SamplerType.INFINITE:
          logger.info("sampler: infinite")
          if size > 0:
              raise ValueError("sampler size > 0 is invalid")
          return InfiniteSampler(
              sample_count=sample_count,
              shuffle=shuffle,
              seed=seed,
              advance=advance,
          )
      elif type in (
          SamplerType.SHARDED_INFINITE,
          SamplerType.SHARDED_INFINITE_NEW,
      ):
          logger.info("sampler: sharded infinite")
          if size > 0:
              raise ValueError("sampler size > 0 is invalid")
          # TODO: Remove support for old shuffling
          use_new_shuffle_tensor_slice = (
              type == SamplerType.SHARDED_INFINITE_NEW
          )
          return ShardedInfiniteSampler(
              sample_count=sample_count,
              shuffle=shuffle,
              seed=seed,
              advance=advance,
              use_new_shuffle_tensor_slice=use_new_shuffle_tensor_slice,
          )
      elif type == SamplerType.EPOCH:
          logger.info("sampler: epoch")
          if advance > 0:
              raise NotImplementedError(
                  "sampler advance > 0 is not supported"
              )
          size = size if size > 0 else sample_count
          logger.info(f"# of samples / epoch: {size:,d}")
          return EpochSampler(
              size=size,
              sample_count=sample_count,
              shuffle=shuffle,
              seed=seed,
          )
      elif type == SamplerType.DISTRIBUTED:
          logger.info("sampler: distributed")
          if size > 0:
              raise ValueError("sampler size > 0 is invalid")
          if advance > 0:
              raise ValueError("sampler advance > 0 is invalid")
          return torch.utils.data.DistributedSampler(
              dataset=dataset,
              shuffle=shuffle,
              seed=seed,
              drop_last=False,
          )
  
      logger.info("sampler: none")
      return None
  
file_path: dinov2/dinov2/data/loaders.py
imports: import logging
  from enum import Enum
  from typing import Any, Callable, List, Optional, TypeVar
  import torch
  from torch.utils.data import Sampler
  from .datasets import ImageNet, ImageNet22k
  from .samplers import EpochSampler, InfiniteSampler, ShardedInfiniteSampler
label_desc: Use image node_id 5 for calling a global function with example usage: _make_sampler() and returns: None, InfiniteSampler, ShardedInfiniteSampler, EpochSampler, torch