问题描述:
执行
div_term = torch.exp(torch.arange(0, d_model, 2) *
-(math.log(10000.0) / d_model))
报错, RuntimeError: exp_vml_cpu not implemented for ‘Long’
原因: torch.exp()操作不支持Long类型的张量作为输入
解决方法: 将张量转为浮点型即可, 执行
div_term = torch.exp(torch.tensor(torch.arange(0, d_model, 2) *
-(math.log(10000.0) / d_model),dtype=torch.float))
总结: pytorch中的很多操作不支持Long类型的张量, 所以会出现这一类报错信息:RuntimeError: xxx_vml_cpu not implemented for ‘Long’, 只需要把输入的张量改成浮点类型即可。