Tencent / NeuralNLP-NeuralClassifier

An Open-source Neural Hierarchical Multi-label Text Classification Toolkit
Other
1.83k stars 402 forks source link

设置“region_embedding” 运行报错“RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!” #123

Closed CrawlingForward closed 2 months ago

CrawlingForward commented 6 months ago

你好! 相关config如下: "task_info":{ "label_type": "multi_label", "hierarchical": false, "hierar_taxonomy": "data/rcv1.taxonomy", "hierar_penalty": 0.000001 }, "device": "cuda", "model_name": "TextCNN", "checkpoint_dir": "checkpoint_dir_spc", "model_dir": "trained_model_ipc",

"embedding": { "type": "region_embedding", "dimension": 300, "region_embedding_type": "context_word", "region_size": 5, "initializer": "uniform", "fan_mode": "FAN_IN", "uniform_bound": 0.25, "random_stddev": 0.01, "dropout": 0.0 }, 使用自建数据,选择textCNN模型,非层次多标签任务,其他参数未动,"type": "embedding", 可正常运行。

微信图片_20240321112832

问题出在哪,应该如何修改,谢谢?

liqunhit commented 3 months ago

在 model\embedding.py的201行之上,加上两行,试一试: mask = mask.to(context_embedding.device) neg_mask = neg_mask.to(context_embedding.device)