Open Gaoshuang77 opened 4 years ago
我尝试在报错这行“a = torch.bmm(e.transpose(1, 2), v)”之后加入“v = torch.tensor(v, dtype=torch.float32)”将v转换成float向量,但是遇到了另一个报错:
Traceback (most recent call last):
File "train.py", line 294, in
@songyouwei 目前还是没有解决,请问您知道如何修改吗?
可能和版本有关,有没有安装requirements.txt呢?
嗯嗯,安装了requirements.txt,除了用了较小的glove以外,别的地方没有改动。
v = torch.tensor(v, dtype=torch.float32).to(self.opt.device)
我再for循环的第一行添加了上面这行代码
@gpf951101 您加了这行是可以运行的吗?我刚刚去试了一下,但是报错“RuntimeError: Expected object of scalar type Double but got scalar type Float for argument #3 'mat1' in call to _thaddmm”
@Gaoshuang77 你是在cpu上跑的吧
@GeneZC 是的,在CPU上跑的。
@Gaoshuang77 那就检查一下你在哪里引入了double(float64)类型的变量,按理说这份代码都应该是float(float32)类型
请问您解决了您的问题吗,我也遇到了同样的问题
@dongyang12138 @Gaoshuang77 try removing line 27 in tfnet_lf.py: pos_inx = pos_inx.cpu().numpy()
Or downgrade Pytorch version <= 1.4.0
And the best solution may be change weight = torch.tensor(weight) to weight = torch.tensor(weight).float()
我在别的模型上也出现了Float和Double类型的问题,后来我去降级了pytorch,从1.5.1降到1.4就没问题了
您好,请问如何解决呢?谢谢。 epoch: 0 Traceback (most recent call last): File "train.py", line 294, in
main()
File "train.py", line 290, in main
ins.run()
File "train.py", line 170, in run
best_model_path = self._train(criterion, optimizer, train_data_loader, val_data_loader)
File "train.py", line 105, in _train
outputs = self.model(inputs)
File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "/content/gdrive/Shared drives/ABSA-PyTorch-master/models/tnet_lf.py", line 67, in forward
a = torch.bmm(e.transpose(1, 2), v)
RuntimeError: expected scalar type Float but found Double