RuntimeError:addmm():参数'mat1'(位置1)必须是Variable,而不是torch.FloatTensor

问题描述 投票:1回答:2

我正在从the documentation运行这个非常简单的PyTorch示例NN,没有任何改变。

我收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/opt/conda/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/conda/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward
    input = module(input)
  File "/opt/conda/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/module.py", line 357, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/conda/envs/fastai/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward
    return F.linear(input, self.weight, self.bias)
  File "/opt/conda/envs/fastai/lib/python3.6/site-packages/torch/nn/functional.py", line 835, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: addmm(): argument 'mat1' (position 1) must be Variable, not torch.FloatTensor

显然在矩阵乘法期间,存在一些数据类型错误。 为什么我试图乘法的矩阵需要变量呢?

我可以 x = Variable(torch.randn(N, D_in)) y = Variable(torch.randn(N, D_out)) 但得到 AttributeError: 'Variable' object has no attribute 'item' 所以没有帮助。

我正在运行PyTorch版本0.3.1.post2。

python variables pytorch tensor
2个回答
3
投票

我想我刚刚找到了自己问题的答案,所以如果有其他人遇到这个问题,我会留在这里:

**NOTE:** These examples have been update for PyTorch 0.4, which made several major changes to the core PyTorch API. Most notably, prior to 0.4 Tensors had to be wrapped in Variable objects to use autograd; this functionality has now been added directly to Tensors, and Variables are now deprecated.

所以这意味着我正在运行旧版PyTorch


3
投票

我有同样的问题,所以我只是添加更新命令,以防你不想搜索它们: 可选的:

conda list | grep pytorch 
conda upgrade conda 

以下更新没有更新任何内容,虽然它们应该并且我认为它是正确的更新方式(您可以先尝试)

conda update pytorch torchvision

帮助是明确指定版本:

conda install pytorch=0.4.0 -c pytorch
© www.soinside.com 2019 - 2024. All rights reserved.