浏览器下载huggingface网络连接超时,使用镜像源教程

镜像源网址:

https://hf-mirror.com/

可以:

1.安装依赖:

pip install -U huggingface_hub

2.设置环境变量

(linux)

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

(windows)

$env:HF_ENDPOINT = "https://hf-mirror.com"

3.下载模型指令(替换掉模型gpt和地址)

huggingface-cli download --resume-download gpt2 --local-dir gpt2

下载数据集指令

huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitext

详细操作见网址

下载模型到本地之后,可以通过代码使用本地模型:

复制代码
from transformers import AutoTokenizer, AutoModel

# 使用绝对路径或相对路径
local_model_path = "your_path"

# 或者如果代码文件在同一目录下,可以用相对路径
# local_model_path = "./roberta-base-finetuned-dianping-chinese"

# 加载模型和分词器
tokenizer = AutoTokenizer.from_pretrained(local_model_path)
model = AutoModel.from_pretrained(local_model_path)

print("✅ 模型加载成功!")
print(f"模型类型: {type(model)}")
print(f"分词器: {tokenizer}")

实操:

以下为jupyter nootbook三个cell

复制代码
# Cell 1: 设置镜像
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
print("镜像已设置为: https://hf-mirror.com")

# Cell 2: 下载模型(带进度显示)
!huggingface-cli download hfl/rbt3 --local-dir ./hfl_rbt3

# Cell 3: 验证下载完成
import glob
files = glob.glob("./hfl_rbt3/*")
print(f"下载了 {len(files)} 个文件:")
for f in files:
    print(f"  - {f}")
相关推荐
Java后端的Ai之路9 小时前
【Python 教程15】-Python和Web
python
冬奇Lab11 小时前
一天一个开源项目(第15篇):MapToPoster - 用代码将城市地图转换为精美的海报设计
python·开源
二十雨辰13 小时前
[python]-AI大模型
开发语言·人工智能·python
Yvonne爱编码13 小时前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
前端摸鱼匠14 小时前
YOLOv8 环境配置全攻略:Python、PyTorch 与 CUDA 的和谐共生
人工智能·pytorch·python·yolo·目标检测
WangYaolove131414 小时前
基于python的在线水果销售系统(源码+文档)
python·mysql·django·毕业设计·源码
AALoveTouch14 小时前
大麦网协议分析
javascript·python
ZH154558913114 小时前
Flutter for OpenHarmony Python学习助手实战:自动化脚本开发的实现
python·学习·flutter
xcLeigh15 小时前
Python入门:Python3 requests模块全面学习教程
开发语言·python·学习·模块·python3·requests
xcLeigh15 小时前
Python入门:Python3 statistics模块全面学习教程
开发语言·python·学习·模块·python3·statistics