Skip to content

text generation webui_zh

ymcui edited this page Apr 30, 2024 · 5 revisions

使用text-generation-webui进行推理

GGUF版仍然需要等待该软件对llama.cpp的最新改动适配,否则会出现无限生成的问题

text-generation-webui是一种基于Gradio的用于运行大模型的Web UI,支持Hugging Face,GGUF(llama.cpp)等常见格式。

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 FaceGGUF等格式的模型。

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

界面如下所示:

image

接下来要进行一些配置:

1)选择model选项卡,在下拉列表里选择llama-3-chinese-8b-instruct,再点击load按钮,即可加载模型。

2)选择parameters选项卡,再选择instruction tempalte选项卡,指令模板形如:

{% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>

'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = '<|begin_of_text|>' + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>

' }}

Step 4:开始聊天

回到chat选项卡,右侧的Mode选择Instruct,即可开始与模型对话。

更详细的用法请自行探索网页界面,或参考官方手册。如果遇到安装或者运行问题还请到原repo下搜索解决方案或提问。

Clone this wiki locally