下载 Hugging Face 中的模型文件

1. Hugging Face Hub

The Hugging Face Hub is a platform with over 350k models, 75k datasets, and 150k demo apps (Spaces), all open source and publicly available, in an online platform where people can easily collaborate and build ML together. The Hub works as a central place where anyone can explore, experiment, collaborate, and build technology with Machine Learning.

Downloading models

https://huggingface.co/docs/hub/models-downloading

2. ggerganov/whisper.cpp

https://huggingface.co/ggerganov/whisper.cpp/tree/main

在这里插入图片描述

在这里插入图片描述

3. 点击图标下载文件

在这里插入图片描述

4. Clone this model repository

在这里插入图片描述

在这里插入图片描述

# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install

git clone https://huggingface.co/ggerganov/whisper.cpp

# If you want to clone without large files - just their pointers
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/ggerganov/whisper.cpp
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$ git lfs install
Error: Failed to call git rev-parse --git-dir: exit status 128
Git LFS initialized.
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$ git lfs install --skip-repo
Git LFS initialized.
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$ GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/ggerganov/whisper.cpp
Cloning into 'whisper.cpp'...
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (39/39), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 56 (delta 6), reused 0 (delta 0), pack-reused 17 (from 1)
Unpacking objects: 100% (56/56), 11.31 KiB | 964.00 KiB/s, done.
(base) yongqiang@yongqiang:~/whisper_work/whisper_cpp_models$

5. Using the Hugging Face Client Library

You can use the huggingface_hub library to create, delete, update and retrieve information from repos. You can also download files from repos or integrate them into your library! For example, you can quickly load a Scikit-learn model with a few lines.

from huggingface_hub import hf_hub_download
import joblib

REPO_ID = "YOUR_REPO_ID"
FILENAME = "sklearn_model.joblib"

model = joblib.load(
    hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
)

6. Using Git

Since all models on the Model Hub are Git repositories, you can clone the models locally by running:

git lfs install
git clone git@hf.co:<MODEL ID> # example: git clone git@hf.co:bigscience/bloom

在这里插入图片描述

git lfs install
git clone https://huggingface.co/ggerganov/whisper.cpp

If you have write-access to the particular model repo, you’ll also have the ability to commit and push revisions to the model.

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] Downloading models, https://huggingface.co/docs/hub/models-downloading
[3] Git Large File Storage (LFS) 的安装与使用, https://yongqiang.blog.csdn.net/article/details/139218502
[4] 配置 HTTP 代理 (HTTP proxy), https://yongqiang.blog.csdn.net/article/details/139378962

### 如何从Hugging Face下载模型文件 #### 使用官方客户端库自动下载 为了简化流程并确保兼容性,推荐使用Hugging Face提供的Python库`transformers`来获取预训练模型及其配套资源。安装此库之后,在脚本里指定所需模型名称即可实现自动化加载过程[^2]。 ```python from transformers import AutoModelForSequenceClassification, AutoTokenizer model_name = "bert-base-uncased" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) ``` 这段代码不仅能够处理模型本身的下载工作,还会同步拉取必要的分词工具及相关配置文档,比如`config.json`, `vocab.txt`以及可能存在的额外组件如`special_tokens_map.json`等[^4]。 #### 手动下载方法 对于那些希望完全掌控下载细节或是遇到网络问题的情况,则可以选择手动方式: 访问[Hugging Face模型页面](https://huggingface.co/models),定位至目标模型条目下(例如`bert-uncased`),点击进入详情页后可以看到一系列可供单独选取的文件链接。用户可以根据实际需求挑选特定版本或组成部分进行保存,并按照指示将其放置于本地缓存目录内(通常是`~/.cache/huggingface/transformers`)[^1]。 如果是在Linux环境下遭遇下载障碍,可以通过设定环境变量指向备用镜像站点的方法绕过原生源站限制。执行如下指令可更改默认请求地址为国内加速节点,从而提高成功率和速度[^5]: ```bash export HF_ENDPOINT="https://hf-mirror.com" echo $HF_ENDPOINT # 验证设置是否成功应用 ``` 需要注意的是上述变更仅限于当前shell session期间有效;若要持久化修改则需进一步编辑`.bashrc`或其他初始化脚本文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Yongqiang Cheng

梦想不是浮躁,而是沉淀和积累。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值