You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dsProject/dsRag/Test/T14_DownloadHuggingFace.py

28 lines
780 B

"""
pip install huggingface_hub
pip install pysocks
pip install hf_xet
开VPN后,使用Python下载模型
"""
import os
from transformers import AutoModel, AutoTokenizer
# 设置环境变量
os.environ['HTTP_PROXY'] = 'socks5://127.0.0.1:1080'
os.environ['HTTPS_PROXY'] = 'socks5://127.0.0.1:1080'
# 配置代理
proxies = {
'http': 'socks5://127.0.0.1:1080',
'https': 'socks5://127.0.0.1:1080'
}
# 加载模型
model_id = "google-bert/bert-base-uncased"
model = AutoModel.from_pretrained(model_id, proxies=proxies)
tokenizer = AutoTokenizer.from_pretrained(model_id, proxies=proxies)
# 保存模型到本地
model.save_pretrained("d:/Model/google-bert/bert-base-uncased")
tokenizer.save_pretrained("d:/Model/google-bert/bert-base-uncased")