繁体   English   中英

Pytorch - 在 GPU 上训练时,在设备 1 上的副本 1 中捕获 StopIteration 错误

[英]Pytorch - Caught StopIteration in replica 1 on device 1 error while Training on GPU

我正在尝试在 git 链接中使用的 train2012 数据上训练 BertPunc model: https://github.com/nkrnrnk/ 在服务器上运行时,启用了 4 个 GPU,以下是我得到的错误:

StopIteration: Caught StopIteration in replica 1 on device 1.
Original Traceback (most recent call last):
  File "/home/stenoaimladmin/.local/lib/python3.8/site-packages/torch/nn/parallel/parallel_apply.py", line 61, in _worker
    output = module(*input, **kwargs)
  File "/home/stenoaimladmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/stenoaimladmin/notebooks/model_BertPunc.py", line 16, in forward
    x = self.bert(x)
  File "/home/stenoaimladmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/stenoaimladmin/anaconda3/lib/python3.8/site-packages/pytorch_pretrained_bert/modeling.py", line 861, in forward
    sequence_output, _ = self.bert(input_ids, token_type_ids, attention_mask,
  File "/home/stenoaimladmin/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/stenoaimladmin/anaconda3/lib/python3.8/site-packages/pytorch_pretrained_bert/modeling.py", line 727, in forward
    extended_attention_mask = extended_attention_mask.to(dtype=next(self.parameters()).dtype) # fp16 compatibility
StopIteration

从链接: https://github.com/huggingface/transformers/issues/8145 ,当数据在多个 GPU 之间来回移动时,这似乎发生了。

根据 git 链接: https://github.com/interpretml/interpret-text/issues/117 ,我们需要将 Z95B88F180E9EB5678E0F9EB88F180E9EB5678E0F9EB2CBE.73 版本从当前使用的版本降级为 14AC2CBE.73I 版本。 对我来说,降级版本不是一个选项,因为我有其他使用 Torch 1.7 版本的脚本。 我应该怎么做才能克服这个错误?

由于行太多,我无法将整个代码放在这里,但这是给我错误的代码段:

bert_punc, optimizer, best_val_loss = train(bert_punc, optimizer, criterion, epochs_top, 
        data_loader_train, data_loader_valid, save_path, punctuation_enc, iterations_top, best_val_loss=1e9)

这是我的 DataParallel 代码:

   bert_punc = nn.DataParallel(BertPunc(segment_size, output_size, dropout)).cuda()

我尝试更改 Dataparallel 线以将训练转移到仅 1 个 GPU,共 4 个。 但这给了我一个空间问题,因此不得不将代码恢复为默认值。

这是我正在使用的所有脚本的链接: https://github.com/nkrnrnk/BertPunc请指教。

改变

extended_attention_mask = extended_attention_mask.to(dtype=next(self.parameters()).dtype) # fp16 compatibility

extended_attention_mask = extended_attention_mask.to(dtype=torch.float32) # fp16 compatibility

有关更多详细信息,请参阅https://github.com/vid-koci/bert-commonsense/issues/6

我第二次小欧王回答。

只需在我的环境中添加需要更新的文件的路径,以获得更好的清晰度

“/data/home/cohnstav/anaconda3/envs/BestEnv/lib/python3.8/site-packages/pytorch_pretrained_bert/modeling.py”

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM