浏览器下载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}")
相关推荐
花酒锄作田16 小时前
Pydantic校验配置文件
python
hboot16 小时前
AI工程师第四课 - 深度学习入门
pytorch·python·神经网络
ZhengEnCi1 天前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
ZhengEnCi1 天前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽1 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
用户8358086187911 天前
基于 Self-RAG 与列表级重排序的进阶 RAG 系统设计与实现
python
Warson_L2 天前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅2 天前
海天线算法的前世今生
python·计算机视觉
韩师傅2 天前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L2 天前
LangGraph的MessageState and HumanMessage
python