title: Moving Dataloader data to GPU PyTorch
body: <p>I am just getting started with PyTorch...</p>
  
  <p>Currently I am following this method of getting training data to the GPU. Source: <a href="https://stanford.edu/~shervine/blog/pytorch-how-to-generate-data-parallel" rel="nofollow noreferrer">https://stanford.edu/~shervine/blog/pytorch-how-to-generate-data-parallel</a></p>
  
  <pre><code># Loop over epochs
  for epoch in range(max_epochs):
      # Training
      for local_batch, local_labels in training_generator:
          # Transfer to GPU
          local_batch, local_labels = local_batch.to(device), local_labels.to(device)
  
          # Model computations
          [...]
  </code></pre>
  
  <p><strong>Question</strong>: This seems less efficient than just loading the entire data set onto the GPU. Does loading data on each batch not cause latency? Am I missing something?</p>