[英]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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.