小编Sep*_*ius的帖子

Pytorch 运行时错误:设备类型为 cuda 的预期对象,但在调用 _th_index_select 时获得了参数 #1 'self' 的设备类型 cpu

我正在训练一个模型,该模型采用标记化的字符串,然后通过嵌入层和 LSTM。但是,输入中似乎存在错误,因为它没有通过嵌入层。

class DrugModel(nn.Module):
    def __init__(self, input_dim, output_dim, hidden_dim, drug_embed_dim,
            lstm_layer, lstm_dropout, bi_lstm, linear_dropout, char_vocab_size,
            char_embed_dim, char_dropout, dist_fn, learning_rate,
            binary, is_mlp, weight_decay, is_graph, g_layer,
            g_hidden_dim, g_out_dim, g_dropout):

        super(DrugModel, self).__init__()

        # Save model configs
        self.drug_embed_dim = drug_embed_dim
        self.lstm_layer = lstm_layer
        self.char_dropout = char_dropout
        self.dist_fn = dist_fn
        self.binary = binary
        self.is_mlp = is_mlp
        self.is_graph = is_graph
        self.g_layer = g_layer
        self.g_dropout = g_dropout
        self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

        # For one-hot encoded SMILES
        if not is_mlp:
            self.char_embed = nn.Embedding(char_vocab_size, char_embed_dim,
                                           padding_idx=0) …
Run Code Online (Sandbox Code Playgroud)

gpu runtime-error embedding pytorch

0
推荐指数
1
解决办法
9732
查看次数

标签 统计

embedding ×1

gpu ×1

pytorch ×1

runtime-error ×1