淘先锋技术网

首页 1 2 3 4 5 6 7

背景

从 huggingface 下载的模型大多是 tensorflow 版本的,错误的使用会报错:Error no file named pytorch_model.bin, tf_model.h5, model.ckpt.index or flax_model.msgpack found in directory /home/nuo/pretrained_models/chinese_bert_wwm_L-12_H-768_A-12.

安装 pytorch-transformers

pip install pytorch-transformers

生成 pytorch.bin

cd ~/Softwares/anaconda3/envs/pytorchenv/lib/python3.8/site-packages/pytorch_transformers

export b=/home/pretrained_models/chinese_bert_wwm_L-12_H-768_A-12

python convert_tf_checkpoint_to_pytorch.py --tf_checkpoint_path="$b/bert_model.ckpt" --bert_config_file="$b/bert_config.json" --pytorch_dump_path="$b/pytorch_model.bin"

期间可能报错没有tensorflow包之类的。就缺啥安啥。

效果

Save PyTorch model to /home/nuo/pretrained_models/chinese_bert_wwm_L-12_H-768_A-12/pytorch_model.bin

does not appear to have a file named config.json.

原始下载的文件里,json 文件名叫做 bert_config.json!不可以,要改成 config.json!