huggingface 下载模型方法的官方教程如下:

官方教程Download files from the Hub

如果可以访问官方教程,建议直接参考官方教程。本文是对官方教程和个人使用经历的片面总结

huggingface的使用环境为python

创建一个python文件(推荐)或者用python命令行:

from huggingface_hub import hf_hub_download

#下载模型和数据集,通过repo_id指定huggingface网站上的模型和数据集,repo_type指定下载的类别
#模型存放位置:'/home/.cache/huggingface/hub/models--your-model-name/snapshots/xxxxxxxxxxxx'
#下载模型
hf_hub_download(repo_id="lysandre/arxiv-nlp", filename="config.json")
#位置:'/home/.cache/huggingface/hub/models--lysandre--arxiv-nlp/snapshots/xxxxxxxx'

#下载数据集
hf_hub_download(repo_id="google/fleurs", filename="fleurs.py", repo_type="dataset")
#位置:'/home/.cache/huggingface/hub/datasets--google--fleurs/snapshots/xxxxxxxx'

#制定版本
# 指定tag:Download from the `v1.0` tag
hf_hub_download(repo_id="lysandre/arxiv-nlp", filename="config.json", revision="v1.0")

# 指定branch:Download from the `test-branch` branch
hf_hub_download(repo_id="lysandre/arxiv-nlp", filename="config.json", revision="test-branch")

# 不熟悉pr和commit的可以参考git教程,这里可以先略过
# 指定PR:Download from Pull Request #3
hf_hub_download(repo_id="lysandre/arxiv-nlp", filename="config.json", revision="refs/pr/3")

# 指定commit:Download from a specific commit hash
hf_hub_download(repo_id="lysandre/arxiv-nlp", filename="config.json", revision="877b84a8f93f2d619faa2a6e514a32beef88ab0a")

这里仅仅是把模型下载下来的过程,找到模型和数据集下载位置是为了便于使用本地模型的权重

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