Xuanfang1121 / relation-extract-tplinker-ch

17 stars 2 forks source link

跑测试集predict.py,无法在GPU上跑,大佬能否解答一下 #7

Open 258508 opened 9 months ago

258508 commented 9 months ago

Traceback (most recent call last): File "predict.py", line 91, in tplinker_predict(eval_config, test_data_path, model_state_path) File "predict.py", line 81, in tplinker_predict result = predict(data, data_maker, max_seq_len, batch_size, device, rel_extractor, True, File "/root/tplinker-ch/utils/util.py", line 236, in predict batch_tail_rel_shaking_outputs = rel_extractor(batch_input_ids, File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, kwargs) File "/root/tplinker-ch/models/tplinker.py", line 378, in forward context_outputs = self.encoder(input_ids, attention_mask, token_type_ids) File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, *kwargs) File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/transformers/models/bert/modeling_bert.py", line 964, in forward embedding_output = self.embeddings( File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(input, kwargs) File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/transformers/models/bert/modeling_bert.py", line 201, in forward inputs_embeds = self.word_embeddings(input_ids) File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl return forward_call(*input, **kwargs) File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/modules/sparse.py", line 158, in forward return F.embedding( File "/root/miniconda3/envs/pfn/lib/python3.8/site-packages/torch/nn/functional.py", line 2043, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking arugment for argument index in method wrapper_index_select) (pfn) root@autodl-container-f8

Mirage7320 commented 4 months ago

要检查一下是不是有数据没有统一 .to(device),这里的device如果用GPU是CUDA0