项目场景:

使用huggingface镜像下载模型

问题描述

embedding_model = SentenceTransformer(‘paraphrase-multilingual-MiniLM-L12-v2’)

注意

1:这个是在当前powershell会话中临时设置环境变量,所以如果关闭powershell而后重新打开,则需要重新运行该命令设置环境变量
2:如果下载失败,可以重复执行上面的命令,来继续下载

解决方案:

如果实在没有梯子,也可以使用huggingface镜像,参考如下文章

国内快速下载huggingface(镜像)上的模型和数据 - 知乎

下面是官方教程

HF-Mirror - Huggingface 镜像站

具体而言:

打开Anaconda powershell prompt

激活环境

conda activate test

安装依赖
pip install -U huggingface_hub

设置环境变量,即使用huggingface镜像站
Linux平台,在命令行执行

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

Windows Powershell,在命令行执行,注意这里必须使用powershell

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

下载模型
huggingface-cli download --resume-download 模型名

huggingface-cli download --resume-download sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2

模型名需要去huggingface镜像站进行查询,以获取精确的模型名称

hf-mirror

运行模型

以我下载的sentence-transformers/all-MiniLM-L6-v2模型为例子:
模型会下载到当前虚拟环境(clw_py3.10.6)的.cache中:在这里插入图片描述
复制该目录到代码中再运行模型即可:
在这里插入图片描述

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