> 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/tu-xiang-sheng-cheng/invokeai.md).

# InvokeAI

在 Clore.ai GPU 上运行带节点式画布的 InvokeAI 专业 Stable Diffusion 工具包

InvokeAI 是一套专业级的 Stable Diffusion 工具包，具有先进的基于节点的画布编辑器、完整的 SDXL/SD1.5/SD2.x 支持、ControlNet、IP-Adapter、LoRA 管理，以及精美的 Web UI。它专为需要对图像生成工作流进行精确控制的艺术家和创意专业人士而设计。CLORE.AI 的高显存 GPU 让你能够以全分辨率运行 SDXL，并可同时使用多个 ControlNet。

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

## 服务器要求

| 参数  | 最低                   | 推荐                       |
| --- | -------------------- | ------------------------ |
| 内存  | 12 GB                | 32 GB+                   |
| 显存  | 6 GB                 | 12 GB+                   |
| 磁盘  | 40 GB                | 200 GB+                  |
| GPU | NVIDIA GTX 1060 6GB+ | RTX 3090, RTX 4090, A100 |

{% hint style="info" %}
对于不作妥协的 SDXL（1024×1024），建议使用 12 GB VRAM。对于 SD1.5（512×512 或 768×768），6 GB VRAM 就足够。VRAM 越多 = 分辨率更高、生成更快、可同时使用更多 ControlNet。
{% endhint %}

## 在 CLORE.AI 上快速部署

**Docker 镜像：** `ghcr.io/invoke-ai/invokeai:latest`

**端口：** `22/tcp`, `9090/http`

**环境变量：**

| 变量              | 示例          | 描述        |
| --------------- | ----------- | --------- |
| `INVOKEAI_ROOT` | `/invokeai` | 模型和输出的根目录 |

## 逐步设置

### 1. 在 CLORE.AI 上租用 GPU 服务器

访问 [CLORE.AI 市场](https://clore.ai/marketplace) 并查找：

* **预算型创意工作**：RTX 3080/3090（10–24 GB VRAM）
* **专业级 SDXL**：RTX 4090（24 GB VRAM）
* **最高质量**：A100 80GB — 可同时运行多个模型

### 2. SSH 登录到你的服务器

```bash
ssh -p <PORT> root@<SERVER_IP>
```

### 3. 创建 InvokeAI 目录结构

```bash
mkdir -p /root/invokeai
```

### 4. 拉取 InvokeAI Docker 镜像

```bash
docker pull ghcr.io/invoke-ai/invokeai:latest
```

### 5. 启动 InvokeAI

**基本启动：**

```bash
docker run -d \\
  --name invokeai \\
  --gpus all \\
  -p 9090:9090 \\
  -v /root/invokeai:/invokeai \\
  -e INVOKEAI_ROOT=/invokeai \\
  ghcr.io/invoke-ai/invokeai:latest \\
  invokeai-web --host 0.0.0.0 --port 9090
```

**使用自定义根目录并增加资源：**

```bash
docker run -d \\
  --name invokeai \\
  --gpus all \\
  --shm-size 8g \\
  -p 9090:9090 \\
  -v /root/invokeai:/invokeai \\
  -v /root/models:/root/models \\
  -e INVOKEAI_ROOT=/invokeai \\
  ghcr.io/invoke-ai/invokeai:latest \\
  invokeai-web --host 0.0.0.0 --port 9090
```

**使用指定 GPU（多 GPU 服务器）：**

```bash
docker run -d \\
  --name invokeai \\
  --gpus '"device=0"' \\
  -p 9090:9090 \\
  -v /root/invokeai:/invokeai \\
  -e INVOKEAI_ROOT=/invokeai \\
  -e CUDA_VISIBLE_DEVICES=0 \\
  ghcr.io/invoke-ai/invokeai:latest \\
  invokeai-web --host 0.0.0.0 --port 9090
```

### 6. 等待初始化

```bash
docker logs -f invokeai
```

查找： `Uvicorn 正在运行于 http://0.0.0.0:9090`

### 7. 通过 CLORE.AI HTTP 代理访问

打开你的 CLORE.AI 仪表板并找到 `http_pub` 9090 端口的 URL：

```
https://<order-id>-9090.clore.ai/
```

这将在浏览器中打开完整的 InvokeAI Web 界面。

### 8. 下载你的第一个模型

在 InvokeAI 界面中：

1. 点击 **模型管理器** （左侧边栏中的立方体图标）
2. 点击 **添加模型 → HuggingFace**
3. 输入模型 ID（例如， `stabilityai/stable-diffusion-xl-base-1.0`)
4. 点击 **添加模型**

