HuggingFace下载模型网络连接失败问题解决方法

最近有很多的小伙伴们在现在大模型文件或者大模型单个文件时总是出现网络问题,此问题也耽误小编很久,找到了各种的方法,终于搞明白了如何快速去解决HuggingFace源的问题。

Huggingface镜像:

  1. 方法一:使用huggingface 官方提供的 huggingface-cli 命令行工具。

    (1) 安装依赖
    pip install -U huggingface_hub
    (2) 基本命令示例:
    export HF_ENDPOINT=https://hf-mirror.com
    huggingface-cli download --resume-download --local-dir-use-symlinks False bigscience/bloom-560m --local-dir bloom-560m
    (3) 下载需要登录的模型(Gated Model)
    请添加--token hf_***参数,其中hf_***是 access token,请在huggingface官网这里获取。示例:
    huggingface-cli download --token hf_*** --resume-download --local-dir-use-symlinks False meta-llama/Llama-2-7b-hf --local-dir Llama-2-7b-hf
  2. 方法二:使用url直接下载时,将 huggingface.co 直接替换为本站域名hf-mirror.com。使用浏览器或者 wget -c、curl -L、aria2c 等命令行方式即可。
    下载需登录的模型需命令行添加 --header hf_*** 参数,token 获取具体参见上文。
  3. 方法三:(非侵入式,能解决大部分情况)huggingface 提供的包会获取系统变量,所以可以使用通过设置变量来解决。
    HF_ENDPOINT=https://hf-mirror.com python your_script.py

 

下面是一个简单的例子:

使用 Hugging Face 官方提供的 huggingface-cli 命令行工具。安装依赖:

pip install -U huggingface_hub

export HF_ENDPOINT=https://hf-mirror.com

然后新建 python 文件,填入以下代码,运行即可。

  • resume-download:断点续下
  • local-dir:本地存储路径。(linux 环境下需要填写绝对路径)
import os

# 下载模型
os.system('huggingface-cli download --resume-download internlm/internlm-chat-7b --local-dir your_path')

以下内容将展示使用 huggingface_hub 下载模型中的部分文件

import os 
from huggingface_hub import hf_hub_download  # Load model directly 

hf_hub_download(repo_id="internlm/internlm-7b", filename="config.json",local_dir= "文件的下载地址路径")

  • 16
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值