# GLM-5.1（7440亿 MoE，SWE-Bench Pro 第一）

{% hint style="info" %}
**状态（2026年4月）：** GLM-5.1 于 **2026年4月7日** 由 Z.ai（原智谱 AI）发布，作为对 [GLM-5](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/glm5)的渐进但重要的升级。它是首个在 **SWE-Bench Pro（58.4%）**&#x4E0A;登顶的开源权重模型，按厂商公布的数据，略微领先 GPT-5.4（57.7）和 Claude Opus 4.6（57.3）。权重地址为 [huggingface.co/zai-org/GLM-5.1](https://huggingface.co/zai-org/GLM-5.1) ，采用 **MIT 许可证**.
{% endhint %}

GLM-5.1 是一个 **7440 亿参数的混合专家（MoE）** 语言模型，每个 token 仅激活 **约 400 亿参数**。与其前代相比 [GLM-5](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/glm5)，5.1 版本保留了相同的 MoE 骨架，但带来了改进的专家路由、 **20 万 token 上下文窗口**、 **13.1072 万 token 最大输出**，以及专注于 **长周期智能体式编程** 的训练——该模型明确针对持续数千次工具调用和数百轮重构而优化，不会偏离目标。

对 Clore.ai 用户来说，最有意思的是 **40B 激活** 这个数字：你不需要一整套 8×H200 机架就能部署它。跨 **2×H100 80GB** （FP8）或 **4×A100 80GB** （带分片的 BF16）的张量并行配置就足以获得实用吞吐量——让前沿级编程能力以市场上每天约 12–24 美元的成本触手可及。

### 租用的 GPU 服务器上

| 属性    | 值                                              |
| ----- | ---------------------------------------------- |
| 总参数量  | 744B（MoE）                                      |
| 激活参数量 | 每次前向传播约 40B                                    |
| 上下文窗口 | 200,000 tokens                                 |
| 最大输出  | 131,072 tokens                                 |
| 许可证   | MIT                                            |
| 发布日期  | 2026年4月7日                                      |
| 组织    | Z.ai（HuggingFace 上的 zai-org）                   |
| 主要工具链 | vLLM、SGLang、llama.cpp（GGUF）、xLLM、KTransformers |

### 为什么选择 GLM-5.1？

* **SWE-Bench Pro 排名第 1** ——厂商宣称 58.4%，领先 GPT-5.4 和 Claude Opus 4.6
* **长周期智能体** ——可在数百轮和数千次工具调用中持续优化
* **20 万上下文** ——足以容纳一个中等规模完整代码库加测试套件
* **40B 激活 MoE** ——你支付的是 40B 稠密模型的推理成本，而不是 744B 模型的成本
* **MIT 许可证** ——完全开放权重，商业使用或微调不受限制
* **开放训练栈** ——Z.ai 已发布该模型，据称训练时未使用 Nvidia 数据中心 GPU

***

## 需求

{% hint style="warning" %}
**但它仍然是个大模型。** 虽然“40B 激活”听起来很友好，但完整的 744B 权重必须装入 VRAM（或卸载到其他介质）。FP8 权重约 860GB；BF16 约 1.5TB。请据此规划。
{% endhint %}

| 组件     | 最低配置（Q4 GGUF，卸载）  | 推荐配置（FP8）             | 完整 BF16       |
| ------ | ----------------- | --------------------- | ------------- |
| GPU 显存 | 约 80GB（Q4 + 内存卸载） | 2× H100 80GB 激活，合计 8× | 8× H200 141GB |
| 内存     | 256GB             | 256GB                 | 512GB         |
| 磁盘     | 500GB NVMe        | 1TB NVMe              | 2TB NVMe      |
| CUDA   | 12.4+             | 12.4+                 | 12.6+         |

