> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/text-generation-webui.md).

# Text Generation WebUI

在 Clore.ai GPU 上运行 text-generation-webui 进行 LLM 推理

运行支持所有模型格式的最受欢迎的 LLM 界面。

{% hint style="success" %}
所有示例都可以在通过以下方式租用的 GPU 服务器上运行 [CLORE.AI 市场](https://clore.ai/marketplace).
{% endhint %}

## 在 CLORE.AI 上租用

1. 访问 [CLORE.AI 市场](https://clore.ai/marketplace)
2. 按 GPU 类型、VRAM 和价格筛选
3. 选择 **按需** （固定费率）或 **竞价** （出价）
4. 配置你的订单：
   * 选择 Docker 镜像
   * 设置端口（SSH 用 TCP，Web UI 用 HTTP）
   * 如有需要，添加环境变量
   * 输入启动命令
5. 选择支付方式： **CLORE**, **BTC**，或 **USDT/USDC**
6. 创建订单并等待部署

### 访问你的服务器

* 在以下位置查找连接信息 **我的订单**
* Web 界面：使用 HTTP 端口 URL
* SSH： `ssh -p <port> root@<proxy-address>`

## 为什么选择 Text Generation WebUI？

* 支持 GGUF、GPTQ、AWQ、EXL2、HF 格式
* 内置聊天、笔记本和 API 模式
* 扩展：语音、角色、多模态
* 支持微调
* 可随时切换模型

## 需求

| 模型大小    | 最低显存 | 推荐       |
| ------- | ---- | -------- |
| 7B（Q4）  | 6GB  | RTX 3060 |
| 13B（Q4） | 10GB | RTX 3080 |
| 30B（Q4） | 20GB | RTX 4090 |
| 70B（Q4） | 40GB | A100     |

## 快速部署

**Docker 镜像：**

```
atinoda/text-generation-webui:default-nvidia
```

**端口：**

```
22/tcp
7860/http
5000/http
5005/http
```

**环境变量：**

```
EXTRA_LAUNCH_ARGS=--listen --api
```

## 手动安装

**镜像：**

```
nvidia/cuda:12.8.1-devel-ubuntu22.04
```

**端口：**

```
22/tcp
7860/http
5000/http
```

**命令：**

```bash
apt-get update && apt-get install -y git python3 python3-pip && \\
cd /workspace && \
git clone https://github.com/oobabooga/text-generation-webui.git && \\
cd text-generation-webui && \\
pip install -r requirements.txt && \
python server.py --listen --api
```

## 访问你的服务

部署后，找到你的 `http_pub` URL 在 **我的订单**:

1. 前往 **我的订单** 页面
2. 点击你的订单
3. 找到 `http_pub` URL（例如， `abc123.clorecloud.net`)

使用 `https://YOUR_HTTP_PUB_URL` 替代 `localhost` 在下面的示例中。

## 访问 WebUI

1. 等待部署完成
2. 在以下位置找到 7860 端口映射： **我的订单**
3. 打开： `http://<proxy>:<port>`

## 下载模型

### 从 HuggingFace（在 WebUI 中）

1. 前往 **模型** 标签页
2. 输入模型名称： `bartowski/Meta-Llama-3.1-8B-Instruct-GGUF`
3. 点击 **下载**

### 通过命令行

```bash
cd /workspace/text-generation-webui

# 下载 GGUF 模型
python download-model.py bartowski/Meta-Llama-3.1-8B-Instruct-GGUF

# 下载特定文件
python download-model.py bartowski/Meta-Llama-3.1-8B-Instruct-GGUF --specific-file Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf
```

### 推荐模型

**用于聊天：**

```bash

# Llama 2 Chat（7B，快速）
python download-model.py bartowski/Meta-Llama-3.1-8B-Instruct-GGUF

# Mistral Instruct（优秀）
python download-model.py bartowski/Mistral-7B-Instruct-v0.3-GGUF

# OpenHermes（很棒的全能型）
python download-model.py bartowski/OpenHermes-2.5-Mistral-7B-GGUF
```

**用于编程：**

```bash

# CodeLlama
python download-model.py bartowski/CodeLlama-13B-Instruct-GGUF

# DeepSeek Coder
python download-model.py bartowski/DeepSeek-Coder-V2-Lite-Instruct-GGUF
```

**用于角色扮演：**

```bash

# MythoMax
python download-model.py bartowski/MythoMax-L2-13B-GGUF
```

## 加载模型

### GGUF（推荐给大多数用户）

1. **模型** 标签页 → 选择模型文件夹
2. **模型加载器：** llama.cpp
3. 设置 **n-gpu-layers：**
   * RTX 3090：35-40
   * RTX 4090：45-50
   * A100：80+
4. 点击 **加载**

### GPTQ（快速，量化）

1. 下载 GPTQ 模型
2. **模型加载器：** ExLlama\_HF 或 AutoGPTQ
3. 加载模型

### EXL2（最快）

```bash

# 安装 exllamav2
pip install exllamav2
```

1. 下载 EXL2 模型
2. **模型加载器：** ExLlamav2\_HF
3. 加载

## 聊天配置

### 角色设置

1. 前往 **参数** → **角色**
2. 创建或加载角色卡
3. 设置：
   * 名称
   * 上下文/人设
   * 示例对话

### 指令模式

适用于指令微调模型：

1. **参数** → **指令模板**
2. 选择与您的模型匹配的模板：
   * Llama-2-chat
   * Mistral
   * ChatML
   * Alpaca

## API 使用

### 启用 API

先从 `--api` 参数（默认端口 5000）

### 兼容 OpenAI 的 API

```python
import openai

openai.api_base = "http://localhost:5000/v1"
openai.api_key = "not-needed"

response = openai.ChatCompletion.create(
    model="any",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
```

### 原生 API

```python
import requests

response = requests.post(
    "http://localhost:5000/api/v1/generate",
    json={
        "prompt": "写一个关于……的故事",
        "max_new_tokens": 200,
        "temperature": 0.7
    }
)
print(response.json()["results"][0]["text"])
```

## 扩展

### 安装扩展

```bash
cd /workspace/text-generation-webui/extensions

# Silero TTS（语音）
git clone https://github.com/oobabooga/text-generation-webui-extensions

# SuperBoogav2（RAG/长期记忆）

# 已内置，在 UI 中启用
```

### 启用扩展

1. **会话** 标签页 → **扩展**
2. 勾选需要的扩展
3. 点击 **应用并重启**

### 热门扩展

| 扩展                | 用途   |
| ----------------- | ---- |
| silero\_tts       | 语音输出 |
| whisper\_stt      | 语音输入 |
| superbooga        | 文档问答 |
| sd\_api\_pictures | 图像生成 |
| multimodal        | 图像理解 |

## 性能调优

### GGUF 设置

```
n_gpu_layers: 35    # GPU 层数（越多 = 越快）
n_ctx: 4096         # 上下文长度
n_batch: 512        # 批大小
threads: 8          # CPU 线程数
```

### 内存优化

对于显存有限的情况：

```bash
python server.py --listen --n-gpu-layers 20 --no-mmap
```

### 速度优化

```bash

# 使用带 cuBLAS 的 llama.cpp
python server.py --listen --loader llama.cpp --n-gpu-layers 50 --threads 8
```

## 微调（LoRA）

### 训练标签页

1. 前往 **训练** 标签页
2. 加载基础模型
3. 上传数据集（JSON 格式）
4. 配置：
   * LoRA rank：8-32
   * 学习率：1e-4
   * 训练轮数：3-5
5. 开始训练

### 数据集格式

```json
[
  {"instruction": "总结这个：", "input": "长文本...", "output": "摘要..."},
  {"instruction": "翻译成法语：", "input": "Hello", "output": "Bonjour"}
]
```

## 保存你的工作

```bash

# 保存模型
rsync -avz /workspace/text-generation-webui/models/ backup-server:/models/

# 保存角色
rsync -avz /workspace/text-generation-webui/characters/ backup-server:/characters/

# 保存 LoRA
rsync -avz /workspace/text-generation-webui/loras/ backup-server:/loras/
```

## 故障排查

### 模型无法加载

* 检查显存使用情况： `nvidia-smi`
* 减少 `n_gpu_layers`
* 使用更小的量化（Q4\_K\_M → Q4\_K\_S）

### 生成缓慢

* 增大 `n_gpu_layers`
* 使用 EXL2 而不是 GGUF
* 启用 `--no-mmap`

{% hint style="danger" %}
**内存不足**
{% endhint %}

生成过程中 - 减少 \`n\_ctx\`（上下文长度） - CPU 仅模式使用 \`--n-gpu-layers 0\` - 尝试更小的模型

## 成本估算

CLORE.AI 市场常见费率（截至 2024 年）：

| GPU       | 小时费率    | 日费率     | 4 小时会话  |
| --------- | ------- | ------- | ------- |
| RTX 3060  | \~$0.03 | \~$0.70 | \~$0.12 |
| RTX 3090  | \~$0.06 | \~$1.50 | \~$0.25 |
| RTX 4090  | \~$0.10 | \~$2.30 | \~$0.40 |
| A100 40GB | \~$0.17 | \~$4.00 | \~$0.70 |
| A100 80GB | \~$0.25 | \~$6.00 | \~$1.00 |

*价格因提供商和需求而异。请查看* [*CLORE.AI 市场*](https://clore.ai/marketplace) *以获取当前费率。*

**节省费用：**

* 使用 **竞价** 可中断工作市场——约三分之一的服务器将现货价格定得低于按需价格（中位数约优惠 13%），其余则与按需价格持平
* 使用 **CLORE** 代币支付
* 比较不同提供商的价格


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/text-generation-webui.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
