> 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/glm5.md).

# GLM-5

在 Clore.ai 上部署 Zhipu AI 的 GLM-5（744B MoE）——通过 vLLM 提供 API 访问和自托管

GLM-5，于2026年2月由智谱AI（Z.AI）发布，是一款 **7440亿参数的混合专家（MoE）** 语言模型，每个 token 仅激活 400亿参数。它在推理、编程和智能体任务上实现了顶尖的开源性能——在 SWE-bench Verified 上得分 77.8%，并可与 Claude Opus 4.5 和 GPT-5.2 等前沿模型相媲美。该模型可在 **MIT 许可证** 在 HuggingFace 上获取。

## 主要特性

* **总计 7440亿 / 激活 400亿** — 采用 256 个专家的高效路由 MoE
* **前沿级编程性能** — SWE-bench Verified 77.8%，SWE-bench Multilingual 73.3%
* **深度推理** — AIME 2026 上 92.7%，HMMT 2025年11月 上 96.9%，内置思考模式
* **智能体能力** — 原生工具调用、函数执行和长程任务规划
* **20万+ 上下文窗口** — 可处理超大代码库和长文档
* **MIT 许可证** — 完全开源权重，允许商业使用

## 需求

{% hint style="warning" %}
**Clore.ai 市场上未列出多 GPU 的 80GB 级机型。** 目前列出的最大配置是 4× RTX PRO 6000 Blackwell（每张 96GB，共 380GB）以及 8–11× RTX 5090（每张 32GB）。A100 / H200 / B200 容量可按 [裸机](https://clore.ai/bare-metal) 需求提供。部署前请查看 [GPU 价格与可用性](/guides/guides_v2-zh/ru-men-zhi-nan/pricing.md) 。
{% endhint %}

自托管 GLM-5 是一项严肃工程——FP8 检查点需要 **\~860GB 显存**.

| 组件   | 最低配置（FP8）    | 推荐            |
| ---- | ------------ | ------------- |
| GPU  | 8× H100 80GB | 8× H200 141GB |
| 显存   | 640GB        | 1,128GB       |
| 内存   | 256GB        | 512GB         |
| 磁盘   | 1.5TB NVMe   | 2TB NVMe      |
| CUDA | 12.8+        | 12.8+         |

**Clore.ai 推荐**：对于大多数用户， **通过 API 访问 GLM-5** （Z.AI、OpenRouter）。只有当你能在 Clore.ai 上租到 8× H100/H200 时，自托管才有意义（[裸机](https://clore.ai/bare-metal) 在 Clore.ai 上）。

## API 访问（推荐给大多数用户）

在 Clore.ai 机器上或任何地方使用 GLM-5 的最实用方式：

### 通过 Z.AI 平台

```python
from openai import OpenAI

client = OpenAI(
    api_key="your-zai-api-key",
    base_url="https://api.z.ai/v1"
)

response = client.chat.completions.create(
    model="glm-5",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "使用 aiohttp 和 BeautifulSoup 编写一个 Python 异步网页爬虫"}
    ],
    temperature=1.0,
    max_tokens=4096
)
print(response.choices[0].message.content)
```

### 通过 OpenRouter

```python
from openai import OpenAI

client = OpenAI(
    api_key="your-openrouter-key",
    base_url="https://openrouter.ai/api/v1"
)

response = client.chat.completions.create(
    model="zai-org/glm-5",
    messages=[
        {"role": "user", "content": "解释 GLM-5 中使用的 MoE 架构"}
    ],
    max_tokens=2048
)
print(response.choices[0].message.content)
```

## vLLM 设置（自托管）

适用于在 Clore.ai 上拥有高端多 GPU 机器的用户：

```bash
# 安装 vLLM（支持 GLM-5 需要 nightly 版本）
pip install -U vllm --pre --extra-index-url https://wheels.vllm.ai/nightly

# 安装最新的 transformers（必需）
pip install git+https://github.com/huggingface/transformers.git
```

### 在 8× H200 GPU 上提供 FP8 服务

```bash
vllm serve zai-org/GLM-5-FP8 \\
  --tensor-parallel-size 8 \\
  --speculative-config.method mtp \\
  --speculative-config.num_speculative_tokens 1 \\
  --tool-call-parser glm47 \\
  --reasoning-parser glm45 \\
  --enable-auto-tool-choice \\
  --served-model-name glm-5-fp8 \\
  --gpu-memory-utilization 0.85
```

### 查询服务器

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")

# 使用思考模式（默认）
response = client.chat.completions.create(
    model="glm-5-fp8",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "求解：找出所有满足 p^2 + 2 也为素数的素数 p"}
    ],
    temperature=1.0,
    max_tokens=4096
)
print(response.choices[0].message.content)

