Skip to content

Hugging Face模型下载

Hugging Face Hub是一个集中式Web服务平台,用于托管以下内容:

  • 基于 Git 的代码仓库,具有类似于 GitHub 的功能,包括项目的讨论(discussions)和拉取请求(pull requests)。
  • 模型(models),同样具有基于Git版本控制的;
  • 数据集(datasets),主要涵盖文本、图像和音频;
  • Web应用程序(“spaces”和“widgets”),用于机器学习应用的小规模演示。

用户可以从上面拉取可用的 LLM 模型文件。该教程将介绍如何从 Hugging Face 拉取模型文件,及如何加速拉取速度。

Git LFS 扩展安装

Git LFS 是 Git 用于管理大文件的命令行扩展,SonmiHPC 集群可用使用如下的命令安装该扩展:

shell
dnf install -y git git-lfs
dnf install -y git git-lfs

加速模型拉取

由于国内网络原因,直接从 Hugging Face 拉取大文件速度会很慢或者中间可能会中断,因此建议使用代理或者从镜像站进行拉取。下面将介绍如何使用 HF-Mirror 镜像站来加速模型文件拉取。

安装huggingface-cli工具

用户需要安装 python 及 pip,然后使用下面的命令安装 hugggingface-cli:

shell
pip install -U huggingface_hub
pip install -U huggingface_hub

如果安装速度过慢,可以使用清华 pypi 源来加速安装:

shell
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple -U huggingface_hub
pip install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple -U huggingface_hub

设置环境变量

root 用户可以设置全局环境变量:

shell
cat >> /etc/profile.d/hf-mirror.sh <<EOF
export HF_ENDPOINT=https://hf-mirror.com
EOF
source /etc/profile
cat >> /etc/profile.d/hf-mirror.sh <<EOF
export HF_ENDPOINT=https://hf-mirror.com
EOF
source /etc/profile

普通用户可以将环境变量写到个人环境变量下:

shell
cat >> ~/.bashrc <<EOF
export HF_ENDPOINT=https://hf-mirror.com
EOF
source ~/.bashrc
cat >> ~/.bashrc <<EOF
export HF_ENDPOINT=https://hf-mirror.com
EOF
source ~/.bashrc

下载模型

用户可用如下的命令下载模型文件到本地中:

shell
huggingface-cli download --resume-download <LLM_Model> --local-dir <Local_Dir>
huggingface-cli download --resume-download <LLM_Model> --local-dir <Local_Dir>

其中 LLM_Model 为模型的仓库名称,Local_Dir 为要保存到本地的路径。

示例

下面以下载 Qwen2.5-1.5B-Instruct-GGUF 仓库为例:

huggingface-cli download --resume-download Qwen/Qwen2.5-1.5B-Instruct-GGUF --local-dir /share/apps/models/Qwen2.5-1.5B-Instruct-GGUF
huggingface-cli download --resume-download Qwen/Qwen2.5-1.5B-Instruct-GGUF --local-dir /share/apps/models/Qwen2.5-1.5B-Instruct-GGUF

参考链接

  1. Hugging Face 官网
  2. Git LFS 官方仓库
  3. HF-Mirror 官网
  4. Qwen2.5-1.5B-Instruct-GGUF

本站内容未经授权禁止转载
联系邮箱: [email protected]