class_docstr: CudaDataPrefetcher prefetches batches and moves them to the device.
  
  This class can be used to interleave data loading, host-to-device copies, and computation more effectively.
  
  Args:
  
      data_iterable: an Iterable containing the data to use for CudaDataPrefetcher construction
      device: the device to which data should be moved
      num_prefetch_batches: number of batches to prefetch
  
  Note:
  
      We recommend users leverage memory pinning when constructing their dataloader:
      https://pytorch.org/docs/stable/data.html#memory-pinning.
  
  Example::
  
      dataloader = ...
      device = torch.device("cuda")
      num_prefetch_batches = 2
      data_prefetcher = CudaDataPrefetcher(dataloader, device, num_prefetch_batches)
      for batch in data_prefetcher:
          # batch is already on device
          # operate on batch
class_docstr_tok: ["CudaDataPrefetcher","prefetches","batches","and","moves","them","to","the","device",".","This","class","can","be","used","to","interleave","data","loading",",","host-to-device","copies",",","and","computation","more","effectively",".","Args",":","data_iterable",":","an","Iterable","containing","the","data","to","use","for","CudaDataPrefetcher","construction","device",":","the","device","to","which","data","should","be","moved","num_prefetch_batches",":","number","of","batches","to","prefetch","Note",":","We","recommend","users","leverage","memory","pinning","when","constructing","their","dataloader",":","https",":","\/\/pytorch.org\/docs\/stable\/data.html","#","memory-pinning",".","Example",":",":","dataloader","=","...","device","=","torch.device","(","``","cuda","''",")","num_prefetch_batches","=","2","data_prefetcher","=","CudaDataPrefetcher","(","dataloader",",","device",",","num_prefetch_batches",")","for","batch","in","data_prefetcher",":","#","batch","is","already","on","device","#","operate","on","batch"]
code: def __init__(
      self,
      data_iterable: Iterable[Batch],
      device: torch.device,
      num_prefetch_batches: int = 1,
  ) -> None:
      if device.type != "cuda":
          raise ValueError(
              "`CudaDataPrefetcher` expects a CUDA device, but got "
              f"device type {device.type}."
          )
      if num_prefetch_batches < 1:
          raise ValueError(
              "`num_prefetch_batches` must be greater than 0. Got "
              f"{num_prefetch_batches}."
          )
      self.data_iterable = data_iterable
      self.device = device
      self.num_prefetch_batches = num_prefetch_batches
      self._reset()
  
file_path: tnt/torchtnt/utils/data/data_prefetcher.py
imports: from typing import Iterable, Iterator, List, TypeVar
  import torch
  from torchtnt.utils.device import copy_data_to_device
label_desc: Use image node_id 1 to create a new CudaDataPrefetcher object from inherited base classes: Iterator with example: obj = CudaDataPrefetcher(data_iterable, device, num_prefetch_batches)