title: pytorch - use device inside 'with statement'
body: <p>Is there a way of running <code>pytorch</code> inside the context of a specific (GPU) device (without having to specify the device for each new tensor, such as the <code>.to</code> option)?</p>
  
  <p>Something like an equivalent of the <code>tensorflow</code> <code>with tf.device('/device:GPU:0'):</code>..</p>
  
  <p>It seems that the default device is the cpu (unless I'm doing it wrong):</p>
  
  <pre><code>with torch.cuda.device('0'):
     a = torch.zeros(1)
     print(a.device)
  
  &gt;&gt;&gt; cpu
  </code></pre>