# 不使用思考模式（更快，回复更短）
response = client.chat.completions.create(
    model="glm-5-fp8",
    messages=[
        {"role": "user", "content": "用 Rust 编写快速排序"}
    ],
    temperature=1.0,
    max_tokens=4096,
    extra_body={
        "chat_template_kwargs": {"enable_thinking": False}
    }
)
print(response.choices[0].message.content)
```

## SGLang 替代方案

SGLang 也支持 GLM-5，并且在某些硬件上可能表现更好：

```bash
# 使用 Docker（Hopper GPU）
docker pull lmsysorg/sglang:glm5-hopper

# 启动服务器
python3 -m sglang.launch_server \\
  --model-path zai-org/GLM-5-FP8 \\
  --tp-size 8 \\
  --tool-call-parser glm47 \\
  --reasoning-parser glm45 \\
  --speculative-algorithm EAGLE \\
  --speculative-num-steps 3 \\
  --speculative-eagle-topk 1 \\
  --speculative-num-draft-tokens 4 \\
  --mem-fraction-static 0.85 \\
  --served-model-name glm-5-fp8
```

## Docker 快速开始

```bash
# 支持 GLM-5 的 vLLM Docker 镜像
docker run --gpus all -p 8000:8000 \\
  --ipc=host \\
  -v ~/.cache/huggingface:/root/.cache/huggingface \\
  vllm/vllm-openai:glm5 zai-org/GLM-5-FP8 \\
  --tensor-parallel-size 8 \\
  --tool-call-parser glm47 \\
  --reasoning-parser glm45 \\
  --enable-auto-tool-choice \\
  --served-model-name glm5 \\
  --trust-remote-code
```

## 工具调用示例

GLM-5 原生支持工具调用——非常适合构建智能体应用：

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "获取某个城市的当前天气",
        "parameters": {
            "type": "object",
            "required": ["city"],
            "properties": {
                "city": {"type": "string", "description": "城市名称"}
            }
        }
    }
}]

response = client.chat.completions.create(
    model="glm-5-fp8",
    messages=[{"role": "user", "content": "东京现在的天气怎么样？"}],
    tools=tools,
    tool_choice="auto"
)
print(response.choices[0].message.tool_calls)
```

## 给 Clore.ai 用户的建议

* **先 API，后自托管**：GLM-5 需要 8× H200（[裸机](https://clore.ai/bare-metal) 在 Clore.ai 上）。对于偶尔使用，Z.AI API 或 OpenRouter 的成本效益要高得多。只有当你需要持续吞吐量或数据隐私时，才考虑自托管。
* **不妨考虑 GLM-4.7**：如果 8× H200 太多，那么其前代 GLM-4.7（3550亿参数，320亿激活）可在 4× H200 或 4× H100 上运行（约 4.16 美元/小时），且依然能提供出色性能。
* **使用 FP8 权重**：始终使用 `zai-org/GLM-5-FP8` ——质量与 BF16 相同，但显存占用几乎减半。BF16 版本需要 16× GPU。
* **监控显存使用情况**: `watch nvidia-smi` ——长上下文查询可能会导致内存峰值。设置 `--gpu-memory-utilization 0.85` 以留出余量。
* **思考模式权衡**：思考模式在复杂任务上效果更好，但会使用更多 token 和时间。对于简单查询，可用 `enable_thinking: false`.

## 故障排查

| 问题                      | 解决方案                                                                    |
| ----------------------- | ----------------------------------------------------------------------- |
| `OutOfMemoryError` 在启动时 | 请确保你拥有 8× H200（每块 141GB）。FP8 需要约 860GB 总显存。                             |
| 下载较慢（约 800GB）           | 使用 `huggingface-cli download zai-org/GLM-5-FP8` 使用 `--local-dir` 以恢复下载。 |
| vLLM 版本不匹配              | GLM-5 需要 vLLM nightly 版本。通过以下方式安装： `pip install -U vllm --pre`.         |
| 工具调用不起作用                | 在 `--tool-call-parser glm47 --enable-auto-tool-choice` 加入 serve 命令。     |
| DeepGEMM 错误             | 为 FP8 安装 DeepGEMM：使用 `install_deepgemm.sh` vLLM 仓库中的脚本。                 |
| 思考模式输出为空                | 设置 `temperature=1.0` ——思考模式需要非零 temperature。                            |

## 延伸阅读

* [HuggingFace 上的 GLM-5](https://huggingface.co/zai-org/GLM-5)
* [GLM-5 FP8 检查点](https://huggingface.co/zai-org/GLM-5-FP8)
* [Z.AI 平台](https://chat.z.ai)
* [Z.AI API 文档](https://docs.z.ai/guides/llm/glm-5)
* [vLLM GLM-5 配方](https://docs.vllm.ai/projects/recipes/en/latest/GLM/GLM5.html)
* [GLM-5 技术博客](https://z.ai/blog/glm-5)
* [Slime RL 基础设施](https://github.com/THUDM/slime)


---

# 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/glm5.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.