或者直接从 CivitAI 下载：

1. 前往 **模型管理器 → 添加模型 → URL**
2. 粘贴 CivitAI 下载 URL
3. 设置模型类型（Checkpoint、LoRA 等）

***

## 使用示例

### 示例 1：通过 Web UI 进行基本图像生成

1. 通过你的 CLORE.AI http\_pub URL 打开 InvokeAI
2. 点击 **文本生成图像** 在工作流选择器中
3. 输入提示词： `“一条雄伟的巨龙栖息在水晶山上，数字艺术，4k”`
4. 设置负面提示词： `“模糊、低质量、水印”`
5. 将分辨率设置为 `1024x1024` （SDXL）或 `512x512` （SD1.5）
6. 点击 **Invoke**

### 示例 2：使用基于节点的画布

工作流编辑器是 InvokeAI 的标志性功能：

1. 点击 **工作流** 在顶部导航栏中
2. 点击 **新建工作流**
3. 添加节点： **文本 → 图像**，连接到 **保存图像**
4. 添加一个 **ControlNet** 节点用于引导生成：
   * 右键 → 添加节点 → **ControlNet**
   * 连接你的参考图像
   * 选择处理器： `Canny`, `深度`, `姿态`等
5. 点击 **Invoke** 以运行完整流程

### 示例 3：LoRA 使用

1. 从 CivitAI 下载一个 LoRA（通过 模型管理器 → URL 导入）
2. 在生成面板中，找到 **LoRA** 部分
3. 点击 **+** 并选择你的 LoRA
4. 设置权重（通常 0.5–1.0）
5. 将触发词添加到提示词中（列在 CivitAI 模型页面上）

带有 LoRA 触发词的示例提示词：

```
“一位女性的肖像，<lora:detail-tweaker:0.8>，超写实，棚拍灯光”
```

### 示例 4：使用 IP-Adapter 进行风格迁移

1. 启用 **IP-Adapter** 在生成面板中
2. 上传一张参考风格图像
3. 设置权重（0.5 = 轻微影响，1.0 = 强烈影响）
4. 使用任意提示词生成 — 输出将匹配参考风格

### 示例 5：API 使用（无头模式）

InvokeAI 提供 REST API 供程序化使用：

```python
import requests
import time
import base64

BASE_URL = "http://localhost:9090"  # 或你的 CLORE.AI http_pub URL

# 列出可用模型
models = requests.get(f"{BASE_URL}/api/v1/models").json()
print("可用模型：", [m["name"] for m in models.get("items", [])])

# 排队生成一次任务
payload = {
    "batch": {
        "graph": {
            "nodes": {
                "text_encoder": {
                    "type": "compel",
                    "id": "text_encoder",
                    "prompt": "一个未来主义城市在日落时分，照片级真实感",
                },
                "noise": {
                    "type": "noise",
                    "id": "noise",
                    "width": 1024,
                    "height": 1024,
                    "seed": 42,
                },
                "denoise_latents": {
                    "type": "denoise_latents",
                    "id": "denoise_latents",
                    "steps": 30,
                    "cfg_scale": 7.5,
                    "scheduler": "dpmpp_2m",
                },
                "l2i": {
                    "type": "l2i",
                    "id": "l2i",
                },
            },
            "edges": [],
        }
    }
}

# 更简单：使用队列 API
response = requests.post(f"{BASE_URL}/api/v1/queue/default/enqueue_batch", json=payload)
print(response.status_code)
```

***

## 配置

### invokeai.yaml 配置文件

位于 `/root/invokeai/invokeai.yaml`:

```yaml
InvokeAI：
  Web 服务器：
    host: 0.0.0.0
    port: 9090
    allow_origins: []
    
  功能：
    esrgan: true          # ESRGAN 放大
    internet_available: true
    
  内存/性能：
    ram: 12.0             # 模型缓存允许的最大 RAM（GB）
    vram: 0.25            # 用于模型缓存的 VRAM 比例
    lazy_offload: true    # 不使用时将模型卸载到 CPU
    
  路径：
    models_path: /invokeai/models
    db_path: /invokeai/databases/invokeai.db
    outdir: /invokeai/outputs
```

### 按 GPU 推荐的设置

**RTX 3090 / 4090（24 GB VRAM）：**

```yaml
内存/性能：
  ram: 24.0
  vram: 0.5   # 保持 50% 供活动模型使用
  lazy_offload: false  # 不要卸载 — VRAM 足够
```

**RTX 3080（10 GB VRAM）：**