**Clore.ai 选择：** 对大多数团队来说，使用 FP8 检查点并进行激进卸载的 2× H100 80GB 是最佳平衡点（约每天 12–16 美元）。如果你需要完整 BF16 吞吐量，就升级到 8× H200，或者在偶尔调用时使用 Z.ai API。

***

## 方案 A — Ollama / GGUF（量化版，社区构建）

{% hint style="warning" %}
**注意：** 社区 GGUF 量化版通常会在 Z.ai 发布后 1–2 周上线。如果 `ollama pull` 失败，请查看 [huggingface.co/models?search=glm-5.1+gguf](https://huggingface.co/models?search=glm-5.1+gguf) 并直接让 llama.cpp 指向该文件。
{% endhint %}

```bash
# 一旦可用 Q4_K_M 构建版本
docker exec ollama ollama pull glm-5.1:q4_K_M
docker exec ollama ollama run glm-5.1:q4_K_M

# 或直接使用 llama.cpp 处理 GGUF 文件
docker run --gpus all -it --rm -p 8080:8080 \
  -v $(pwd)/models:/models \
  ghcr.io/ggerganov/llama.cpp:server-cuda \
  -m /models/glm-5.1-q4_k_m.gguf \
  --n-gpu-layers 80 --ctx-size 32768 \
  --port 8080 --host 0.0.0.0
```

***

## 方案 B — vLLM（生产 API，推荐）

vLLM 是 Z.ai 的一等公民级部署目标。FP8 检查点（`zai-org/GLM-5.1-FP8`）是你想要的——质量与 BF16 相同，内存大约减半。

```yaml
version: "3.8"
services:
  vllm：
    image: vllm/vllm-openai:latest
    ports:
      - "8000:8000"
    volumes:
      - hf_cache:/root/.cache/huggingface
    command: >
      --model zai-org/GLM-5.1-FP8
      --tensor-parallel-size 8
      --max-model-len 65536
      --gpu-memory-utilization 0.88
      --tool-call-parser glm47
      --reasoning-parser glm45
      --enable-auto-tool-choice
      --served-model-name glm-5.1
      --trust-remote-code
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    shm_size: "16gb"

volumes:
  hf_cache:
```

```bash
# 测试 API
curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "glm-5.1",
    "messages": [
      {"role": "system", "content": "你是一名资深软件工程师。"},
      {"role": "user", "content": "请重构这个 Go 处理器，正确使用 context.Context，并添加重试。"}
    ],
    "max_tokens": 4096,
    "temperature": 1.0
  }'
```

{% hint style="info" %}
使用 `--tensor-parallel-size 2` 在 2× H100 上，如果你的 GPU 数量比较紧张，但要为 20 万上下文的较慢预填充做好准备。 `--enable-chunked-prefill` 会很有帮助。
{% endhint %}

***

## 方案 C — SGLang（替代方案，通常在 Hopper 上更快）

```bash
docker pull lmsysorg/sglang:latest

python3 -m sglang.launch_server \
  --model-path zai-org/GLM-5.1-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.88 \
  --context-length 65536 \
  --served-model-name glm-5.1
```

SGLang 的 EAGLE 推测解码通常会让长篇代码补全的吞吐量提升 1.5–2 倍。

***

## Clore.ai GPU 推荐

| 配置            | VRAM    | 预期性能                   | Clore.ai 费用  |
| ------------- | ------- | ---------------------- | ------------ |
| 2× H100 80GB  | 160GB   | 带卸载的 FP8，约 15–25 tok/s | 约 12–16 美元/天 |
| 4× A100 80GB  | 320GB   | 分片 BF16，约 20–30 tok/s  | 约 15–22 美元/天 |
| 8× H100 80GB  | 640GB   | 完整 FP8，约 60+ tok/s     | 约 40–55 美元/天 |
| 8× H200 141GB | 1,128GB | 完整 BF16，最高吞吐量          | 约 70 美元+/天   |

{% hint style="success" %}
**最佳性价比：** 2× H100 80GB 搭配 FP8 检查点。你能以大致相当于 Claude Opus 订阅的价格获得前沿级编程性能——而且权重保留在你自己的机器上。
{% endhint %}

***

## 使用场景

* **自主 SWE 智能体** ——GLM-5.1 明确针对长时间工具调用循环训练；可搭配 SWE-agent 或 OpenHands 等工具
* **代码库理解** ——把 10 万以上 token 的 Go/Rust/Python 放入上下文，并请求架构评审
* **长上下文 RAG** ——20 万上下文可一次性处理整个产品文档 + 支持工单
* **重构流水线** ——在数百次文件编辑中持续保持正确性
* **智能体编排智能体** ——用 GLM-5.1 作为规划器，较小模型（Qwen3.5-35B、GLM-4.7）作为执行者

***

## 基准测试

{% hint style="warning" %}
**厂商宣称——请独立验证。** 以下数字来自 Z.ai 于 2026 年 4 月 7 日的公告。SWE-Bench Pro 上的独立复现仍在陆续出现。
{% endhint %}

| 基准                 | GLM-5.1   | GPT-5.4 | Claude Opus 4.6 | GLM-5 |
| ------------------ | --------- | ------- | --------------- | ----- |
| SWE-Bench Pro      | **58.4%** | 57.7%   | 57.3%           | \~52% |
| SWE-Bench Verified | \~79%     | \~78%   | \~80%           | 77.8% |
| HumanEval          | \~94%     | \~95%   | \~94%           | \~93% |
| LiveCodeBench      | \~72%     | \~73%   | \~70%           | \~68% |

***

## 故障排除

| 问题                      | 解决方案                                                                                                     |
| ----------------------- | -------------------------------------------------------------------------------------------------------- |
| `OutOfMemoryError` 在加载时 | FP8 检查点总共需要约 860GB VRAM。请使用 8× H100/H200，或改用带内存卸载的 GGUF Q4。                                              |
| HuggingFace 下载很慢        | 使用 `huggingface-cli download zai-org/GLM-5.1-FP8 --local-dir ./weights --resume-download`。预计需要 800GB 以上。 |
| 工具调用被静默丢弃               | 确保 `--tool-call-parser glm47` 和 `--enable-auto-tool-choice` 这两个选项都已在 vLLM 中设置。                           |
| 思考模式为空                  | 需要 `temperature=1.0` ——零温度采样会破坏推理轨迹。                                                                     |
| vLLM 拒绝该配置              | GLM-5.1 需要 vLLM ≥ 0.7.x（2026 年 4 月版本）。如果版本较旧，请使用 `pip install -U vllm --pre` 。                           |
| 20 万上下文 OOM             | 从 `--max-model-len 65536` 开始，并添加 `--enable-chunked-prefill`；稳定后再提高。                                      |

***

## 下一步

* **前代：** [GLM-5](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/glm5) ——相同的 MoE 结构，但编程导向稍弱
* **更便宜的替代方案：** [Qwen3.5](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/qwen35) ——35B 稠密模型可在单张 RTX 4090 上运行
* **超大上下文替代方案：** [DeepSeek V4](https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/deepseek-v4) ——100 万上下文，多模态，约 1T 参数
* **Clore.ai 市场：** [clore.ai/marketplace](https://clore.ai/marketplace) ——可租用 H100/H200/A100，低至每天 0.50 美元

### 链接

* [HuggingFace 上的 GLM-5.1](https://huggingface.co/zai-org/GLM-5.1)
* [Z.ai 博客——GLM-5.1 公告](https://z.ai/blog/glm-5.1)
* [Z.ai 平台（托管 API）](https://chat.z.ai)
* [vLLM 文档](https://docs.vllm.ai)
* [SGLang 仓库](https://github.com/sgl-project/sglang)


---

# Agent Instructions: 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:

```
GET https://docs.clore.ai/guides/guides_v2-zh/yu-yan-mo-xing/glm-5-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
