对于Variable的态度,PyTorch官方明确说明:deprecated已经被废弃。下面是PyTorch官方说明:

The Variable API has been deprecated: Variables are no longer necessary to use autograd with tensors. Autograd automatically supports Tensors with requires_grad set to True. Below please find a quick guide on what has changed:

  • Variable(tensor) and Variable(tensor, requires_grad) still work as expected, but they return Tensors instead of Variables.
  • var.data is the same thing as tensor.data.
  • Methods such as var.backward(), var.detach(), var.register_hook() now work on tensors with the same method names.

从上述的说明我们可以获知:Variable已经完全被Tensor所取代,在早期版本的PyTorch中张量Tensor和变量Variable是两类不同的东西,如今被统一到一起了。