手动下载模型 #
打开模型的对应页面, 手动点击下载. 缺点: 只能一个一个下载
Git LFS 模型下载方案(优雅,但不够灵活) #
准备工作 #
Git LFS的方案相较于前面自行实现的方案要简洁的多得多. 我们需要在安装 git 的基础上,再安装 git lfs.
git lfs install
Ubuntu #
sudo apt-get install git-lfs
模型下载 #
点击主页下载 #
-
打开主页面
点击图中按钮
-
点击 Clone respository
-
根据图中前两条命令安装
git lfs install git clone https://huggingface.co/YeungNLP/firefly-llama2-13b-chat
Hugging Face Hub 模型下载方案(优雅,强烈推荐) #
准备工作 #
准备工作同样很简单, 我们只需要安装 huggingface_hub.
pip install huggingface_hub
如果想使用 TUI 管理 huggingface_hub 下载的模型:
pip install -U "huggingface_hub[cli]"
详细内容请查看 官方文档
Arch Linux #
在 Arch Linux 中可以安装 AUR 包: python-huggingface-hub 但是没有 CLI 特性, 无法使用 TUI 界面
模型下载 #
huggingface_hub 提供了很多种模型下载的方案, 详细的可以到 官方文档 进行查看
snapshot_download #
from huggingface_hub import snapshot_download
path = snapshot_download(repo_id="FlagAlpha/Llama2-Chinese-7b-Chat")
print(path)
忽略一些内容 #
在 snaphot_download 方法中, 提供了 allow_regex 和 ignore_regex 两个参数, 简单来说前者是对指定的匹配项进行下载, 后者是忽略指定的匹配项, 下载其余部分. 我们只需要使用其中一种就可以了.
snapshot_download(repo_id="bert-base-chinese", ignore_regex=["*.h5", "*.ot", "*.msgpack"])
使用代理 #
可以使用:
export http_proxy=http://127.0.0.1:20171
export https_proxy=http://127.0.01:20171
然后再执行 python 脚本下载.