【问题标题】:RuntimeError: _th_exp_out not supported on CUDAType for LongRuntimeError: CUDAType 不支持 _th_exp_out 长
【发布时间】:2020-07-09 22:17:34
【问题描述】:

问题和帮助

我正在尝试微调变压器模型以进行问答,并且正在使用 BCEWithLogitsLoss 函数。 但是,当我尝试计算损失时,我得到了这个错误:

RuntimeError: CUDAType 不支持 _th_exp_out for Long

我正在输入形状和 dtype 为 [16, 2]Long 的矩阵
可悲的是,我不知道如何解决这个问题。我尝试使用另一种 dtype(int32、float32、double),但不起作用。

代码如下:

def loss_fn(self, preds, labels):
    return torch.nn.BCEWithLogitsLoss()(preds, labels)

def train_fn(self, dataloader, model, optimizer, device):
    # Some other stuff here
    pred = model(
            token_ids = token_ids,
            attention_mask = attention_mask,
            token_type_ids = token_type_ids)
    start_scores = torch.argmax(pred[0], dim=1)
    end_scores = torch.argmax(pred[1], dim=1)
        
    pred = torch.tensor(list(zip(start_scores, end_scores)))
    pred = pred.to(device, dtype=torch.long)

    batch_loss = self.loss_fn(pred, label)

【问题讨论】:

    标签: python machine-learning pytorch


    【解决方案1】:

    在我的情况下,将 pred 和 label 都传递为 float 有效。

    【讨论】:

      猜你喜欢
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 2018-12-13
      • 2019-04-18
      • 1970-01-01
      • 2021-05-03
      • 2014-06-07
      • 2023-01-04
      相关资源
      最近更新 更多