huggingface 下载模型和数据集方法与位置(linux服务器)

本文介绍了如何使用HuggingFaceHub的`hf_hub_download`函数在Python环境中下载模型和数据集,通过指定repo_id、filename、repo_type、revision(如tag、branch、PR或commit)来获取特定版本的资源。下载的模型和数据集存储在用户的缓存目录中,便于后续使用本地权重。
摘要由CSDN通过智能技术生成

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")

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

  • 5
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值