RuntimeError: _th_exp_out not supported on CUDAType for Long

问题与帮助

我在尝试微调一个用于问答的Transformer模型,并使用BCEWithLogitsLoss函数。然而,当我尝试计算损失时,遇到了以下错误:

RuntimeError: _th_exp_out not supported on CUDAType for Long

我输入的矩阵形状和数据类型分别为[16, 2]Long
但遗憾的是,我不知道如何解决这个问题。我尝试使用其他数据类型(int32, float32, double),但都没有效果。

以下是我的代码:

def loss_fn(self, preds, labels):    return torch.nn.BCEWithLogitsLoss()(preds, labels)def train_fn(self, dataloader, model, optimizer, device):    # 这里有一些其他代码    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)

回答:

在我这里,将pred和label都转换为float类型后,问题得到了解决。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注