最重要的两张图:
Figure1:
下载地址
模型名称 | 完整版 | LoRA版 | GGUF版 |
---|---|---|---|
Llama-3-Chinese-8B-Instruct-v3 (指令模型) | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | N/A | [🤗Hugging Face] [🤖ModelScope] |
Llama-3-Chinese-8B-Instruct-v2 (指令模型) | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] |
Llama-3-Chinese-8B-Instruct (指令模型) | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] |
Llama-3-Chinese-8B (基座模型) | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] [🟣wisemodel] | [🤗Hugging Face] [🤖ModelScope] |
模型类型说明:
- 完整模型:可直接用于训练和推理,无需其他合并步骤
- LoRA模型:需要与基模型合并并才能转为完整版模型,合并方法:💻 模型合并步骤
- v1基模型:原版Meta-Llama-3-8B
- v2基模型:原版Meta-Llama-3-8B-Instruct
- GGUF模型:llama.cpp推出的量化格式,适配ollama等常见推理工具,推荐只需要做推理部署的用户下载;模型名后缀为
-im
表示使用了importance matrix进行量化,通常具有更低的PPL,建议使用(用法与常规版相同)
Figure2:
推理与部署
本项目中的相关模型主要支持以下量化、推理和部署方式,具体内容请参考对应教程。
工具 | 特点 | CPU | GPU | 量化 | GUI | API | vLLM | 教程 |
---|---|---|---|---|---|---|---|---|
llama.cpp | 丰富的GGUF量化选项和高效本地推理 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | [link] |
🤗transformers | 原生transformers推理接口 | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | [link] |
仿OpenAI API调用 | 仿OpenAI API接口的服务器Demo | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | [link] |
text-generation-webui | 前端Web UI界面的部署方式 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | [link] |
LM Studio | 多平台聊天软件(带界面) | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | [link] |
Ollama | 本地运行大模型推理 | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | [link] |
我使用的是 text-generation-webui 进行推理,
Step 1: 安装text-generation-webui
text-generation-webui目前支持Windows/Linux/macOS/WSL系统。
1、下载并解压:https://github.com/oobabooga/text-generation-webui/archive/refs/heads/main.zip
2、根据不同操作系统,执行start_*.sh脚本
3、根据提示选择GPU
What is your GPU?
A) NVIDIA
B) AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)
C) Apple M Series
D) Intel Arc (IPEX)
N) None (I want to run models in CPU mode)
安装过程较长,请耐心等待。更详细的教程请参考:webui installation
Step 2: 准备模型权重
text-generation-webui目前支持Hugging Face、GGUF等格式的模型。
Hugging Face兼容格式
将完整版Llama-3-Chinese-8B-Instruct放到text-generation-webui的models文件夹下,目录文件如下所示:
text-generation-webui
└── models
└── llama-3-chinese-8b-instruct
├── config.json
├── generation_config.json
├── model-00001-of-00004.safetensors
├── model-00002-of-00004.safetensors
├── model-00003-of-00004.safetensors
├── model-00004-of-00004.safetensors
├── model.safetensors.index.json
├── special_tokens_map.json
├── tokenizer_config.json
└── tokenizer.json
GGUF格式
如果是GGUF格式,可作为一个单独文件直接放到对应目录中。相应权重可从完整模型下载 GGUF下载,然后重命名,文件目录如下:
text-generation-webui
└── models
└── llama-3-chinese-8b-instruct-q4_k.gguf
Step 3: 加载模型和配置
安装完毕之后,再次运行start_*.sh,浏览器中访问日志显示的地址,即可进入网页界面。
15:59:59-435616 INFO Starting Text generation web UI
Running on local URL: http://127.0.0.1:7860
如图所示:
点开链接进入到网页text-generation-webui,后台cmd同时也在运行:
网页Model选项中的模型都在models文件夹下可以找到:
选择一个模型,点击Load:
选择instruct以后,就可以对话了:
通过实验,可以发现,我们使用cpu推理 可以使用 text-generation-webui 加载不同类型的模型,,比如 hugging face中的 safetensors 类型 或者 量化后的 .gguf类型。
我们加载这个14.9G的 safetensors 模型:
创建一个 new chat, 同时选择 instruct 选项:
你会发现问它一个问题,它蹦出来一个字母都需要一分钟:
我们看下任务管理器使用情况:
电脑非常卡,然后内存基本上吃光了,
等了两分钟,就出现一个hello!,左下角出现闪烁圆点,表示模型正在推理中,
又过了三分钟,
所以这也证明了,为什么我们需要 量化后的 .gguf 模型,
llama3 github网页里面的 llama.cpp给出来了量化的方式,llamacpp_zh · ymcui/Chinese-LLaMA-Alpaca-3 Wiki · GitHub
按照这个操作就可以了,我们可以试试 这个safetensors 量化后的 .gguf模型,
几秒出来了一大堆,这就是量化的魔力。