在使用新版本pytorch 执行老版本代码时,或使用 torchkeras 时,有事会出现如下错误:
AttributeError: module 'torch.nn' has no attribute 'MultiheadAttention'
解决方案:
这是由于版本不匹配导致的,一个快速的解决方法是安装另一个包:
pip install torch_multi_head_attentionfrom torch_multi_head_attention import MultiHeadAttention- 使用
MultiHeadAttention代替torch.nn.MultiheadAttention
3448

被折叠的 条评论
为什么被折叠?



