使用pytorch变量的目标是什么?

Bob*_*Bob 3 python pytorch

我有这个代码:

from torch.autograd import Variable
d_real_data = Variable(d_sampler(d_input_size))
Run Code Online (Sandbox Code Playgroud)

Variable(d_sampler(d_input_size))但我想知道和之间有什么区别d_sampler(d_input_size)

我认为这是两个张量,但值不同。所以我想知道这个函数 Variable 的目标是什么?

Nop*_*eos 7

Variable()是一种将 autograd 与张量结合使用的方法。该功能现已弃用,不应再使用。requires_grad如果该标志设置为 true,则张量现在可以与 autograd 配合使用。来自 官方文档

变量 API 已被弃用:使用带有张量的 autograd 不再需要变量。Autograd 自动支持requires_grad设置为 的张量True