本地/笔记本/纯 cpu 部署、使用类 gpt 大模型

使用 web UI + 大模型文件,即可在笔记本上部署、使用类 gpt 大模型。

1. 安装 web UI

1.1. 下载代码库

https://github.com/oobabooga/text-generation-webui

1.2. 创建 conda 环境

conda create -n textgen python=3.11
conda activate textgen

1.3. 安装 pytorch

文档:https://github.com/oobabooga/text-generation-webui#2-install-pytorch

SystemGPUCommand
Linux/WSLNVIDIApip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
Linux/WSLCPU onlypip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
LinuxAMDpip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm5.6
MacOS + MPSAnypip3 install torch torchvision torchaudio
WindowsNVIDIApip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
WindowsCPU onlypip3 install torch torchvision torchaudio

如果是 nvidia 显卡,需执行以下命令:

conda install -y -c "nvidia/label/cuda-12.1.0" cuda-runtime

1.4. 安装 pip 库

文档:https://github.com/oobabooga/text-generation-webui#3-install-the-web-ui

pip install -r <requirements file according to table below>
GPUCPUrequirements file to use
NVIDIAhas AVX2requirements.txt
NVIDIAno AVX2requirements_noavx2.txt
AMDhas AVX2requirements_amd.txt
AMDno AVX2requirements_amd_noavx2.txt
CPU onlyhas AVX2requirements_cpu_only.txt
CPU onlyno AVX2requirements_cpu_only_noavx2.txt
AppleIntelrequirements_apple_intel.txt
AppleApple Siliconrequirements_apple_silicon.txt

如果是 linux ,需按照以下步骤才可以使用 cuda 加速的 llama 后端:

# 注释 requirements.txt 中安装 llama_cpp_python_cuda 的行
pip install -r requirements.txt
export LLAMA_CUBLAS=1
CMAKE_ARGS="-DLLAMA_CUBLAS=on" pip install llama-cpp-python

2. 下载大模型

2.1. 搜索大模型

Models - Hugging Face:https://huggingface.co/models

在这里插入图片描述

Hugging Face 是深度学习里最活跃的开源社区之一,提供了许多开源模型量化版本的下载。

  • 量化:将模型权重中的 float 替换为 int 等数据类型,损失一小部分精度,但大量减少模型文件大小、内存占用、计算开销。

在页面搜索需要的模型,建议勾选 Libraries 选项中的 transformersGGUF 后搜索,例如搜索模型名 Llama-2-7B-GGUF

  • 其中 7B 代表模型的参数量 7 billion(常见参数量有 7b , 13b , 70b),参数量越大,模型精度越高,即对话质量越高。
  • transformers 是一种大模型的格式,勾选后也会包含 GPTQ 量化格式的模型。
  • GPTQ 是一种量化大模型的格式,示例模型名为 Llama-2-7B-GPTQ
  • GGUF 是另一种量化大模型的格式,示例模型名为 Llama-2-7B-GGUF
  • GPTQGGUF 是最常用、好用的量化模型格式

2.2. 下载模型文件

2.2.1. 下载 GGUF 模型文件

在具体模型页面的 Provided files 部分(以 https://huggingface.co/TheBloke/Llama-2-7B-GGUF#provided-files 为例)可以看到该模型的不同量化版本、文件大小、预计内存占用、推荐与否。点击具体量化版本的模型即可下载。

在这里插入图片描述

最后将下载的模型文件保存在本地 text-generation-webuimodels 文件夹里即可。

2.2.2. 下载 GPTQ 模型文件

在具体模型页面的 Files and versions 页面(以 https://huggingface.co/TheBloke/Llama-2-13B-GPTQ/tree/main 为例),点击 clone repository 即可看到下载命令如下:

# Make sure you have git-lfs installed (https://git-lfs.com)
git lfs install
git clone https://huggingface.co/TheBloke/Llama-2-13B-GPTQ

# if you want to clone without large files – just their pointers
# prepend your git clone with the following env var:
GIT_LFS_SKIP_SMUDGE=1

在这里插入图片描述

  • LFS :git clone 命令很可能无法成功下载模型库中的 LF(large file),可以在 clone 了其他文件后,单独下载标有 LFS 的文件。

最后同样将下载的模型库保存在本地 text-generation-webuimodels 文件夹里即可。

补充参考文章——git lfs使用(huggingface下载大模型文件):
https://blog.csdn.net/flyingluohaipeng/article/details/130788293

2.3 额外推荐

Hugging Face 用户 TheBloke: https://huggingface.co/TheBloke

TheBloke 是 hugging face 社区的一个用户, ta 提供了许多预量化大模型的下载。

在这里插入图片描述

3. 使用 web UI

3.1. 运行 UI 界面

打开 conda 命令行窗口,运行以下命令,并保持窗口开启:

conda activate textgen
cd text-generation-webui
python server.py --trust-remote-code --listen
  • --trust-remote-code :部分 GPTQ 模型的加载需要启用该选项
  • --listen:监听局域网访问,即使得其他设备可以通过 ip 访问网页 ui,未开启时只能本机通过 127.0.0.1:7860 访问

3.2. 加载 GPTQ 模型

![在这里插入图片描述](https://img-blog.csdnimg.cn/9f5d26fb0ef345228b4ff439a697bf9f.png

打开 127.0.0.1:7860 网页链接,model 页面,按上图进行模型加载即可(大概需要几十秒),随后即可进行对话。

GPTQ 模型加载具体文档:https://github.com/oobabooga/text-generation-webui/wiki/04-‐-Model-Tab#transformers

3.3. 加载 GGUF 模型

在这里插入图片描述

打开 127.0.0.1:7860 网页链接,model 页面,按上图进行模型加载即可(大概需要几十秒),随后即可进行对话。

GGUF 模型加载具体文档:https://github.com/oobabooga/text-generation-webui/wiki/04-‐-Model-Tab#llamacpp

3.3. 进行对话

在这里插入图片描述

打开 chat 页面,即可进行对话。

  • 在对话框左侧菜单中有 “开始新对话” 等操作
  • 需注意,大部分模型默认语言为英文,不支持中文对话(可在模型页面查看详情)
  • 需注意,本地模型无法像 chat-gpt 一样联网访问信息

4. 探索更多

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值