当我运行以下代码时,出现错误:

时间:2021-05-20 06:04:21

标签: python pytorch huggingface-transformers

代码:

model = BertWSD.from_pretrained(model_dir)
tokenizer = BertTokenizer.from_pretrained(model_dir)
# add new special token
if '[TGT]' not in tokenizer.additional_special_tokens:
    tokenizer.add_special_tokens({'additional_special_tokens': ['[TGT]']})
    assert '[TGT]' in tokenizer.additional_special_tokens
    model.resize_token_embeddings(len(tokenizer))
    
model.to(DEVICE)
model.eval()

出于某种原因,每当我运行代码时,我总是收到一个奇怪的错误:

RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    625             try:
--> 626                 state_dict = torch.load(resolved_archive_file, map_location="cpu")
    627             except Exception:

3 frames
RuntimeError: unexpected EOF, expected 5298350 more bytes. The file might be corrupted.

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    627             except Exception:
    628                 raise OSError(
--> 629                     "Unable to load weights from pytorch checkpoint file. "
    630                     "If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. "
    631                 )

OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. 

有人知道我为什么会收到这个错误吗?

0 个答案:

没有答案