```yaml
内存/性能：
  ram: 16.0
  vram: 0.25
  lazy_offload: true
```

**更小的 GPU（6-8 GB VRAM）：**

```yaml
内存/性能：
  ram: 8.0
  vram: 0.1
  lazy_offload: true
```

***

## 性能提示

### 1. 使用 SDXL-Turbo 或 SDXL-Lightning 进行快速生成

不要使用 SDXL 基础模型（25–50 步），改用：

* **SDXL-Turbo**：1–4 步，实时生成
* **SDXL-Lightning**：4–8 步，接近 SDXL 的质量

通过 模型管理器 → HuggingFace 下载：

* `stabilityai/sdxl-turbo`
* `ByteDance/SDXL-Lightning`

### 2. 选择合适的调度器

| 调度器            | 质量 | 速度 | 最适合  |
| -------------- | -- | -- | ---- |
| `euler_a`      | 好  | 快  | 通用   |
| `dpmpp_2m`     | 优秀 | 快  | 照片写实 |
| `dpmpp_2m_sde` | 优秀 | 中等 | 高细节  |
| `ddim`         | 好  | 快  | 局部重绘 |
| `lms`          | 好  | 快  | 艺术风格 |

### 3. 启用 xFormers 内存优化

当可用时，InvokeAI 会自动启用。请在日志中确认：

```
xFormers 可用
```

### 4. 使用模型缓存

将最常用的模型保留在缓存中。在 invokeai.yaml 中：

```yaml
ram: 32.0  # 更大 = 缓存更多模型
```

### 5. 大分辨率时使用分块

对于超过 VRAM 允许范围的图像（例如在 12 GB GPU 上生成 2048×2048）：

* 使用 **分块 VAE** 在工作流编辑器中
* 或者先以 1024×1024 生成，再使用 **ESRGAN**

***

## 故障排查

### 问题：“CUDA 内存不足”

```
RuntimeError：CUDA 内存不足
```

**解决方案：**

1. 降低分辨率（1024→768 或 512）
2. 将批次大小降为 1
3. 在 invokeai.yaml 中启用惰性卸载
4. 使用更小的模型（用 SD1.5 替代 SDXL）

### 问题：Web UI 无法访问

```bash
# 检查容器是否正在运行
docker ps | grep invokeai

# 检查日志中的错误
docker logs invokeai 2>&1 | tail -50

# 验证端口映射
docker port invokeai
```

确保 9090 端口已列在你的 CLORE.AI 订单端口配置中。

### 问题：容器内模型下载失败

```bash
# 通过 exec 手动下载
docker exec -it invokeai bash
cd /invokeai/models/main
wget "https://civitai.com/api/download/models/XXX" -O mymodel.safetensors
```

### 问题：生成速度慢（< 1 it/s）

* 检查 GPU 利用率： `docker exec -it invokeai nvidia-smi`
* 确保日志中已启用 xFormers
* 尝试 `euler_a` 调度器（最快）

### 问题：黑图/损坏的图像

通常是 VAE 问题。试试：

1. 模型管理器 → 编辑模型 → 将 VAE 更改为 `sdxl-vae-fp16-fix`
2. 或添加 `--fp32-vae` 标志

### 问题：容器无法启动

```bash
docker logs invokeai
# 常见情况：9090 端口已被占用
# 解决方法：
docker stop $(docker ps -q --filter "publish=9090")
docker start invokeai
```

***

## 链接

* [GitHub](https://github.com/invoke-ai/InvokeAI)
* [文档](https://invoke-ai.github.io/InvokeAI/)
* [Docker Hub / GHCR](https://github.com/invoke-ai/InvokeAI/pkgs/container/invokeai)
* [CivitAI（模型）](https://civitai.com)
* [CLORE.AI 市场](https://clore.ai/marketplace)

***

## Clore.ai GPU 推荐

| 使用场景  | 推荐 GPU         | Clore.ai 预计成本                     |
| ----- | -------------- | --------------------------------- |
| 开发/测试 | RTX 3090（24GB） | $0.07–0.21/gpu/hr                 |
| 生产环境  | RTX 4090（24GB） | $0.14–0.42/gpu/hr                 |
| 大规模   | A100 80GB      | [裸机](https://clore.ai/bare-metal) |

> 💡 本指南中的所有示例都可以部署在 [Clore.ai](https://clore.ai/marketplace) GPU 服务器上。浏览可用 GPU 并按小时租用——无需承诺，拥有完整 root 访问权限。


---

# 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/tu-xiang-sheng-cheng/invokeai.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.
