gpt4 book ai didi

pytorch - RuntimeError : ‘lengths’ argument should be a 1D CPU int64 tensor, 但得到 1D cuda:0 长张量

转载 作者:行者123 更新时间:2023-12-05 02:35:53 32 4
gpt4 key购买 nike

我正在尝试在纸空间上使用 pytorch 和 torchtext 进行文本分类。

我明白了

RuntimeError: ‘lengths’ argument should be a 1D CPU int64 tensor, but got 1D cuda:0 Long tensor

我的PyTorch版本是1.10.1+cu102

最佳答案

我昨天刚遇到这个问题,在我的例子中,rnn pad 序列希望长度在 cpu 上,所以只需将长度放在函数调用中的 CPU 中,如下所示:

packed_sequences = nn.utils.rnn.pack_padded_sequence(padded_tensor, valid_frames.to('cpu'), batch_first=True, enforce_sorted=True) 

这可能不是您正在使用的确切函数,但我认为它将适用于大多数 rnn utils 函数。

关于pytorch - RuntimeError : ‘lengths’ argument should be a 1D CPU int64 tensor, 但得到 1D cuda:0 长张量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70428140/

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