下载huggingface模型到本地
用如下脚本可以下载HuggingFace上的各种模型, 网址 https://huggingface.co/models
#coding=gbk
import time
from huggingface_hub import snapshot_download
#huggingface上的模型名称
repo_id = "LinkSoul/Chinese-Llama-2-7b-4bit"
#本地存储地址
local_dir = "E:\\work\\AI\\GPT\\llama_model_7b_4bit"
cache_dir = local_dir + "\\cache"
while True:try:snapshot_download(cache_dir=cache_dir,local_dir=local_dir,repo_id=repo_id,local_dir_use_symlinks=False,resume_download=True,allow_patterns=["*.model", "*.json", "*.bin","*.py", "*.md", "*.txt"],ignore_patterns=["*.safetensors", "*.msgpack","*.h5", "*.ot",],)except Exception as e :print(e)# time.sleep(5)else:print('下载完成')break
参考从Hugging Face下载模型到本地并调用 - 午夜稻草人 - 博客园