title: Automatically set cuda variables in pytorch
body: <p>I'm trying to automatically set Variables to use cuda if a flag <code>use_gpu</code> is activated. </p>
  
  <p>Usually I would do:</p>
  
  <pre><code>import torch
  from torch import autograd
  use_gpu = torch.cuda.is_available()
  
  foo = torch.randn(5)
  
  if use_gpu:
      fooV = autograd.Variable(foo.cuda())
  else:
      fooV = autograd.Variable(foo)
  </code></pre>
  
  <p>However, to do things faster when I have to initialise variables in different parts of the code I wanted to do something like this:</p>
  
  <pre><code>import torch
  from torch import autograd
  use_gpu = torch.cuda.is_available()
  
  class Variable(autograd.Variable):
      def __init__(self, data, *args, **kwargs):
          if use_gpu:
              data = data.cuda()
          super(Variable, self).__init__(data, *args, **kwargs)
  
  foo = torch.randn(5)
  fooV = Variable(foo)
  </code></pre>
  
  <p>Unfortunately, this doesn't seem to be working and <code>fooV</code> doesn't contain a cuda Tensor when the <code>use_gpu</code> is <code>True</code>.</p>