gpt4 book ai didi

pytorch - 运行时错误: "exp" not implemented for 'torch.LongTensor'

转载 作者:行者123 更新时间:2023-12-02 11:45:26 33 4
gpt4 key购买 nike

我正在关注本教程:http://nlp.seas.harvard.edu/2018/04/03/attention.html实现“Attention Is All You Need”论文中的 Transformer 模型。

但是我收到以下错误:运行时错误:“exp”未针对“torch.LongTensor”实现

这是 PositionalEnconding 类中导致错误的行:

div_term = torch.exp(torch.arange(0, d_model, 2) * -(math.log(10000.0) / d_model))

在这里构建时:

pe = PositionalEncoding(20, 0)

有什么想法吗?我已经尝试将其转换为 Tensor Float 类型,但这没有奏效。

我什至下载了整个笔记本及其随附文件,并且该错误似乎在原始教程中仍然存在。

有什么想法可能导致此错误吗?

谢谢!

最佳答案

我也碰巧遵循了这个教程。

对我来说,我刚刚得到了 torch.arange 来生成浮点类型张量

来自

position = torch.arange(0, max_len).unsqueeze(1)
div_term = torch.exp(torch.arange(0, d_model, 2) * -(math.log(10000.0) / d_model))

position = torch.arange(0., max_len).unsqueeze(1)
div_term = torch.exp(torch.arange(0., d_model, 2) * -(math.log(10000.0) / d_model))

只是一个简单的修复。但现在它对我有用。 torch expsin 之前可能支持 LongTensor,但现在不再支持(不太确定)。

关于pytorch - 运行时错误: "exp" not implemented for 'torch.LongTensor' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52922445/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com