huggingface报错记录

1.OSError: Unable to load weights from pytorch checkpoint file for '/mnt/workspace/wzf/transformer/model/vit-gpt2-image-captioning/pytorch_model.bin' at '/mnt/workspace/wzf/transformer/model/vit-gpt2-image-captioning/pytorch_model.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

解决办法:from_pretrained加载模型时设置set from_tf=True.

2.ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (/home/pai/lib/python3.9/site-packages/tensorflow/_api/v2/compat/v2/experimental/__init__.py)

解决办法:

使用pip show tensorflow 和pip show keras查看版本问题

Name: keras
Version: 2.15.0

Name: tensorflow
Version: 2.6.0

原因:keras版本太高

pip install keras==2.6

3.RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`

方法一(不行):

import os
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'

报错:

RuntimeError: CUDA error: device-side assert triggered

方法二:参考RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)`问题解决-CSDN博客 

from transformers import BertTokenizer, BertModel
 
tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
# 添加特殊词
tokenizer.add_special_tokens({'additional_special_tokens':[""]})
 
model = BertModel.from_pretrained("bert-base-cased")
# 在模型中更新词表的大小!
# 重要!
model.resize_token_embeddings(len(tokenizer))

你可能感兴趣的:(huggingface)